Skip to content

Runtime: guard closed-list IA/OM/PSO state setters and expand D3D12 Close parity tests - #6644

Merged
shayderrr merged 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/d3d12-ia-state-close-parity
Nov 23, 2026
Merged

shayderrr merged 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/d3d12-ia-state-close-parity

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Claim: #6414 (comment)

Summary

100% generic D3D12->Vulkan command-list state-setter closed-list guards and live-WARP Close() parity coverage (deliberately excluding IASetVertexBuffers, queue-type checks, RSSetViewports/RSSetScissorRects, and OMSetRenderTargets/SetDescriptorHeaps).

Changes

  • runtime/shims/d3d12_com.cpp: Added if (list_.closed()) return; guards to ExecuteBundle, SetPipelineState, ClearState, IASetPrimitiveTopology, IASetIndexBuffer, OMSetBlendFactor, and OMSetStencilRef:
    • Prevents post-Close() calls on a direct list from silently mutating recorded state (front_stencil_ref_, back_stencil_ref_, blend_factor_, topology_, index_, compute_pipeline_, graphics_pipeline_, held_).
    • Fixes SetPipelineState on a closed bundle previously still calling hold(state) after defer() returned true.
    • Leaves already-closed bundles valid when state calls are made after Close(), matching empirical Windows 11 WARP and RTX 5090 D3D12 behavior where ExecuteBundle on such a bundle still closes with S_OK.
  • Empirical D3D12 host verification (Windows 11 WARP & RTX 5090, no debug layer):
    • IASetIndexBuffer accepts nullptr, R16_UINT, R32_UINT, UNKNOWN (size 0 and 64), R8_UINT, R32_FLOAT, and format 999 at Close() (S_OK) on both direct lists and bundles; invalid formats are already rejected at indexed-draw replay in vulkan_replay.h.
    • IASetPrimitiveTopology accepts UNDEFINED, TRIANGLELIST, gap values (7, 8, 9), 32_CONTROL_POINT_PATCHLIST (64), 65, and 99 at Close() (S_OK) on both direct lists and bundles.
    • SetPipelineState(nullptr) crashes (access violation) on Windows D3D12 without debug layer and is explicitly expected to close with S_OK by d3d12_gcl8_test, so it is kept compatible and omitted from live-WARP cases.
  • runtime/test/d3d12_close_parity_test.cpp: Added 13 live-WARP Close() parity cases covering IASetIndexBuffer (nullptr, R16_UINT, R32_UINT, UNKNOWN size 0/64, R32_FLOAT), IASetPrimitiveTopology (TRIANGLELIST, gap 7, 32_CONTROL_POINT_PATCHLIST, 65), OMSetBlendFactor, OMSetStencilRef(7), and ExecuteBundle after post-close state calls on a closed bundle.
  • runtime/test/d3d12_com_test.cpp: Added closed-list immutability assertions for direct lists and bundles verifying post-close state setters do not mutate recorded state or invalidate an already-closed bundle.

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

All 7 targets built in RelWithDebInfo (Ninja) and passed with 0 failures and 0 Vulkan validation errors:

  • d3d12_close_parity_test: 113 cases, 78 match WARP, 20 known layer-stricter, 15 known layer-looser, 0 not run, 0 where WARP differs from the measured column, 0 failures
  • d3d12_draw_test: passed (0 validation errors)
  • d3d12_bundle_test: 14 scenarios on the layer, 25 host comparisons, 0 failures
  • d3d12_bundle_forbidden_test: 10 on the layer, 10 compared with the host, 0 hosts disagree, 0 failures
  • d3d12_com_test: passed (16 colour, depth and stencil texels matched; queue wait held the GPU)
  • d3d12_gcl8_test: passed (QueryInterface, OMSetFrontAndBackStencilRef(1, 2), refcount balanced)
  • d3d12_vulkan_device_test: passed (all checks matched against host RTX 5090)
  • git diff --check: clean

AI-assisted (Gemini 4 Neon).

@0xTehuti 0xTehuti left a comment

Copy link
Copy Markdown
Contributor

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 Pro x64 (Build 26100)
  • GPU: NVIDIA GeForce RTX 2070 SUPER (8192 MB VRAM, Driver 595.79, Vulkan 1.4)
  • Toolchain: MSVC 2022 Community (vcvars64, cl.exe 19.44.35225.0), Ninja 1.13, CMake 4.4, Windows SDK 10.0.26100.0
  • Validation: LEONIDA_VK_VALIDATION=1 (VK_LAYER_KHRONOS_validation active)

Verification Summary

All 7 test targets configured, built cleanly with MSVC 2022 and Ninja, and executed natively on the RTX 2070 SUPER under full Vulkan validation (LEONIDA_VK_VALIDATION=1):

  1. d3d12_close_parity_test.exe:

    • 113 cases, 78 match WARP, 20 known layer-stricter, 15 known layer-looser, 0 not run, 0 where WARP differs from the measured column, 0 failures
    • All 13 newly added live-WARP parity cases passed matching expected behaviors:
      • IASetIndexBuffer with nullptr, R16_UINT, R32_UINT, UNKNOWN (size 0 & 64), and R32_FLOAT.
      • IASetPrimitiveTopology with TRIANGLELIST, gap value 7, 32_CONTROL_POINT_PATCHLIST, and 65.
      • OMSetBlendFactor and OMSetStencilRef(7).
      • ExecuteBundle after post-close state calls on bundle (closed bundle remains executable with S_OK).
  2. d3d12_com_test.exe:

    • Closed-list immutability assertions passed on direct command list and bundles.
    • Calling state setters post-Close() does not mutate recorded state or invalidate an already-closed bundle.
    • COM list/queue/fence: 16 colour, depth and stencil texels matched; queue wait held the GPU.
  3. CTest Suite (ctest -R "^d3d12_(close_parity|com|draw|bundle|bundle_forbidden|gcl8|vulkan_device)$" under Vulkan validation):

    • d3d12_com: Passed (0 VUID errors)
    • d3d12_gcl8: Passed (0 VUID errors)
    • d3d12_vulkan_device: Passed (0 VUID errors)
    • d3d12_close_parity: Passed (0 VUID errors)
    • d3d12_draw: Passed (0 VUID errors)
    • d3d12_bundle: Passed (14 scenarios on the layer, 25 host comparisons, 0 failures, 0 VUID errors)
    • d3d12_bundle_forbidden: Passed (10 on the layer, 10 compared with host, 0 failures, 0 VUID errors)
  4. Repo Hygiene & Standards:

    • git diff --check: clean (no whitespace or formatting defects).
    • python -m unittest discover -s tests -p "test_ctest_registration.py": 4 tests passed.
    • Clean-room compliant: zero game data, archives, or proprietary files used or referenced.

Code Review & Audit

  • runtime/shims/d3d12_com.cpp:
    • The if (list_.closed()) return; early exits in ExecuteBundle, SetPipelineState, ClearState, IASetPrimitiveTopology, IASetIndexBuffer, OMSetBlendFactor, and OMSetStencilRef correctly prevent mutation of internal state (front_stencil_ref_, back_stencil_ref_, blend_factor_, topology_, index_, etc.) after Close().
    • Fixes bundle state deferred registration (calls_) and prevents SetPipelineState from leaking holds on closed bundles.
    • Correctly preserves closed bundle validity for subsequent ExecuteBundle calls, matching empirical D3D12 WARP / native driver behavior.
  • runtime/test/d3d12_close_parity_test.cpp & runtime/test/d3d12_com_test.cpp:
    • Comprehensive, reproducible regression tests verifying both native direct list and bundle behavior against WARP.

LGTM! Verified and ready to merge.


AI-assisted review (Gemini 3.8 Flash High) executed on native hardware.

@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

Verification Summary

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

  1. **\d3d12_close_parity_test.exe**:

    • \close parity: 113 cases, 78 match WARP, 20 known layer-stricter, 15 known layer-looser, 0 not run, 0 where WARP differs from the measured column, 0 failures\
    • Verified newly added closed-list parity tests for \IASetIndexBuffer\ (null, R16_UINT, R32_UINT, UNKNOWN, R32_FLOAT), \IASetPrimitiveTopology\ (TRIANGLELIST, gap 7, 32_CONTROL_POINT_PATCHLIST, 65), \OMSetBlendFactor, \OMSetStencilRef, and \ExecuteBundle after post-close state calls on bundle.
  2. **\d3d12_com_test.exe**:

    • Passed with 16 color, depth and stencil texels matched; queue wait held the GPU.
    • Verified that calling state setters on closed direct command lists and bundles (\OMSetStencilRef, \OMSetBlendFactor, \IASetPrimitiveTopology, \IASetIndexBuffer, \SetPipelineState, \ClearState) are ignored and do not mutate internal state or invalidate bundles.
  3. CTest:

    • \d3d12_com: Passed (0.20s)
    • \d3d12_close_parity: Passed (0.17s)

Clean-room compliant; zero game data or proprietary files used or referenced. LGTM!

@BeegSchmooze

Copy link
Copy Markdown
Contributor

Tested 898b6a5c on NVIDIA GeForce RTX 4080, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 19.51 (VS 18), RelWithDebInfo: pass.

  • d3d12_close_parity_test: 113 cases, 78 match WARP, 20 known layer-stricter, 15 known layer-looser, 0 not run, 0 where WARP differs from the measured column, 0 failures.
  • d3d12_com_test: exit 0.

AI-assisted (Claude Code). No game files.

@nullmarsh

Copy link
Copy Markdown

Tested 898b6a5c on RX 9060 XT (RDNA4, AMD 26.11.2), Windows 11: pass.

  • d3d12_close_parity: 113 cases, 78 match WARP, 0 failures. d3d12_com and d3d12_bundle pass.
  • With the reference device on the RX 9060 XT's native D3D12 instead of WARP (a local change, a fresh device per case), every new IA/OM case gets WARP's verdict, IASetIndexBuffer as R32_FLOAT and the gap topologies included. The only exceptions are the three root-argument-before-root-signature rows, which remove the AMD device (see d3d12: match Close() parity for unbound draws, dispatches, and root arguments #6068).

AI-assisted (Claude Code), no game files.

@wasonidas

Copy link
Copy Markdown

Independent dual-adapter check of 898b6a5cee1530a00438083716f794b63343f81a. Windows 11 build 26300.9974, MSVC 19.44.35230, Khronos validation 1.4.363, RelWithDebInfo. Integrated Radeon (32.0.21042.62) and RTX 5080 (621.24) each passed 7/7 focused CTests with zero Vulkan validation errors.

Each run checked 113 cases against live WARP. All 13 new cases returned S_OK on both sides. Totals were 78 matches, 20 known layer-stricter cases and 15 known layer-looser cases, with zero skips or deviations from the recorded WARP expectations. COM readback, the draw and the bundle comparisons also passed on both adapters.

For coordination with #6610, a known layer-stricter Close() result can cause that PR's proposed whole-batch guard to reject otherwise valid work in the same batch. The Close() parity test does not measure replay outcomes for the layer-looser cases. Existing synthetic fixtures 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

runtime/shims/d3d12_com.cpp adds if (list_.closed()) return; to ExecuteBundle, SetPipelineState, ClearState, IASetPrimitiveTopology, IASetIndexBuffer, OMSetBlendFactor and OMSetStencilRef, matching D3D12's no-op semantics after Close. d3d12_close_parity_test.cpp adds a closed bundle and many setter cases; d3d12_com_test.cpp checks closed-list calls neither mutate recorded state nor invalidate a bundle.

Why merge

Brings the shim into line with the real API, preventing spurious state changes and parity failures on post-close calls.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

runtime/shims/d3d12_com.cpp adds if (list_.closed()) return; to ExecuteBundle, SetPipelineState, ClearState, IASetPrimitiveTopology, IASetIndexBuffer, OMSetBlendFactor and OMSetStencilRef, matching D3D12's no-op semantics after Close. d3d12_close_parity_test.cpp adds a closed bundle and many setter cases; d3d12_com_test.cpp checks closed-list calls neither mutate recorded state nor invalidate a bundle.

Why merge

Brings the shim into line with the real API, preventing spurious state changes and parity failures on post-close calls.

Verdict: Approve

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