Skip to content

Runtime: barriers into PREDICATION cover conditional rendering's read (D3D-15/D3D-18 follow-up) - #858

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
traeb0n:d3d12-predication-sync
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
traeb0n:d3d12-predication-sync

Conversation

@traeb0n

@traeb0n traeb0n commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

New D3D item, a follow-up to D3D-15 (#278) and D3D-18 (claim).

The problem

D3D12_RESOURCE_STATE_PREDICATION is the same bit as INDIRECT_ARGUMENT (0x200). Likewise, SYNC_PREDICATION / ACCESS_PREDICATION are the same bits as EXECUTE_INDIRECT / INDIRECT_ARGUMENT. The layer mapped that bit only to INDIRECT_COMMAND_READ at DRAW_INDIRECT. But vkCmdBeginConditionalRenderingEXT reads the predicate with VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT at VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT, and the replay adds no barrier of its own at SetPredication. So the usual occlusion-culling sequence:

ResolveQueryData(heap, ..., predicate, 0)
ResourceBarrier(predicate: COPY_DEST -> PREDICATION)
SetPredication(predicate, 0, ...)

had no dependency from the resolve's write to the predicate read. Nothing ordered the read before the next resolve either (PREDICATION -> COPY_DEST).

The change

  • vulkan_access(states, presentable, conditional_rendering) and vulkan_barrier_scope(sync, access, conditional_rendering): when the extension is enabled, the PREDICATION bit also adds the conditional-rendering access and stage. That's the only case those flags are valid. GENERIC_READ contains the bit, so it gets them too. access_stages learns which stages can perform CONDITIONAL_RENDERING_READ, so a scope like SYNC_COPY with ACCESS_PREDICATION widens correctly. Without the extension the mappings are unchanged, and the new parameter defaults to off.
  • emit passes the flag (vk.begin_conditional_rendering != nullptr, set only when the extension is enabled).
  • d3d12_state::predication names the state alias, with a static_assert against the SDK.

Tests

  • d3d12_state_map_test: both mappings with and without the extension, the GENERIC_READ case, a pair that has to widen, and the unchanged pairs.
  • d3d12_vulkan_device_test now enables conditional rendering on its device (info.conditional_rendering), so SetPredication runs through the D3D12 device for the first time. A new block resolves an occlusion query into a predicate. EQUAL_ZERO skips a clear and NOT_EQUAL_ZERO runs one, since there are no draws yet and the count is 0. The predicate is then resolved into again after the read. This runs once through legacy barriers and once through enhanced buffer barriers, with fence values 12 and 13.

To be clear about what the GPU test does and doesn't show: the hazard doesn't show up on NVIDIA, and the validation layer's synchronization checks report nothing on it even before the fix. So the new device-test block passes before and after this change. The regression guard is the state-map unit test. The GPU block is the first end-to-end check of queries plus predication, and it proves the new stage and access masks are accepted by the validation layer in both barrier models.

Tested on an NVIDIA GeForce RTX 5070, driver 621.01, Windows 11, MSVC 14.44 (VS 2022 Build Tools), Vulkan SDK 1.4.363, at 4a36bb1:

  • ctest -E loader: 28/28. loader_test is excluded because it hangs on this PC; that's unrelated and also happens on main.
  • d3d12_vulkan_device_test and d3d12_com_test with LEONIDA_VK_VALIDATION=1: pass, 0 validation errors.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

D3D12_RESOURCE_STATE_PREDICATION is the same bit as INDIRECT_ARGUMENT
(and SYNC/ACCESS_PREDICATION the same as EXECUTE_INDIRECT /
INDIRECT_ARGUMENT), and the layer mapped that bit only to
INDIRECT_COMMAND_READ at DRAW_INDIRECT. vkCmdBeginConditionalRenderingEXT
reads the predicate with CONDITIONAL_RENDERING_READ at the
CONDITIONAL_RENDERING stage, so ResolveQueryData -> COPY_DEST to
PREDICATION barrier -> SetPredication had no dependency from the copy's
write to the predicate read (and none the other way before the next
resolve).

With the extension enabled (the only case those flags are valid),
vulkan_access and vulkan_barrier_scope now add the conditional-rendering
access and stage for that bit; GENERIC_READ, which contains it, gets
them too. The replay passes the flag from its conditional-rendering
entry points.

d3d12_vulkan_device_test now enables conditional rendering on its device
and runs an occlusion query resolved into a predicate: EQUAL_ZERO skips a
clear, NOT_EQUAL_ZERO runs one, and the predicate is resolved into again
after the read, once through legacy barriers and once through enhanced
buffer barriers. d3d12_state_map_test checks both mappings with and
without the extension.

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

Copy link
Copy Markdown
Contributor

Tested d868cba on an NVIDIA GeForce RTX 3070, driver 610.88, Windows 11 (26300), MSVC 19.44 (VS generator, RelWithDebInfo), Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1: pass

  • Build passes, ctest 26/26.
  • d3d12_vulkan_device_test: exit 0, with 0 validation and 0 synchronization-hazard messages. The new occlusion-query → COPY_DEST → PREDICATION → COPY_DEST section ran (the 3070 has VK_EXT_conditional_rendering, so no "skipped" line).
  • d3d12_state_map_test, d3d12_com_test and vk_command_replay_test A to F (E is Runtime: SetPredication on VK_EXT_conditional_rendering (D3D-18) #258's predicated clears): pass, with no validation messages.

Code read, as the author of #258: the mapping is right. PREDICATION shares its bit with INDIRECT_ARGUMENT, so on main a barrier into it never covered CONDITIONAL_RENDERING_READ. Adding the access and stage only when the extension is enabled keeps both valid. The access_stages entry makes a SYNC_COPY + ACCESS_PREDICATION scope widen correctly.

Two small things:

AI-assisted (Claude Code).

@quackottu quackottu 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.

Tested d868cba on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

  • ctest -C RelWithDebInfo: 100% tests passed, 0 tests failed out of 32
  • d3d12_state_map_test (changed here): exit=0 validation=0 | state map, enhanced barriers, subresource decoding, layout tracking and BAR detection OK
  • d3d12_vulkan_device_test (changed here): exit=0 validation=0 | [rt] d3d12: upload heaps in VRAM (DEVICE_LOCAL | HOST_VISIBLE, Resizable BAR)
  • 33 test programs in the build pass with 0 validation errors
  • d3d12_clear_test fails (R8G8B8A8_UNORM/SNORM 0.5 ties and a D16 clear byte differ from WARP) exactly as on main 4a36bb1 here, so not from this PR; #521 addresses it

Implicit Vulkan layers (overlays) were off through an empty VK_IMPLICIT_LAYER_PATH.

@ItsNotRexed
ItsNotRexed merged commit 9b21cde into ItsNotRexed:main Nov 22, 2026
10 checks passed
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
…d_wait

#850 moved the waits to a counter, but the 1D-texture block still signalled 8 and #858's predication block
12/13. Once the counter had passed those values, SetEventOnCompletion returned at once and the blocks read results
the GPU had not written yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
…longer hides heap_desc (C4456)

The occlusion-query block from #858 declared a D3D12_QUERY_HEAP_DESC
named heap_desc inside the function that already has a
D3D12_DESCRIPTOR_HEAP_DESC heap_desc (line 2107), and MSVC /W4 warned
C4456. Rename it to query_heap_desc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

4 participants