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

Open
github-bot wants to merge 2 commits from github-bot/gh-499 into main AGit
Owner

@⁠jujumoneylol on GitHub · 2026-11-24 06:30 UTC · original
jujumoneylol:pr/d3d12-execind-graphics → main · +1072 −163 · 10 files · 2 commits · open

Claimed in the coordination issue as: D3D-EXECIND-GRAPHICS (#14)

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)
**@⁠jujumoneylol** on GitHub · 2026-11-24 06:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/499) `jujumoneylol:pr/d3d12-execind-graphics` → `main` · +1072 −163 · 10 files · 2 commits · open Claimed in the coordination issue as: D3D-EXECIND-GRAPHICS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:04:16 +00:00
Author
Owner

@⁠moffington on GitHub · 2026-11-24 07:03 UTC · original

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.

**@⁠moffington** on GitHub · 2026-11-24 07:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/499#issuecomment-7124576436) 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.
Author
Owner

@⁠jujumoneylol on GitHub · 2026-11-24 07:51 UTC · original

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** on GitHub · 2026-11-24 07:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/499#issuecomment-7125444908) 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.
Author
Owner

@⁠jujumoneylol on GitHub · 2026-11-24 21:59 UTC · original

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.

**@⁠jujumoneylol** on GitHub · 2026-11-24 21:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/499#issuecomment-7145648836) 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.
This pull request has changes conflicting with the target branch.
  • runtime/shims/d3d12_com.cpp
  • runtime/shims/d3d12_vulkan_device.cpp
  • runtime/src/vulkan_backend.h
  • runtime/src/vulkan_replay.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/499/head:github-bot/gh-499'
git switch 'github-bot/gh-499'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-499'
git switch 'github-bot/gh-499'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-499'
git switch 'github-bot/gh-499'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-499'
git switch 'main'
git merge --squash 'github-bot/gh-499'
git switch 'main'
git merge --ff-only 'github-bot/gh-499'
git switch 'main'
git merge 'github-bot/gh-499'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.