Skip to content

d3d12: match Windows recording-time ExecuteIndirect validation - #6830

Merged
shayderrr merged 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/d3d12-execute-indirect-validation
Nov 23, 2026
Merged

shayderrr merged 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/d3d12-execute-indirect-validation

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Claim: #6603 (comment)

Summary

Adds host-matched recording-time validation to ID3D12GraphicsCommandList::ExecuteIndirect (runtime/shims/d3d12_com.cpp) and CommandList::execute_indirect (runtime/src/command_list.h), empirically verified against both live Windows 11 WARP and live NVIDIA GeForce RTX 5090 hardware D3D12 (0 disagreements across 49 cases).

Changes

  • runtime/shims/d3d12_com.cpp (GraphicsCommandList::ExecuteIndirect):
    • Require argument_buffer to have Dimension == D3D12_RESOURCE_DIMENSION_BUFFER and argument_buffer_offset % 4 == 0 (even when max_command_count == 0).
    • When count_buffer != nullptr, require Dimension == D3D12_RESOURCE_DIMENSION_BUFFER, count_buffer_offset % 4 == 0, and overflow-safe bounds count_desc.Width >= 4 && count_buffer_offset <= count_desc.Width - 4 (even when max_command_count == 0).
    • When count_buffer == nullptr, require count_buffer_offset == 0 (even when max_command_count == 0).
    • When max_command_count > 0, require overflow-safe argument buffer bounds using Windows D3D12's exact formula (max_command_count - 1) * stride + record_size <= arg_desc.Width - argument_buffer_offset (leaving max_command_count == 0 OOB aligned offsets accepted as no-ops, matching WARP and RTX 5090).
    • Queue-type restrictions (COPY/COMPUTE) are intentionally untouched to avoid overlap with #5252.
  • runtime/src/command_list.h (CommandList::execute_indirect):
    • Reject unaligned stride / argument_offset / count_offset (% 4 != 0) and !count_buffer && count_offset != 0 at recording time.
  • runtime/test/d3d12_state_map_test.cpp:
    • Update the unaligned argument_offset check to reflect recording-time rejection in CommandList::execute_indirect, plus coverage for unaligned count_offset and null count_buffer with non-zero count_offset.
  • runtime/test/d3d12_execute_indirect_validation_test.cpp & runtime/CMakeLists.txt:
    • New 49-case ExecuteIndirect Close() host-parity test comparing the Vulkan layer against live Windows 11 WARP and live hardware D3D12, plus layer null-pointer safety checks and a positive GPU ExecuteIndirect dispatch sanity check (exact-fit padded stride 244 + 12 == 256 and max_command_count == 0 no-op). Registered in CTest with SKIP_RETURN_CODE 77 and FAIL_REGULAR_EXPRESSION "Validation Error;VUID-".

Verification (Windows 11, NVIDIA GeForce RTX 5090, LEONIDA_VK_VALIDATION=1)

  • d3d12_execute_indirect_validation_test: PASS — 49/49 parity cases matched live WARP and live RTX 5090 HW D3D12 (0 disagreements), positive GPU dispatch ok, 0 Vulkan validation errors.
  • d3d12_close_parity_test: PASS — 100 cases, 65 match WARP, 20 known layer-stricter, 15 known layer-looser, 0 failures, 0 validation errors.
  • d3d12_com_test: PASS — 0 validation errors.
  • command_list_test: PASS.
  • d3d12_state_map_test: PASS.
  • d3d12_vulkan_device_test: PASS — 0 validation errors.
  • d3d12_indirect_dispatch_count_test: failed on count 0 update 1: host 6/10, layer 0/0, expected 6/10 (pre-existing GPU replay issue unrelated to recording-time Close() validation; Close() and ExecuteCommandLists both succeed).

100% generic standard D3D12 API parity, zero game data.
AI-assisted (Gemini 4 Neon).

@Bj0rnis

Bj0rnis commented Nov 23, 2026

Copy link
Copy Markdown

Verified on Windows 11 (MSVC 19.44 / Ninja, Vulkan SDK 1.4.363.0) at 2294cfc7 with LEONIDA_VK_VALIDATION=1:

  • NVIDIA GeForce RTX 5070 Ti: 4/4 PASS (d3d12_com, d3d12_execute_indirect_validation, d3d12_draw, d3d12_state_map; 2.07 s, 0 Vulkan validation errors).
  • AMD Radeon(TM) Graphics (iGPU): 4/4 PASS (0.95 s, 0 Vulkan validation errors).

@0xTehuti

Copy link
Copy Markdown
Contributor

Tested \2294cfc7c\ on NVIDIA GeForce RTX 2070 SUPER (Driver 595.79, Vulkan 1.4, Windows 11 Pro 24H2 Build 26100): pass.

  • Environment: MSVC 2022 Community (19.44), Ninja 1.13, CMake 4.4.
  • \d3d12_execute_indirect_validation_test.exe:
    • 49/49 parity cases matched live WARP and live RTX 2070 SUPER hardware D3D12 (0 disagreements, 0 failures).
    • Positive GPU dispatch verified cleanly: \d3d12: 1 translated shaders, \peak end 0.3 of 256.0 MiB, 0 Vulkan validation errors.
  • \command_list_test.exe: Passed (0.01s).
  • \d3d12_state_map_test.exe: Passed (state map, enhanced barriers, layout tracking, BAR detection OK).
  • CTest suite (\d3d12_execute_indirect_validation, \command_list, \d3d12_state_map): 3/3 passed (100%).

Zero game data or private files used (synthetic tests only). AI-assisted.

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardware & Environment

  • Host: Windows 11 Build 26300 x64
  • GPU: AMD Radeon RX 7900 GRE (16 GB VRAM, RDNA3 gfx1100, Vulkan 1.3.296)
  • Toolchain: MSVC 19.44 (Visual Studio 2022), CMake 4.4, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0

Verification Summary

Targets compiled with MSVC 19.44 and executed natively on AMD Radeon RX 7900 GRE:

  1. **\d3d12_execute_indirect_validation_test.exe**:

    • \execute_indirect_validation: 49 parity cases (WARP=live, HW=AMD Radeon RX 7900 GRE), positive GPU dispatch ok, 0 validation errors, 0 failures\
    • Verified 49 validation cases matching live Windows D3D12 (WARP) and native hardware driver (AMD Radeon RX 7900 GRE):
      • Buffer type checking: non-buffer argument or count buffers immediately fail with \E_INVALIDARG.
      • 4-byte alignment checks for \ArgumentBufferOffset\ and \CountBufferOffset.
      • Non-zero \CountBufferOffset\ with null \pCountBuffer\ rejected.
      • Out-of-bounds offset and stride validation for draws, indexed draws, and dispatches.
      • Zero max-command count no-op handling (preserving valid command-list recording state).
      • Positive GPU dispatch execution verified.
  2. **\d3d12_state_map_test.exe**:

    • Passed with zero errors (enhanced barriers, layout tracking, discard ranges, block formats, BAR detection).
  3. CTest:

    • \d3d12_execute_indirect_validation: Passed (0.21s)
    • \d3d12_state_map: Passed (0.01s)
    • Total: 2/2 passed (100%).
  4. Hygiene & Compliance:

    • Clean-room compliant: pure synthetic unit tests; zero game assets or proprietary code.
    • \git diff HEAD~1..HEAD --check: Clean.

LGTM!

@wasonidas

Copy link
Copy Markdown

Independent source and integration review of 2294cfc7cac24696a52b5ad68cf085b5ac506252. The count-buffer subtraction is guarded by the width check. With zero max count the argument buffer is not read, while recording still checks alignment and any supplied count buffer. Compileall, the CLI help smoke check and the text line-ending checks passed on Windows. This review did not rerun host/GPU parity.

The exact heads of #6830, #6610 and #6644 merged without textual conflicts, both pairwise and together (merged tree 2a22f7bc65718733ae84da491401db4ed5fc3ce3). The changes address separate stages: recording validation, rejected submission batches and closed-list state setters. With #6610 present, a list marked invalid by the #6830 recording check is refused before queue submission. This was a source integration check, without running the combined tree.

Synthetic review only. AI-assisted.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

GraphicsCommandList::ExecuteIndirect in runtime/shims/d3d12_com.cpp now checks argument/count buffer dimensions, 4-byte offset alignment, count-buffer bounds and overflow-safe max_command_count stride coverage. CommandList::execute_indirect rejects unaligned stride/argument/count offsets and a null count buffer with nonzero offset at recording time. Adds the 459-line d3d12_execute_indirect_validation_test.cpp, a CMake test target, and updates d3d12_state_map_test.cpp.

Why merge

Brings the Vulkan-backed D3D12 shim's ExecuteIndirect behavior in line with live Windows WARP and NVIDIA hardware (0 disagreements across 49 cases), catching invalid calls at record time.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

GraphicsCommandList::ExecuteIndirect in runtime/shims/d3d12_com.cpp now checks argument/count buffer dimensions, 4-byte offset alignment, count-buffer bounds and overflow-safe max_command_count stride coverage. CommandList::execute_indirect rejects unaligned stride/argument/count offsets and a null count buffer with nonzero offset at recording time. Adds the 459-line d3d12_execute_indirect_validation_test.cpp, a CMake test target, and updates d3d12_state_map_test.cpp.

Why merge

Brings the Vulkan-backed D3D12 shim's ExecuteIndirect behavior in line with live Windows WARP and NVIDIA hardware (0 disagreements across 49 cases), catching invalid calls at record time.

Verdict: Approve

@rideinstead

Copy link
Copy Markdown

✅ Automated security review: CLEAN (commit 2294cfc7)

  • bounds math in UINT64, zero count guarded

Scope: static analysis of added diff lines only; no code was executed. Please review findings manually.

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.

7 participants