Skip to content

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

Open
jujumoneylol wants to merge 2 commits into
ProjectLeonida:mainfrom
jujumoneylol:pr/d3d12-execind-graphics
Open

jujumoneylol wants to merge 2 commits into
ProjectLeonida:mainfrom
jujumoneylol:pr/d3d12-execind-graphics

Conversation

@jujumoneylol

Copy link
Copy Markdown
Contributor

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

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)

@moffington

Copy link
Copy Markdown
Contributor

Reviewed 72f8719 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

Copy link
Copy Markdown
Contributor Author

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.

demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…on multiDrawIndirect and drawIndirectCount

# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
#	runtime/src/vulkan_replay.h
#	runtime/test/vk_test_device.h
demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…nd multi-scissor rendering (1..16 viewports/scissors)

Resolved against ProjectLeonida#499's emit_graphics_pass, ProjectLeonida#469's depth bounds and ProjectLeonida#511's lazy modules: the viewport/scissor setup moves into emit_graphics_pass, the pipeline's dynamic-state list keeps DEPTH_BOUNDS and picks the *_WITH_COUNT states, and ProjectLeonida#499's ExecuteIndirect draws now carry the bound depth bounds and viewports like record_draw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…nd depth bounds (ProjectLeonida#469), like record_draw

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 24, 2026
@jujumoneylol

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants