22 Commits

Author SHA1 Message Date
091bfa8d4d d3d12/vulkan(r9a): fix pending_stream dword6 refill, gpu_owned eviction, COPY_CLIP, and sync slots 131/132 2026-11-29 09:25:40 -05:00
8c1b8da152 Merge main into d3d12/barrier-into-undefined
main gained its own Part K in vk_command_replay_test and a sentence in the
same bullet of docs/d3d12_vulkan.md (D3D-838, pull request 751). Both stay as
they are on main; this branch's release test becomes Part L, and the doc
bullet for LayoutAfter = UNDEFINED names it so.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 12:45:05 -06:00
37c5af12a4 d3d12: an enhanced texture barrier into LAYOUT_UNDEFINED closes and keeps the layout (D3D-BARRIER-INTO-UNDEFINED)
CommandList::barrier(TextureBarrier) refused LayoutAfter = UNDEFINED from a
defined layout, so the list's Close failed. D3D12 allows it: the contents are
no longer needed, as before the memory is aliased. WARP closes such a list
(measured on Windows 11 26340 in #984), and #984 reports that the retail title
ends a depth buffer's use this way and takes the failed Close as fatal.

The rule goes. Vulkan has no transition into UNDEFINED
(VUID-VkImageMemoryBarrier2-newLayout-01198), so replay gives each piece a
barrier with oldLayout = newLayout, the layout the tracker has for it, which
orders the accesses and changes nothing in the image; the tracker keeps the
layouts. A piece that was never used gets no barrier and is not zero-filled
for it. The next barrier starts from UNDEFINED and discards, as before.

UNDEFINED -> UNDEFINED is not touched here: that is #600.

The barrier half of item 2 of the split proposed in #984, carried onto main
from Moriz82's integration branch (command_list.h, the emit change and the
command_list_test, replay_texture_barrier_test and d3d12_close_parity_test
cases), restricted to a defined LayoutBefore, with more cases and two GPU
tests added.

Tests:
- command_list_test, replay_texture_barrier_test (CPU): the recorded barrier;
  kept layouts over mips in two layouts, with the discard flag and without a
  tracker; an unused image released without a barrier or a zero-fill; the
  barrier from UNDEFINED that follows.
- d3d12_close_parity_test: three enhanced-barrier rows (116 cases, 85 match).
- vk_command_replay_test part K (GPU): a colour target, a depth buffer whose
  planes are in two layouts and an unused image released; the target used
  again and read back.
- d3d12_com_test (GPU, D3D12 list and queue): a depth buffer cleared,
  released, taken from UNDEFINED again, cleared and read back.

Co-authored-by: Moriz82 <72836413+Moriz82@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 11:20:21 -06:00
a744fa8ab1 d3d12: SYNC_COPY waits for the CLEAR stage too (D3D-838)
An enhanced barrier's D3D12_BARRIER_SYNC_COPY mapped to VK_PIPELINE_STAGE_2_COPY_BIT only. Two D3D12
copy-scope commands are not Vulkan copies: WriteBufferImmediate is recorded as vkCmdUpdateBuffer and
ResolveQueryData's never-written queries as vkCmdFillBuffer, and synchronization2 runs both in the CLEAR
stage. A SYNC_COPY barrier after either therefore did not order it, and a copy after the barrier could read
the word before the write landed.

vulkan_sync now maps SYNC_COPY to COPY | CLEAR. vk_command_replay_test part K records WriteBufferImmediate,
a SYNC_COPY -> SYNC_COPY buffer barrier and a CopyBufferRegion of the written word; under
LEONIDA_VK_VALIDATION=1 it is a read-after-write hazard without this change. d3d12_state_map_test and
docs/d3d12_vulkan.md follow the new mapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 16:28:34 +03:00
29f6a3ecb2 Merge pull request #3348 from admin 2026-11-22 17:01:34 -05:00
9e6544a36b Fix Vulkan replay of same-subresource texture copies
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-22 20:09:05 +00:00
fc5b0c27b6 Register three self-checking Vulkan tests with CTest (TEST-514)
vk_command_replay_test, vk_predicated_copy_test and vk_predicate_capture_test
were built but never registered, so no ctest run executed them. Register them
next to depth24_convert, and have each exit 77 (CTest skip) when the test
device reports no Vulkan device, as depth24_convert_test does, so a machine
without a GPU skips them instead of failing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:44:57 -05:00
ef4d3053b1 Depth/stencil region resolves keep the texels around the rectangle
A ResolveSubresourceRegion of a depth or stencil plane runs in a rendering scope whose render area is the source
rectangle, and Vulkan resolves only inside it. MoltenVK (1.4.2 and 1.4.3) resolves the whole destination
subresource: it resolves through Metal's store action, which has no render area. d3d12_depth_resolve failed its
eight MIN/MAX rectangle cases under Wine on an M3 Max for that reason.

The texels around the rectangle now go into copy_scratch before the scope and back after it, in up to four bands, on
every GPU: no device property reports the behaviour. vk_command_replay_test part I resolves a D32 rectangle natively
and checks the texels around it; it failed on MoltenVK before this change (all 28 overwritten) and passes on
MoltenVK and KosmicKrisp, with no validation errors on KosmicKrisp.

AI-assisted.
2026-11-22 19:18:06 +04:00
e1b3fca96d Runtime: depth <-> colour copies through a scratch buffer
CopyResource and CopyTextureRegion between D32_FLOAT and R32_FLOAT/UINT/SINT,
and between D16_UNORM and R16_FLOAT/UNORM, were refused at execution because
vkCmdCopyImage cannot mix a depth and a colour aspect. Host D3D12 and WARP
copy the bits, and #1134 listed these as not covered.

The replay now stages each such region image -> scratch buffer -> image.
The scratch comes from a new ScratchBuffers pool (vulkan_scratch.h):
device-local chunks handed out while a list is prepared and retired with
the submission's timeline value, like the depth24 converter's scratch, but
enabled on every GPU. Without it the copy is refused as unsupported before
anything is written.

Still refused: depth with stencil (two planes), D24 stored as D32, and
multisampled textures.

Tests: d3d12_copy_xfmt gains five depth <-> colour cases (R16 -> D16 both
ways, D32 -> R32_UINT, three mips, and a D32 -> R16 negative control), and a
depth <-> colour mismatch now fails it. vk_command_replay_test part H runs a
D32 -> R32 -> D32 round trip through the replay, and checks that a list is
refused with no scratch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:33:50 +02:00
8e50a770f8 Runtime: suspend conditional rendering around WriteBufferImmediate 2026-11-22 13:19:27 +03:00
9360ec9ec0 Runtime: predicate byte-granular CopyBufferRegion on the GPU
Build on the full 64-bit predicate snapshots from #856. Replay predicated buffer copies through a storage8 compute helper, retain descriptor batches through timeline completion, and reject missing capabilities or active statistics queries before submitting work.

Validate byte offsets, high predicate words, bounds, skipped destinations and pending descriptor lifetimes with CPU checks, 180 native WARP comparisons and 64 gated/reused GPU submissions. The existing OPTIONS19 host-capability mismatch also reproduces on base 4a36bb1; no tests are disabled.
2026-11-22 05:28:28 -04:00
29345889be Runtime: capture full 64-bit predication values on the GPU 2026-11-22 04:34:35 -04:00
033192d050 vk_command_replay_test: cover a subresource copied twice in one list
copy_layout has to order a transfer write that finds its range already in
the transfer layout, because a texture can stay in COPY_DEST and be copied
into again; D3D12 orders copies on the queue and needs no barrier from the
application. That ordering landed in 5ec780c without a test, and the BC7
copy case in d3d12_vulkan_device_test reaches it: on a tree without it the
case reports ten WRITE_AFTER_WRITE hazards under synchronization
validation.

Part G records two buffer-to-image copies into the same subresource with no
transition between them and reads the texture back, so the missing
dependency shows up as a validation error and as the wrong texels.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-21 23:26:54 -06:00
c7e450fc69 D3D-26: keep a null discard region apart from an explicit UINT_MAX count
A region with NumSubresources = UINT_MAX was recorded like a null region and
skipped the FirstSubresource check. DiscardResource now has a whole flag;
explicit ranges are checked in 64-bit at recording and replay. Tests at the
UINT_MAX boundary in command_list_test, part F and the COM device test.
Found by matheuskshn in review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 02:55:44 +00:00
e40bd6563e Merge main into D3D-26: predication and reserved resources on main
main added SetPredication (D3D-18) and reserved resources; both sides are
kept. The predication replay test took part E, so the D3D-26 test is now
part F. An atomic copy recorded under a predicate is counted with the
other copies that Vulkan's conditional rendering cannot skip, and
SetPredication, DiscardResource and the atomic copies are all refused in
a bundle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 01:29:19 +00:00
be91840c07 Runtime: SetPredication on VK_EXT_conditional_rendering (D3D-18)
- command_list.h: a Predication command (offset 8-byte aligned, EQUAL_ZERO or
  NOT_EQUAL_ZERO; a null buffer turns it off), recorded by
  GraphicsCommandList::SetPredication.
- vulkan_replay.h: begin/end conditional rendering (INVERTED for NOT_EQUAL_ZERO),
  ended before a new predicate and at the end of the list. While predicated,
  whole-view clears go through vkCmdClearAttachments, which conditional rendering
  covers. New ReplayResult::invalid_predication; PreparedList::unpredicated_copies
  counts copies Vulkan cannot predicate.
- Device: VK_EXT_conditional_rendering and its feature enabled when present, and
  buffers created with VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT; without it a
  predicated list is unsupported.
- Tests: command_list_test (recording rules), vk_command_replay_test part C (GPU).
- docs/d3d12_vulkan.md 4.7: what is done; copies and the 64-bit value are open.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 10:59:11 +11:00
399b8ff839 Merge main into D3D-26: the replay test's new part D, the resolve-region section
main's vk_command_replay_test now has a part D (sync/access pairs), so the
D3D-26 test becomes part E. The device test's D3D-26 section signals fence
value 7, after main's resolve-region section took 5 and 6. The docs keep
both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:49:29 +00:00
19742b531a Runtime: DiscardResource, WriteBufferImmediate and atomic copies on Vulkan (D3D-26)
Three command-list IR commands, recorded through COM and replayed by
vulkan_replay.h:

- DiscardResource: an oldLayout = UNDEFINED barrier to the layout the
  tracker already has for each subresource. Buffers, rectangle discards,
  parts never used yet, untracked replays and one plane of a combined
  depth-stencil without separate layouts are no-ops.
- WriteBufferImmediate: a 4-byte vkCmdUpdateBuffer at the address,
  resolved at execution through ResourceBinding::va / buffer_offset and
  ReplayFunctions::buffer_at (the same fields and lookup as #291).
  MARKER_OUT waits for and sees every earlier write; MARKER_IN gets an
  execution-only ALL_COMMANDS dependency (Vulkan cannot say "started");
  DEFAULT is ordered by the application's barriers.
- AtomicCopyBufferUINT/UINT64: one vkCmdCopyBuffer region after a
  barrier that covers every earlier write, the dependent resources'
  included. Recording follows the debug layer's ATOMICCOPYBUFFER_* and
  WRITEBUFFERIMMEDIATE_* rules.

Tests: command_list_test (recording rules), vk_command_replay_test part D
(GPU readback of writes in all three modes, ordered atomic copies,
discards, and the lists that must be refused), and the COM path in
d3d12_vulkan_device_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:16:54 +00:00
44a94f35ca Runtime: widen enhanced-barrier stages so every access has a stage that can perform it
D3D12 lets an access be named with a sync scope whose Vulkan stages cannot perform it:
SYNC_ALL_SHADING with ACCESS_VERTEX_BUFFER is valid D3D12, but VERTEX_ATTRIBUTE_READ needs
VERTEX_ATTRIBUTE_INPUT. Vulkan rejects such barriers (docs/d3d12_vulkan.md listed it as a known gap).

vulkan_barrier_scope maps each side of a global, buffer or texture barrier and adds the narrowest
stage that supports any access left without one (the synchronization2 "supported access types"
table). The access is never dropped, so the dependency still covers everything the application
named. CLEAR only writes, and ALL_GRAPHICS holds no transfer stage, so transfer reads get ALL_TRANSFER.

vk_command_replay_test part D records all 360 D3D12 sync/access pairs as global, buffer and texture
barriers: 462 validation errors before, 0 after, on Intel(R) Graphics. d3d12_state_map_test checks
that stages only grow, accesses never change, and pairs Vulkan already accepts are left alone.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:42:05 +01:00
d27e4c5765 Runtime: ResolveSubresource and multisampled textures on Vulkan
There was no resolve, and a multisampled committed texture was refused.

- IR: ResolveSubresource (two different resources).
- Replay: ResolveSubresource is vkCmdResolveImage in the layouts copies
  use: a multisampled colour subresource into a single-sampled 2D one of
  the same size and format. Depth-stencil resolves and resolves between
  two formats of a typeless family stay unsupported. ResourceBinding gains
  samples: a multisampled texture copies only to its own sample count and
  has no footprint.
- Device: committed multisampled 2D textures (single-mip render targets or
  depth-stencils, when the GPU has the sample count for the format; the
  other shapes are E_INVALIDARG as in D3D12), and TEXTURE2DMS
  render-target and depth-stencil views.
- COM: ID3D12GraphicsCommandList::ResolveSubresource.

Tests: command_list_test (recording rules, and a copy with a z range);
vk_command_replay_test part C (a 4x resolve and the refused resolves and
multisampled copies; it also runs the volume copies that are already on
main at the Vulkan level, on Linux too: a 4x4x4 volume uploaded, copied as
a block and whole, read back, and the z ranges that must be refused);
d3d12_vulkan_device_test (a resolve through the Xbox-ABI proxy and the
refused shapes).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 16:34:22 -05:00
Ryx
6052bf0bd5 Runtime: rectangle clears, layout tracking, enhanced barriers, COM list/queue/fence
Closes the gaps left by the barrier/clear slice:

- Rectangle clears: ClearRenderTargetView/ClearDepthStencilView rects are
  recorded and replayed with vkCmdClearAttachments in a dynamic-rendering
  scope, clipped to the mip.
- LayoutTracker: the current Vulkan layout per image subresource, so barriers
  start from the real layout. This honours implicit promotion and decay
  (COMMON is GENERAL; simultaneous-access textures stay GENERAL) and, with
  separateDepthStencilLayouts, lets one depth/stencil plane be cleared or
  transitioned while the other stays in another state.
- Enhanced barriers (global, buffer, texture, split, discard) mapped to
  vkCmdPipelineBarrier2.
- vulkan_backend.h: VulkanContext, VulkanQueue (ExecuteCommandLists checks
  every list before writing any; Wait is attached to the next submission),
  VulkanFence on timeline semaphores.
- d3d12_com.cpp: ID3D12GraphicsCommandList7, ID3D12CommandQueue,
  ID3D12CommandAllocator and ID3D12Fence1. Unimplemented methods are stubs
  generated at build time from the SDK's d3d12.h (tools/gen_d3d12_stubs.py),
  so vtables follow the SDK order and nothing SDK-derived is checked in.

Tests: command_list_test and d3d12_state_map_test (every copied D3D12
constant checked against d3d12.h) in ctest; vk_command_replay_test and the new
d3d12_com_test on the GPU, clean under the Khronos validation layer.
2026-11-21 19:19:31 +01:00
Ryx
7f6e8f059d Runtime: D3D12 barriers and depth-stencil clears in the command-list IR
The IR (command_list.h, was clear_commands.h) now records transition, UAV and
aliasing barriers (split barriers record their end half) and full-view
ClearDepthStencilView next to ClearRenderTargetView.

vulkan_replay.h (was vulkan_clear.h) maps D3D12 resource states to Vulkan
layout/access/stage (section 4.3 table), decodes subresource indices including
depth/stencil planes, validates the whole list before emitting anything, and
wraps clears in a layout round trip so images stay in their D3D12 state. The
caller no longer manages layouts by hand.

Tests: command_list_test (recording rules), d3d12_state_map_test (state table,
subresource decoding, constants checked against d3d12.h; needs Vulkan headers
only) and vk_command_replay_test (GPU readback of colour, depth and stencil;
LEONIDA_VK_VALIDATION=1 runs it under the Khronos validation layer).
2026-11-21 18:58:48 +01:00