Skip to content

Runtime: SetPredication on VK_EXT_conditional_rendering (D3D-18) - #258

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Parakeet-Wheat:d3d-18-predication
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Parakeet-Wheat:d3d-18-predication

Conversation

@Parakeet-Wheat

@Parakeet-Wheat Parakeet-Wheat commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

D3D-18 in #156 (docs/d3d12_vulkan.md §4.7).

What and why

ID3D12GraphicsCommandList::SetPredication was a logging stub. It now maps to VK_EXT_conditional_rendering:

  • IR (runtime/src/command_list.h): a Predication command. The offset must be 8-byte aligned and the op EQUAL_ZERO or NOT_EQUAL_ZERO, as D3D12 requires; a null buffer turns predication off and ignores the other arguments. GraphicsCommandList::SetPredication records it.
  • Replay (runtime/src/vulkan_replay.h): vkCmdBeginConditionalRenderingEXT on the predicate buffer, plain for EQUAL_ZERO (Vulkan discards when the word is 0) and VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT for NOT_EQUAL_ZERO. It is ended before a new predicate (conditional rendering cannot nest) and at the end of the list (predication does not carry over to the next list). While a predicate is set, whole-view clears are replayed as one rectangle with vkCmdClearAttachments, because vkCmdClearColorImage/vkCmdClearDepthStencilImage ignore conditional rendering. New ReplayResult::invalid_predication (a predicate that isn't a buffer, or whose word is out of range).
  • Device (runtime/shims/d3d12_vulkan_device.cpp, vulkan_backend.h, d3d12_com.h): the standalone device enables the extension and its conditionalRendering feature when the GPU has them (VulkanDeviceInfo::conditional_rendering), and then creates buffers with VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT. The two entry points reach the replay only when the extension is on. Without it, a predicated list is rejected as unsupported instead of running unpredicated.
  • Bundles: D3D12 doesn't allow SetPredication in a bundle, so it invalidates the bundle like main's other bundle-forbidden calls (Close returns E_INVALIDARG). It's added to the bundle check in d3d12_com_test and to the bundle note in §3.2.
  • Docs: §4.7 says what is done and what is open.

Open (documented in §4.7, not hidden):

  • Copies and resolves. D3D12 predicates CopyBufferRegion/CopyTextureRegion/CopyResource/ResolveSubresource/ResolveSubresourceRegion (resolves are on main since Runtime: ResolveSubresource and multisampled textures on Vulkan #228). Vulkan's conditional rendering doesn't cover transfer commands, so they run unconditionally. PreparedList::unpredicated_copies counts them for the caller. A fix replays them as a compute dispatch once compute pipelines are in (D3D-3).
  • The 64-bit value. Vulkan reads one 32-bit word, so the low dword is used: wrong only when it is 0 and the high dword isn't. A fix is a small compute pass that ORs both dwords.
  • Draws, dispatches and ExecuteIndirect get predication from conditional rendering as soon as they are replayed (D3D-3, D3D-4, D3D-17).

Depends on: #119
Depends on: #278
Depends on: #286
Depends on: #288
Depends on: #291
Depends on: #306
Depends on: #317
Depends on: #335
Depends on: #367
Depends on: #388
Depends on: #391
Depends on: #417
Depends on: #419
Depends on: #469

(None of these is needed for this PR to work. Each one conflicts with it in git. I checked with git merge-tree against every open PR that touches the same files, counting only conflicts this branch adds on top of what the PR already has with main. The overlap is mechanical: a new Command alternative, new ReplayFunctions pointers, a new VulkanDeviceInfo field, a new optional extension in device creation and a new replay test part. #157, #333, #334, #423 and #450 already conflict with main in the same files, so I'll re-check them after they rebase. I'll rebase onto whichever lands first.)

Tested

Windows 11, NVIDIA GeForce RTX 3070 (driver 610.88, Vulkan 1.4.341), Vulkan SDK 1.4.363.0, MSVC 14.44 (VS 2022), rebased on 4abd545. No game files.

  • cmake --build runtime/build --config RelWithDebInfo: builds with no warnings.
  • ctest -C RelWithDebInfo: 19/19, including command_list with the new recording checks (alignment, op, off, closed list).
  • vk_command_replay_test with LEONIDA_VK_VALIDATION=1: parts A to D unchanged (C is main's volume and resolve test, D its barrier test), new part E passes with no validation errors. Five layers, one case each, read back: EQUAL_ZERO on 0 skips a whole-view and a rectangle clear; EQUAL_ZERO on 1 runs; NOT_EQUAL_ZERO on 1 skips; NOT_EQUAL_ZERO on 0 runs; predication turned off runs. A predicate left set at the end of the list is ended by the replay (validation would flag it otherwise). Rejections checked: no extension (unsupported), unknown resource, out-of-range offset and an image as predicate (invalid_predication); one copy under a predicate is counted.
  • d3d12_com_test: passes, including the new bundle check.
  • d3d12_vulkan_device_test: passes with the extension enabled on the standalone device.

(Validation on this PC also reports a loader error from a third-party overlay layer that fails to load; with that layer disabled through VK_LOADER_LAYERS_DISABLE the run has zero validation errors.)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator change.)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@ItsNotRexed

Copy link
Copy Markdown
Owner

Thanks! This conflicts with the D3D12 command path on main (command_list.h, vulkan_replay.h, vulkan_backend.h, d3d12_com.*, after #228, #230, #241). It's core runtime code, so could you rebase onto main?

@kotorvr

kotorvr commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Tested ebff762 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest --test-dir runtime/build --output-on-failure: 15/15 passed.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and VK_LAYER_KHRONOS_validation: d3d12_com_test, d3d12_descriptor_test, d3d12_vulkan_device_test, vk_command_replay_test all exit 0, with 0 validation messages.

No game files used. AI-assisted run (Claude Code).

- 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>
@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested be91840 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest --test-dir runtime/build --output-on-failure: 19/19 passed.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and VK_LAYER_KHRONOS_validation: d3d12_com_test, d3d12_descriptor_test, d3d12_uint_clear_test, d3d12_vulkan_device_test, vk_command_replay_test (including the predication part) all exit 0, with 0 validation messages. No overlay layers needed disabling on this machine.

This re-tests the new head (earlier pass: ebff762).

No game files used. AI-assisted run (Claude Code).

@lohant27-netizen

Copy link
Copy Markdown

Tested: PR head be91840 merged onto main 4abd545, ctest 19/19. vk_command_replay_test part E passes: predicated clears on 5 layers, rejected predicates, and the copy under a predicate counted. Built and run on NVIDIA GeForce RTX 5070, driver 621.01, Windows 11, Vulkan SDK 1.4.363, MSVC 14.44 (VS 2022 Build Tools). All D3D12 GPU tests (d3d12_com_test, d3d12_vulkan_device_test, d3d12_descriptor_test, d3d12_uint_clear_test, vk_command_replay_test) exit 0 with and without LEONIDA_VK_VALIDATION=1, so 0 validation errors. No game files. 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.

4 participants