d3d12/vulkan: replay full graphics state for ExecuteIndirect DRAW and DRAW_INDEXED (D3D-EXECIND-GRAPHICS) #499

Closed
jujumoneylol wants to merge 2 commits from upstream-pr/499 into main
jujumoneylol commented 2026-11-24 06:30:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by jujumoneylol on 2026-11-24T06:30:02Z.


Claimed in the coordination issue as: D3D-EXECIND-GRAPHICS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7123837093)

Depends on: #469 (adjacent lines in vulkan_replay.h draw replay, d3d12_vulkan_device.cpp feature enables, and vk_test_device.h if both merge; this branch is based cleanly on current main 8f481cf16 with no code dependency on #469)

What and why

Previously, ExecuteIndirect for graphics draw signatures (D3D12_INDIRECT_ARGUMENT_TYPE_DRAW and D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED) only validated the argument/count buffers and emitted a bare vkCmdDrawIndirect* call without snapshotting graphics state, starting dynamic rendering, or binding the graphics pipeline, render targets, push constants, viewport/scissor, or vertex/index buffers. In addition, neither create_vulkan_device_standalone nor vktest::Device enabled Vulkan's multiDrawIndirect or drawIndirectCount features required for max_count > 1 and GPU count buffers.

  • Command list snapshot (runtime/src/command_list.h, runtime/shims/d3d12_com.cpp):
    • Adds bool has_draw + Draw draw to leonida::ExecuteIndirect.
    • When ExecuteIndirect is recorded for draw or draw_indexed with max_command_count > 0 and a bound graphics pipeline, root signature, and primitive topology, snapshots the full graphics state (pipeline, root user data, render targets, depth target, vertex/index buffer views, viewport, scissor, blend factor, stencil refs), matching DrawInstanced / DrawIndexedInstanced (including the zero-viewport early-out).
    • Leaves has_draw == false when no graphics PSO is bound or max_command_count == 0, preserving existing Close() validation parity (d3d12_indirect_zero_test, d3d12_execute_indirect_validation_test) and bare-IR tests (d3d12_indirect_rt_test).
  • Replay (runtime/src/vulkan_replay.h):
    • Prepares ind->draw via detail::prepare_draw (resolving targets, format variants, vertex buffers, and index buffer).
    • Factors out a shared emit_graphics_pass helper used by both direct Draw and graphics ExecuteIndirect so dynamic rendering, attachment layout transitions, pipeline, bindless set, push constants, dynamic state, and vertex/index buffer bindings are identical.
    • Treats max_count == 0 as a clean no-op without opening an empty render pass.
  • Vulkan device features (runtime/shims/d3d12_vulkan_device.cpp, runtime/test/vk_test_device.h):
    • Enables VkPhysicalDeviceFeatures::multiDrawIndirect and VkPhysicalDeviceVulkan12Features::drawIndirectCount where supported by the GPU.
  • Live GPU host-parity test (runtime/test/d3d12_indirect_draw_test.cpp):
    • Self-contained (in-memory SPIR-V 1.3 VB-backed VS + passthrough PS, no external shader compiler required; HLSL via d3dcompiler_47 for host reference).
    • Exercises 11 cases (DRAW fixed/multi/padded-stride, DRAW with GPU count buffer 0/1/clamped 5>2, DRAW_INDEXED multi/padded-stride with BaseVertexLocation, DRAW_INDEXED with GPU count buffer 1/2, and max_count = 0 no-op), comparing all 64/64 pixels byte-for-byte against host Windows D3D12 on the same adapter.

Tested

  • Built d3d12_indirect_draw_test, d3d12_indirect_zero_test, d3d12_execute_indirect_validation_test, and d3d12_state_map_test with MSVC 19.44 (vcvars64) + Ninja on top of main 8f481cf16.
  • d3d12_indirect_draw_test: ALL 11 CASES PASSED (EXACT MATCH vs host D3D12) — 64/64 pixels exact on every case on NVIDIA GeForce GTX 1650 with 0 validation errors.
  • d3d12_indirect_zero_test: PASSED (6/6 exact vs GTX 1650 & WARP).
  • d3d12_state_map_test: PASSED.
  • py -3.13 -I scripts/check_no_game_data.py on all 7 touched files: clean.

GPUs tested: NVIDIA GeForce GTX 1650 Mobile 4 GB (driver 592.00, Vulkan 1.4.325, Windows 11 26200)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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. (n/a — D3D12 → Vulkan runtime only)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5467301315 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/499). Originally posted by [jujumoneylol](https://github.com/jujumoneylol) on 2026-11-24T06:30:02Z. --- Claimed in the coordination issue as: D3D-EXECIND-GRAPHICS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7123837093) Depends on: #469 (adjacent lines in `vulkan_replay.h` draw replay, `d3d12_vulkan_device.cpp` feature enables, and `vk_test_device.h` if both merge; this branch is based cleanly on current `main` `8f481cf16` with no code dependency on #469) ### What and why Previously, `ExecuteIndirect` for graphics draw signatures (`D3D12_INDIRECT_ARGUMENT_TYPE_DRAW` and `D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED`) only validated the argument/count buffers and emitted a bare `vkCmdDrawIndirect*` call without snapshotting graphics state, starting dynamic rendering, or binding the graphics pipeline, render targets, push constants, viewport/scissor, or vertex/index buffers. In addition, neither `create_vulkan_device_standalone` nor `vktest::Device` enabled Vulkan's `multiDrawIndirect` or `drawIndirectCount` features required for `max_count > 1` and GPU count buffers. - **Command list snapshot (`runtime/src/command_list.h`, `runtime/shims/d3d12_com.cpp`)**: - Adds `bool has_draw` + `Draw draw` to `leonida::ExecuteIndirect`. - When `ExecuteIndirect` is recorded for `draw` or `draw_indexed` with `max_command_count > 0` and a bound graphics pipeline, root signature, and primitive topology, snapshots the full graphics state (pipeline, root user data, render targets, depth target, vertex/index buffer views, viewport, scissor, blend factor, stencil refs), matching `DrawInstanced` / `DrawIndexedInstanced` (including the zero-viewport early-out). - Leaves `has_draw == false` when no graphics PSO is bound or `max_command_count == 0`, preserving existing `Close()` validation parity (`d3d12_indirect_zero_test`, `d3d12_execute_indirect_validation_test`) and bare-IR tests (`d3d12_indirect_rt_test`). - **Replay (`runtime/src/vulkan_replay.h`)**: - Prepares `ind->draw` via `detail::prepare_draw` (resolving targets, format variants, vertex buffers, and index buffer). - Factors out a shared `emit_graphics_pass` helper used by both direct `Draw` and graphics `ExecuteIndirect` so dynamic rendering, attachment layout transitions, pipeline, bindless set, push constants, dynamic state, and vertex/index buffer bindings are identical. - Treats `max_count == 0` as a clean no-op without opening an empty render pass. - **Vulkan device features (`runtime/shims/d3d12_vulkan_device.cpp`, `runtime/test/vk_test_device.h`)**: - Enables `VkPhysicalDeviceFeatures::multiDrawIndirect` and `VkPhysicalDeviceVulkan12Features::drawIndirectCount` where supported by the GPU. - **Live GPU host-parity test (`runtime/test/d3d12_indirect_draw_test.cpp`)**: - Self-contained (in-memory SPIR-V 1.3 VB-backed VS + passthrough PS, no external shader compiler required; HLSL via `d3dcompiler_47` for host reference). - Exercises 11 cases (`DRAW` fixed/multi/padded-stride, `DRAW` with GPU count buffer 0/1/clamped 5>2, `DRAW_INDEXED` multi/padded-stride with `BaseVertexLocation`, `DRAW_INDEXED` with GPU count buffer 1/2, and `max_count = 0` no-op), comparing all 64/64 pixels byte-for-byte against host Windows D3D12 on the same adapter. ### Tested - Built `d3d12_indirect_draw_test`, `d3d12_indirect_zero_test`, `d3d12_execute_indirect_validation_test`, and `d3d12_state_map_test` with MSVC 19.44 (`vcvars64`) + Ninja on top of `main` `8f481cf16`. - `d3d12_indirect_draw_test`: **ALL 11 CASES PASSED (EXACT MATCH vs host D3D12)** — 64/64 pixels exact on every case on NVIDIA GeForce GTX 1650 with 0 validation errors. - `d3d12_indirect_zero_test`: PASSED (6/6 exact vs GTX 1650 & WARP). - `d3d12_state_map_test`: PASSED. - `py -3.13 -I scripts/check_no_game_data.py` on all 7 touched files: clean. GPUs tested: NVIDIA GeForce GTX 1650 Mobile 4 GB (driver 592.00, Vulkan 1.4.325, Windows 11 26200) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — D3D12 → Vulkan runtime only)
moffington commented 2026-11-24 07:03:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by moffington on 2026-11-24T07:03:56Z.


Reviewed 72f87190 and tested under Wine 11.20 on Linux with an RTX 3060. d3d12_indirect_draw passed all 11 cases, along with the focused indirect, direct-draw and replay tests I ran. Under Wine, the new draw test checks two pixels per case; its native Windows D3D12 comparison is skipped.

I found one feature-handling issue using custom Vulkan devices with features deliberately disabled:

  • With multiDrawIndirect disabled, a draw with max_count = 2 returned replay success but produced VUID-vkCmdDrawIndirect-drawCount-02718.
  • With drawIndirectCount disabled, a counted draw returned replay success but produced VUID-vkCmdDrawIndirectCount-None-04445.

As a control, max_count = 1 with multiDrawIndirect disabled passed without a draw validation error. Could replay gate these paths on the enabled features, or provide a supported fallback?

The new draw test built against the baseline triggered draw validation errors and hung submission, so it did distinguish the original path in my run. d3d12_indirect_zero skipped under Wine; d3d12_indirect_dispatch_count failed identically on the PR and baseline.

AI-assisted review and validation.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7124576436 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/499#issuecomment-7124576436). Originally posted by [moffington](https://github.com/moffington) on 2026-11-24T07:03:56Z. --- Reviewed 72f87190 and tested under Wine 11.20 on Linux with an RTX 3060. d3d12_indirect_draw passed all 11 cases, along with the focused indirect, direct-draw and replay tests I ran. Under Wine, the new draw test checks two pixels per case; its native Windows D3D12 comparison is skipped. I found one feature-handling issue using custom Vulkan devices with features deliberately disabled: - With multiDrawIndirect disabled, a draw with max_count = 2 returned replay success but produced VUID-vkCmdDrawIndirect-drawCount-02718. - With drawIndirectCount disabled, a counted draw returned replay success but produced VUID-vkCmdDrawIndirectCount-None-04445. As a control, max_count = 1 with multiDrawIndirect disabled passed without a draw validation error. Could replay gate these paths on the enabled features, or provide a supported fallback? The new draw test built against the baseline triggered draw validation errors and hung submission, so it did distinguish the original path in my run. d3d12_indirect_zero skipped under Wine; d3d12_indirect_dispatch_count failed identically on the PR and baseline. AI-assisted review and validation.
jujumoneylol commented 2026-11-24 07:51:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by jujumoneylol on 2026-11-24T07:51:16Z.


Thanks for the thorough review and testing on Linux/Wine + RTX 3060, @moffington! Great catch on custom Vulkan devices with those features disabled.

Fixed in bc243a4e4:

  1. multiDrawIndirect disabled (VUID-vkCmdDrawIndirect-drawCount-02718):

    • Added ReplayFunctions::multi_draw_indirect (configured from VulkanDeviceInfo::features.multiDrawIndirect via VulkanContext::configure_indirect_draw).
    • When multiDrawIndirect is off, fixed multi-draw ExecuteIndirect (DRAW and DRAW_INDEXED) now falls back to max_count single-draw calls (drawCount = 1 at arguments + k * stride), keeping full multi-draw functionality without violating the VUID.
  2. drawIndirectCount disabled (VUID-vkCmdDrawIndirectCount-None-04445):

    • Added VulkanDeviceInfo::draw_indirect_count (populated from VkPhysicalDeviceVulkan12Features::drawIndirectCount in standalone creation and vktest::Device).
    • VulkanContext::configure_indirect_draw now leaves replay_.draw_indirect_count and replay_.draw_indexed_indirect_count null when drawIndirectCount is disabled (even though vkGetDeviceProcAddr returns core 1.2 pointers), so prepare() cleanly rejects counted graphics draws with ReplayResult::unsupported (while max_count == 0 stays a no-op).
  3. Regression tests added:

    • d3d12_state_map_test: verifies multi_draw_indirect = false emits drawCount = 1 calls at offset + k * stride, and null draw_indirect_count / draw_indexed_indirect_count rejects counted draws with ReplayResult::unsupported (and accepts max_count == 0).
    • d3d12_indirect_draw_test: spins up two custom vktest::Device instances — one with request_multi_draw_indirect = false (verifies all 4 DRAW / DRAW_INDEXED max_count = 2 cases render exact red+green pixels) and one with request_draw_indirect_count = false (verifies counted DRAW and DRAW_INDEXED lists are rejected cleanly leaving the cleared target untouched).

Re-verified on Windows 11 26200 / NVIDIA GTX 1650 (d3d12_indirect_draw_test 11 host-parity + 6 feature-gating cases, d3d12_indirect_zero_test, d3d12_state_map_test, d3d12_vulkan_device_test, and scripts/check_no_game_data.py all pass).

AI-assisted fix and verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7125444908 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/499#issuecomment-7125444908). Originally posted by [jujumoneylol](https://github.com/jujumoneylol) on 2026-11-24T07:51:16Z. --- Thanks for the thorough review and testing on Linux/Wine + RTX 3060, @moffington! Great catch on custom Vulkan devices with those features disabled. Fixed in `bc243a4e4`: 1. **`multiDrawIndirect` disabled (`VUID-vkCmdDrawIndirect-drawCount-02718`):** - Added `ReplayFunctions::multi_draw_indirect` (configured from `VulkanDeviceInfo::features.multiDrawIndirect` via `VulkanContext::configure_indirect_draw`). - When `multiDrawIndirect` is off, fixed multi-draw `ExecuteIndirect` (`DRAW` and `DRAW_INDEXED`) now falls back to `max_count` single-draw calls (`drawCount = 1` at `arguments + k * stride`), keeping full multi-draw functionality without violating the VUID. 2. **`drawIndirectCount` disabled (`VUID-vkCmdDrawIndirectCount-None-04445`):** - Added `VulkanDeviceInfo::draw_indirect_count` (populated from `VkPhysicalDeviceVulkan12Features::drawIndirectCount` in standalone creation and `vktest::Device`). - `VulkanContext::configure_indirect_draw` now leaves `replay_.draw_indirect_count` and `replay_.draw_indexed_indirect_count` null when `drawIndirectCount` is disabled (even though `vkGetDeviceProcAddr` returns core 1.2 pointers), so `prepare()` cleanly rejects counted graphics draws with `ReplayResult::unsupported` (while `max_count == 0` stays a no-op). 3. **Regression tests added:** - `d3d12_state_map_test`: verifies `multi_draw_indirect = false` emits `drawCount = 1` calls at `offset + k * stride`, and null `draw_indirect_count` / `draw_indexed_indirect_count` rejects counted draws with `ReplayResult::unsupported` (and accepts `max_count == 0`). - `d3d12_indirect_draw_test`: spins up two custom `vktest::Device` instances — one with `request_multi_draw_indirect = false` (verifies all 4 `DRAW` / `DRAW_INDEXED` `max_count = 2` cases render exact red+green pixels) and one with `request_draw_indirect_count = false` (verifies counted `DRAW` and `DRAW_INDEXED` lists are rejected cleanly leaving the cleared target untouched). Re-verified on Windows 11 26200 / NVIDIA GTX 1650 (`d3d12_indirect_draw_test` 11 host-parity + 6 feature-gating cases, `d3d12_indirect_zero_test`, `d3d12_state_map_test`, `d3d12_vulkan_device_test`, and `scripts/check_no_game_data.py` all pass). AI-assisted fix and verification.
jujumoneylol commented 2026-11-24 21:59:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by jujumoneylol on 2026-11-24T21:59:08Z.


Rebased cleanly onto main 4a50cafc7 (head 3093a8493) to resolve merge conflicts after #510 (multi-viewport) merged; emit_graphics_pass and ExecuteIndirect now also preserve multi-viewport/multi-scissor state automatically.

Re-verified on Windows 11 26200 / NVIDIA GTX 1650: d3d12_indirect_draw_test (11 host-parity + 6 feature-gating cases), d3d12_indirect_zero_test, d3d12_state_map_test, d3d12_multi_viewport_test, tests/test_docs_env_vars.py, and scripts/check_no_game_data.py all pass.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7145648836 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/499#issuecomment-7145648836). Originally posted by [jujumoneylol](https://github.com/jujumoneylol) on 2026-11-24T21:59:08Z. --- Rebased cleanly onto `main` `4a50cafc7` (head `3093a8493`) to resolve merge conflicts after #510 (multi-viewport) merged; `emit_graphics_pass` and `ExecuteIndirect` now also preserve multi-viewport/multi-scissor state automatically. Re-verified on Windows 11 26200 / NVIDIA GTX 1650: `d3d12_indirect_draw_test` (11 host-parity + 6 feature-gating cases), `d3d12_indirect_zero_test`, `d3d12_state_map_test`, `d3d12_multi_viewport_test`, `tests/test_docs_env_vars.py`, and `scripts/check_no_game_data.py` all pass.
MoonEyes commented 2026-11-28 17:58:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:58:28Z.


Hi @jujumoneylol, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/shims/d3d12_com.cpp, runtime/shims/d3d12_vulkan_device.cpp, runtime/src/vulkan_backend.h, runtime/src/vulkan_replay.h), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243430510 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/499#issuecomment-7243430510). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T17:58:28Z. --- Hi @jujumoneylol, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/shims/d3d12_com.cpp`, `runtime/shims/d3d12_vulkan_device.cpp`, `runtime/src/vulkan_backend.h`, `runtime/src/vulkan_replay.h`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:30:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:30:35Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317724023 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/499#issuecomment-7317724023). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:30:35Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!499
No description provided.