Skip to content

d3d12: advertise WriteBufferImmediate on direct, bundle and compute lists - #8457

Closed
Kalmarv wants to merge 2 commits into
ProjectLeonida:mainfrom
Kalmarv:fix/write-buffer-immediate-caps
Closed

Kalmarv wants to merge 2 commits into
ProjectLeonida:mainfrom
Kalmarv:fix/write-buffer-immediate-caps

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 23, 2026 •

Copy link
Copy Markdown

d3d12: advertise WriteBufferImmediate on DIRECT, BUNDLE and COMPUTE lists

Claimed in #8344 (#8344 (comment)).

Depends on: #8187. replay_write_immediate_barriers_test's ordering part fails on main until #8187 is merged. This is by design: that is the ordering this PR's capability bits rely on.

CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3) answered WriteBufferImmediateSupportFlags = NONE. But WriteBufferImmediate records on every list type, and replay runs it as vkCmdUpdateBuffer (#417). The layer now answers DIRECT | BUNDLE | COMPUTE (0x7).

Why not COPY yet (review by @tupacfan04):

Legacy barriers (COPY_DEST → TRANSFER), SYNC_ALL and the MARKER modes' own barriers are ordered on every queue.

Measured on the same adapter: native D3D12 answers 0x7f (RTX 5070 Ti, driver 610.74) and WARP answers 0xF. 0x7 is a subset of both, as the host check in d3d12_vulkan_device_test requires.

Changes

  • runtime/shims/d3d12_vulkan_device.cpp: the OPTIONS3 answer, with the reason COPY is left out. The BarycentricsSupported line beside it is untouched.
  • runtime/test/d3d12_vulkan_device_test.cpp: the local invariant expects 0x7.
  • New runtime/test/replay_write_immediate_barriers_test.cpp (no GPU). It mocks vkCmdPipelineBarrier/2 and vkCmdUpdateBuffer and checks:
    • the barrier each mode records:
      • DEFAULT: none;
      • MARKER_IN: ALL_COMMANDS → TRANSFER, no access;
      • MARKER_OUT: ALL_COMMANDS/MEMORY_WRITE → TRANSFER/TRANSFER_WRITE;
      • each barrier comes before the update, which carries the right value;
    • ordering: on the DIRECT queue (no mask) and under queue_stages_compute, a DEFAULT write, a SYNC_COPY buffer barrier (COPY_DEST → COPY_SOURCE) and a copy must record, in that order, the update, then a barrier whose first scope holds CLEAR and the transfer write, then the copy. The COPY-queue case is left to the separate claim.
  • New runtime/test/d3d12_write_immediate_queues_test.cpp (GPU, skips with 77):
    • DIRECT, COMPUTE and bundle-via-DIRECT lists write all three modes and the values are read back;
    • a COPY list does the same, as replay coverage only; the capability is not claimed;
    • the capability check expects 0x7;
    • it prints the Vulkan families the COMPUTE and COPY queues use.
    • Values do not distinguish the modes; the barrier test above does.

Tested

Windows 11, MSVC 2022 Build Tools, Ninja RelWithDebInfo.

Overlap

#8232 edits the same OPTIONS3 block and the same test line for BarycentricsSupported. The conflict is textual only.

AI-assisted (Claude Code): written with Claude Code and reviewed by a second agent. No game data, keys or online services were used.

🤖 Generated with Claude Code

…MPUTE and COPY lists

CheckFeatureSupport(OPTIONS3) answered WriteBufferImmediateSupportFlags NONE, although
WriteBufferImmediate records on every list type and replays as vkCmdUpdateBuffer on any queue
family since D3D-26 (ItsNotRexed#417). WARP answers DIRECT | BUNDLE | COMPUTE | COPY (0xF), and native
D3D12 on an RTX 5070 Ti (driver 610.74) answers 0x7f, which adds the video list types. The
layer now answers 0xF, a subset of both, so the same-adapter host comparison in
d3d12_vulkan_device_test still holds. Its local invariant now expects that value.

The new d3d12_write_immediate_queues test holds each advertised type to it:
- a DIRECT, a COMPUTE and a COPY list, each on its own queue, write the three modes into a
  readback buffer;
- a bundle executed by a DIRECT list does the same;
- each of the three lists then copies a word and overwrites it with a MARKER_OUT write, which
  must land last;
- the test prints which Vulkan families the COMPUTE and COPY queues lease from.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@tupacfan04 tupacfan04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 0xF flag set matches the recording code and the test exercises all four list types, but COPY is advertised while a known ordering hole remains.

  • queue_stages_copy (runtime/src/vulkan_replay.h:1263-1265) has TRANSFER/COPY but no CLEAR.
  • vulkan_sync() maps D3D12_BARRIER_SYNC_COPY to VK_PIPELINE_STAGE_2_COPY_BIT only (:216).
  • restrict_to_queue() masks the stage to the queue's stages (:1270-1281), removing the CLEAR stage.
  • WriteImmediate replays as vkCmdUpdateBuffer in the CLEAR/transfer path (:3884-3900), with no barrier for DEFAULT.

A title that sees COPY in WriteBufferImmediateSupportFlags and uses a DEFAULT-mode WBI followed by an enhanced SYNC_COPY barrier gets no ordering — the PR body itself documents this. Either do not advertise COPY until queue_stages_copy includes CLEAR and the enhanced mapping is fixed, or fix it and add a COPY-list test with DEFAULT WBI, SYNC_COPY, and a readback. The new d3d12_write_immediate_queues_test uses MARKER_OUT and a legacy CopyBufferRegion, so it misses this.

Test gap: write_three() issues all three modes and landed() checks only the final values. The implementation could ignore modes, or swap MARKER_IN/MARKER_OUT, and every value check would pass; the copy-then-MARKER_OUT case is also weak because both are transfer commands. Add an earlier non-transfer op (dispatch/render write) followed by MARKER_IN/MARKER_OUT and a visibility check, or an invalid-mode/HRESULT test.

Clean: the 0xF subset, recording on every list type, type creation/execution, mode/value/copy/capability/Close checks, 77 skip and 30 s timeout; the current mode constants and replay barriers are correct. Synthetic only; no game files. AI-assisted (OpenCode).

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Author

Returned this to draft while we resolve the enhanced-barrier ordering concern. The existing tests establish write execution and the measured capability subset, but do not establish DEFAULT-mode WBI ordering through enhanced SYNC_COPY barriers. We are checking the exact #8187 dependency and the remaining queue-stage filtering against current ownership before proposing a change; we will not duplicate that author's implementation. We will also keep the marker-mode coverage claims limited to what the tests actually exercise.

@lohant27-netizen

Copy link
Copy Markdown

Tested ac1da4534 on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 2a3b3b554 together with #8457, #8454, #8373, #8364 and #8340 (no conflicts between them): pass.

@Grimkaaah Grimkaaah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Linux CPU review (ac1da453) — code read

What changed: OPTIONS3.WriteBufferImmediateSupportFlags advertises DIRECT/BUNDLE/COMPUTE/COPY (matching the vkCmdUpdateBuffer replay path), with a new queue-type test.

Checked:

  • Diff is a four-flag advertisement + focused CTest.
  • Did not build/run the C++ test here.

Looks correct; no game files.

@xundru xundru left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the new test on a second NVIDIA generation with the Vulkan validation layer, which the description lists as not run. Setup: Windows 11 26200, RTX 3060 (Ampere), NVIDIA 610.88, Vulkan SDK 1.4.363.1, MSVC 19.44.35230, with ac1da45 applied on main e68c5c9 (applies cleanly).

d3d12_write_immediate_queues_test Result
plain 18/18 PASS
LEONIDA_VK_VALIDATION=1 18/18 PASS, no validation messages
+ VK_KHRONOS_VALIDATION_VALIDATE_SYNC=1 18/18 PASS, no SYNC-HAZARD
+ VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 18/18 PASS, only the layer's own settings warnings

The queue families here match the 5070 Ti: graphics 0, compute 2, copy 1 (own queues).

d3d12_vulkan_device_test: the OPTIONS3 comparison passes with the new 0xF invariant. The run then stops at tiles == 1, exactly as it does on main (the existing #7125 / #8496 failure).

On the COPY ordering gap raised above: sync validation stays silent, but that doesn't rule the gap out. The test records no barriers at all, and its COPY ordering cases use MARKER_OUT, which carries its own barrier. So nothing here runs a DEFAULT-mode write followed by an enhanced SYNC_COPY barrier on a COPY list. A case for exactly that sequence, run under sync validation, would confirm or rule out the hole.

No game files. AI-assisted run.

…ers of each mode

Review of ItsNotRexed#8457: a DEFAULT-mode WriteBufferImmediate followed by an enhanced SYNC_COPY barrier
is not ordered. Replay records the write as vkCmdUpdateBuffer, which synchronization2 runs in
the CLEAR stage, while SYNC_COPY maps to COPY only. ItsNotRexed#8187 adds CLEAR to that mapping, which
orders the DIRECT and COMPUTE queues. The COPY queue's stage mask (queue_stages_copy) drops CLEAR
again, so OPTIONS3 now answers DIRECT | BUNDLE | COMPUTE (0x7). Advertising COPY is deferred to a
follow-up after that mask is fixed. 0x7 is a subset of the native answer on the same adapter (0x7f on an RTX 5070 Ti, driver
610.74) and of WARP's 0xF.

The new replay_write_immediate_barriers_test (no GPU) mocks the barrier and update functions:
- DEFAULT adds no barrier, MARKER_IN waits for every earlier command (ALL_COMMANDS -> TRANSFER,
  no access) and MARKER_OUT for them and their writes (MEMORY_WRITE -> TRANSFER_WRITE). This is
  what the written values cannot show: swapping the two marker modes fails it.
- On the DIRECT queue (no mask) and under queue_stages_compute, a DEFAULT write, a SYNC_COPY
  buffer barrier and a copy record the update, then a barrier holding its CLEAR stage and transfer
  write, then the copy. This part fails until ItsNotRexed#8187 is merged.

d3d12_write_immediate_queues_test expects 0x7 and still runs a COPY list's writes as replay
coverage, without the cap. Its copy-then-MARKER_OUT checks are gone: both are transfer commands,
so they showed no ordering.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Kalmarv Kalmarv changed the title d3d12: advertise implemented WriteBufferImmediate list types d3d12: advertise WriteBufferImmediate on direct, bundle and compute lists Nov 23, 2026
@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Author

Addressed in 85931f8. The advertised flags are now DIRECT|BUNDLE|COMPUTE (0x7), with Depends on: #8187. COPY is not advertised. The COPY-stage filtering/image-initialization guard has a separate bounded claim: #8504 (comment).

The probe showed the enhanced SYNC_COPY gap on all three queue kinds on main. #8187 resolves DIRECT/COMPUTE; COPY still drops CLEAR. This PR remains draft and its ordering tests intentionally fail until #8187 lands.

A CPU mocked-dispatch test now distinguishes DEFAULT, MARKER_IN and MARKER_OUT by their stage/access barriers, verifies the barrier precedes the update, and verifies DEFAULT update -> CLEAR-covering enhanced barrier -> copy on DIRECT/COMPUTE. It passes all 5 checks with #8187 at 1cb2e43. Swapping the marker modes fails their checks; moving the enhanced barrier after the copy also fails despite its correct CLEAR scope. Callbacks use the correct Vulkan function signatures.

The GPU test is now value/replay coverage only. At 0x7 it passes 15/15 on RTX 5070 Ti / 610.74, including COPY execution without claiming that capability. No Vulkan validation layer or AMD/Intel run. Synthetic inputs only; AI-assisted.

@h0useadv

Copy link
Copy Markdown

Tested 85931f8e8 (base dfe4e4ad3, without #8187) on AMD Radeon RX 9070 XT (RDNA4), AMD Windows driver 32.0.32029.2010, Windows 11 Pro build 26300. Built with clang-cl 23.1.6 + lld-link against an xwin splat (MSVC 14.44, SDK 10.0.26100), RelWithDebInfo; synthetic, no game files.

  • d3d12_write_immediate_queues: passes.
  • replay_write_immediate_predication: passes.
  • replay_write_immediate_barriers: fails, as the description says it does without d3d12: SYNC_COPY waits for the CLEAR stage too, so WriteBufferImmediate is ordered (D3D-838) #8187: PASS DEFAULT adds no barrier, PASS MARKER_IN ..., PASS MARKER_OUT ..., then FAIL on the DIRECT queue a SYNC_COPY barrier waits for a DEFAULT write (CLEAR stage, transfer write) and the same FAIL on the COMPUTE queue.
  • Full ctest -j8, failures rerun with -j1: 266/273. Apart from replay_write_immediate_barriers, the failures are the ones main has on this GPU, plus d3d12_indirect_dispatch_count, which fails because this base predates its fix on main.

So no regression; this head should be rechecked together with #8187 for the ordering part.

AI-assisted (Claude Code).

@h0useadv

Copy link
Copy Markdown

Follow-up: same GPU and build, 85931f8e8 with #8187 (1cb2e4302) merged on top (clean merge):

  • replay_write_immediate_barriers: all 5 PASS, including on the DIRECT queue a SYNC_COPY barrier waits for a DEFAULT write (CLEAR stage, transfer write) and the COMPUTE case; exit 0.
  • d3d12_write_immediate_queues: OK, exit 0.

So with #8187 the ordering part holds on RDNA4.

AI-assisted (Claude Code).

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3), AMD Windows driver 32.0.32029.2010, Windows 11, MSVC 14.51 Release, at 85931f8:

replay_write_immediate_barriers d3d12_write_immediate_queues full ctest
this PR alone FAIL: the 2 SYNC_COPY-after-DEFAULT ordering cases (DIRECT, COMPUTE), as the description says pass 236/242. The only new failure is this one
this PR + #8187's diff pass pass (targeted run) replay_write_immediate_predication pass

The other failures in the full run are the same 5 as on main dde82f2 on this card (vk_queue_query_sync, d3d12_vulkan_device tiles == 1, d3d12_texture_tiles, d3d12_depth_resolve, d3d12_pipeline_library_host; see #8426). Nothing else regresses, and the dependency on #8187 holds on AMD too.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants