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

Open
opened 2026-11-26 20:18:15 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/499
Author: @jujumoneylol
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: pr/d3d12-execind-graphics


📝 Commits (2)

  • 106c718 d3d12/vulkan: replay full graphics state for ExecuteIndirect DRAW and DRAW_INDEXED
  • 3093a84 d3d12/vulkan: gate indirect draw replay on multiDrawIndirect and drawIndirectCount

📊 Changes

10 files changed (+1072 additions, -163 deletions)

View changed files

📝 runtime/CMakeLists.txt (+9 -1)
📝 runtime/shims/d3d12_com.cpp (+9 -0)
📝 runtime/shims/d3d12_com.h (+4 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+5 -0)
📝 runtime/src/command_list.h (+6 -0)
📝 runtime/src/vulkan_backend.h (+14 -2)
📝 runtime/src/vulkan_replay.h (+197 -160)
➕ runtime/test/d3d12_indirect_draw_test.cpp (+782 -0)
📝 runtime/test/d3d12_state_map_test.cpp (+40 -0)
📝 runtime/test/vk_test_device.h (+6 -0)

📄 Description

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/499 **Author:** [@jujumoneylol](https://github.com/jujumoneylol) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/d3d12-execind-graphics` --- ### 📝 Commits (2) - [`106c718`](https://github.com/ubiquitarianism/leonida/commit/106c718fd9168150d2c16df1cdc6210867b3f435) d3d12/vulkan: replay full graphics state for ExecuteIndirect DRAW and DRAW_INDEXED - [`3093a84`](https://github.com/ubiquitarianism/leonida/commit/3093a84932b2688c45accdf1d9c50154250f760a) d3d12/vulkan: gate indirect draw replay on multiDrawIndirect and drawIndirectCount ### 📊 Changes **10 files changed** (+1072 additions, -163 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+9 -1) 📝 `runtime/shims/d3d12_com.cpp` (+9 -0) 📝 `runtime/shims/d3d12_com.h` (+4 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+5 -0) 📝 `runtime/src/command_list.h` (+6 -0) 📝 `runtime/src/vulkan_backend.h` (+14 -2) 📝 `runtime/src/vulkan_replay.h` (+197 -160) ➕ `runtime/test/d3d12_indirect_draw_test.cpp` (+782 -0) 📝 `runtime/test/d3d12_state_map_test.cpp` (+40 -0) 📝 `runtime/test/vk_test_device.h` (+6 -0) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#549
No description provided.