Skip to content

d3d12: enforce COPY and COMPUTE command-list recording restrictions - #5252

Open
DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/d3d12-queue-type-restrictions
Open

DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/d3d12-queue-type-restrictions

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Claim: #5156 (comment)

Summary

Enforces standard D3D12 command-list recording restrictions for D3D12_COMMAND_LIST_TYPE_COMPUTE and D3D12_COMMAND_LIST_TYPE_COPY lists in runtime/shims/d3d12_com.cpp, verified 1:1 against real Windows host D3D12 (RTX 5090, AMD Radeon iGPU, and WARP without the debug layer):

  • Graphics-only calls refused on COMPUTE and COPY lists (keeping BUNDLE rules intact):
    • DrawInstanced, DrawIndexedInstanced
    • ClearRenderTargetView, ClearDepthStencilView, ResolveSubresource
    • SetGraphicsRootSignature, SetGraphicsRootDescriptorTable, SetGraphicsRoot32BitConstant, SetGraphicsRoot32BitConstants, SetGraphicsRootConstantBufferView, SetGraphicsRootShaderResourceView, SetGraphicsRootUnorderedAccessView
    • IASetPrimitiveTopology, IASetVertexBuffers, IASetIndexBuffer
    • RSSetViewports, RSSetScissorRects
    • OMSetRenderTargets, OMSetBlendFactor, OMSetStencilRef, OMSetFrontAndBackStencilRef
  • Compute / pipeline / descriptor-heap / indirect / RT calls refused on COPY lists (and ExecuteIndirect with draw signatures refused on COMPUTE lists, matching all 3 host adapters):
    • Dispatch, ClearState, SetPipelineState, SetDescriptorHeaps
    • SetComputeRootSignature, SetComputeRootDescriptorTable, SetComputeRoot32BitConstant, SetComputeRoot32BitConstants, SetComputeRootConstantBufferView, SetComputeRootShaderResourceView, SetComputeRootUnorderedAccessView
    • ExecuteIndirect (refused on COPY; draw/draw-indexed command signatures refused on COMPUTE)
    • BuildRaytracingAccelerationStructure, EmitRaytracingAccelerationStructurePostbuildInfo, CopyRaytracingAccelerationStructure
  • Confirmed AtomicCopyBufferUINT / AtomicCopyBufferUINT64 are allowed on DIRECT, COMPUTE, and COPY on host D3D12 (only forbidden on BUNDLE), so they remain allowed.
  • Intentionally leaves DiscardResource and ClearUnorderedAccessView* untouched to stay disjoint from d3d12: fix DiscardResource list/3D-rect parity and compute-queue layout barrier #5068 and d3d12: support UAV rectangle clears on 3D volumes, non-attachment formats, and compute queues #5170.

New Test

  • runtime/test/d3d12_queue_type_restrictions_test.cpp (registered as d3d12_queue_type_restrictions in runtime/CMakeLists.txt with SKIP_RETURN_CODE 77 and FAIL_REGULAR_EXPRESSION "Validation Error;VUID-"):
    • Compares Close() pass/fail verdict for all 38 calls across DIRECT, COMPUTE, and COPY lists (114 checks) against Windows host hardware adapter + WARP (skipped under Wine), asserting 0 disagreements.
    • Runs positive end-to-end GPU execution + readback controls on COPY and COMPUTE queues under LEONIDA_VK_VALIDATION=1.

Verification (Windows 11, LEONIDA_VK_VALIDATION=1)

  • NVIDIA GeForce RTX 5090 (default adapter + WARP):
    • d3d12_com — Passed (0.28s, 0 validation errors)
    • d3d12_vulkan_device — Passed (12.49s, 0 validation errors)
    • d3d12_bundle_forbidden — Passed (2.27s, 10/10 host-compared, 0 failures, 0 validation errors)
    • d3d12_queue_type_restrictions — Passed (0.65s, 38 calls / 114 checks, 114 host-compared, 0 host-disagreed, 0 failures, 0 validation errors; COPY + COMPUTE positive controls verified)
  • AMD Radeon(TM) Graphics iGPU (LEONIDA_VK_DEVICE=AMD, default adapter + WARP):
    • d3d12_com — Passed (0.23s, 0 validation errors)
    • d3d12_bundle_forbidden — Passed (2.14s, 10/10 host-compared, 0 failures, 0 validation errors)
    • d3d12_queue_type_restrictions — Passed (0.55s, 38 calls / 107 non-PSO checks on 128B push-constant iGPU, 107 host-compared, 0 host-disagreed, 0 failures, 0 validation errors; COPY positive control verified)

AI-assisted (Gemini 4 Neon).

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested d7bfc0a on Windows 11 with NVIDIA GeForce RTX 4090 (32.0.16.2101) and AMD Radeon Graphics (32.0.21043.5001): pass. AI-assisted.

I selected each Vulkan driver separately with VK_DRIVER_FILES and set LEONIDA_VK_VALIDATION=1. I ran this command on each adapter:

ctest --test-dir E:/Leonida-review-work-build -C RelWithDebInfo -V -R "^(d3d12_queue_type_restrictions|d3d12_com|d3d12_bundle_forbidden|d3d12_vulkan_device)$"

All four tests passed on each adapter. The new test compared 38 calls across three command-list types. All 114 checks matched the host references on each run. The test reported zero Vulkan validation errors.

I also built the new test against merge base 3faac55. On the RTX 4090 it reported 70 failed assertions and exited with code 1. For example, the layer accepted CopyRTAS on a COPY list. The host rejected it.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested d7bfc0a on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_queue_type_restrictions_test exits 0 with "queue-type restrictions: 38 calls (114 checks) on layer, 114 host-compared, 0 host-disagreed, 0 failures, 0 validation errors". d3d12_bundle_forbidden_test exits 0 with "bundle forbidden calls: 10 on the layer, 10 compared with the host, 0 hosts disagree, 0 failures", and d3d12_com_test exits 0. No validation layer was loaded in this run, so the "0 validation errors" figure is the test's own count.

AI-assisted.

@Kam471 Kam471 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.

Reviewed d7bfc0a (base 3faac55). git diff --check clean (3 files, +812/−11).

Built and ran in a fresh worktree:

cmake -S runtime -B runtime/build-5252 -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DVulkan_INCLUDE_DIR=C:/VulkanSDK/1.4.363.0/Include -DVulkan_LIBRARY=C:/VulkanSDK/1.4.363.0/Lib/vulkan-1.lib
cmake --build runtime/build-5252 --target d3d12_queue_type_restrictions_test d3d12_com_test d3d12_bundle_forbidden_test
LEONIDA_VK_DEVICE='RTX 5070 Ti' LEONIDA_VK_VALIDATION=1 runtime/build-5252/d3d12_queue_type_restrictions_test.exe

d3d12_queue_type_restrictions: PASS — 38 calls / 114 checks, 114 host-compared, 0 host-disagreed, 0 failures, 0 validation errors; COPY and COMPUTE positive controls executed with correct readback. Every row matched host D3D12 (RTX 5070 Ti and WARP), including ResolveSubresource, ClearState, SetDescriptorHeaps and SetPipelineState refused on COPY, ExecuteIndirect(draw) refused on COMPUTE, and AtomicCopyBufferUINT allowed on all three types.
d3d12_com_test: PASS (16 colour/depth/stencil texels matched). d3d12_bundle_forbidden: PASS (10/10 host-compared, 0 failures).

Verdict: no blockers; the gates match measured host behaviour on this machine.
Minor test note: the host arm needs d3dcompiler_47.dll; if it is missing the run reports 0 host-compared and silently checks the layer against the hard-coded expectations only.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 35e9089 on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_com_test exits 0, d3d12_bundle_forbidden_test exits 0 with "bundle forbidden calls: 10 on the layer, 10 compared with the host, 0 hosts disagree, 0 failures", and d3d12_queue_type_restrictions_test exits 0 with "queue-type restrictions: 38 calls (114 checks) on layer, 114 host-compared, 0 host-disagreed, 0 failures, 0 validation errors". No validation layer was loaded in this run.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 35e9089 merged with main 561b65a (merge was a no-op) on Windows 11 native (MSVC 14.51 via VS 18, CMake + Ninja, RelWithDebInfo; device NVIDIA GeForce RTX 4080 SUPER, driver for the default adapter, plus WARP): pass

Built and ran the PR's own target d3d12_queue_type_restrictions_test (not the full ctest). Result line: 38 calls (114 checks) on layer, 114 host-compared, 0 host-disagreed, 0 failures, 0 validation errors. The table compares the layer with host D3D12 on the default adapter and on WARP for DIRECT, COMPUTE and COPY lists; the layer matches the host in all 114 checks, including the positive COPY and COMPUTE controls (AtomicCopyBufferUINT, ExecuteIndirect(dispatch), Dispatch).

Negative control: with runtime/shims/d3d12_com.cpp checked out from main and rebuilt, the same test prints 114 host-compared, 0 host-disagreed, 70 failures (for example RSSetScissorRects (COPY): layer OK != expected FAIL, SetPipelineState (COPY), ExecuteIndirect(draw) (COMPUTE)); the PR's file was then restored.

Not run: the other d3d12_* tests and ctest as a whole, so I did not check that nothing else in the repo records these calls on a COMPUTE or COPY list. Worktree and ref removed afterwards.

@DenRakEiw

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto latest main (e0816d6af -> d9c3d7cb4), resolving merge conflicts in runtime/CMakeLists.txt and runtime/shims/d3d12_com.cpp while preserving both main's DXR/ExecuteIndirect validation (#6825, #6830) and this PR's COPY/COMPUTE command-list recording restrictions.

Re-verified on NVIDIA GeForce RTX 5090 with LEONIDA_VK_VALIDATION=1 (0 VUIDs / 0 validation errors):

  • d3d12_queue_type_restrictions: Passed (38 calls / 114 checks, 114 host-compared, 0 host-disagreed, 0 failures)
  • d3d12_dxr_validation: Passed (WARP + RTX 5090 HW + Leonida Vulkan)
  • d3d12_execute_indirect_validation: Passed (49 parity cases, WARP + RTX 5090 HW, positive GPU dispatch OK)
  • d3d12_close_parity: Passed
  • d3d12_com: Passed

AI-assisted (Gemini 4 Neon).

@EduAzevedo

Copy link
Copy Markdown

Tested d9c3d7c (current head, after the rebase onto e0816d6) on NVIDIA GeForce RTX 2070 SUPER (Turing), driver 610.88, Vulkan 1.4.341, Windows 11 (10.0.26200): pass

Built with MSVC 14.51 (VS 2026), Visual Studio generator, RelWithDebInfo, Vulkan SDK 1.4.363.0. Ran ctest -C RelWithDebInfo on the five tests from the rebase comment, with LEONIDA_VK_DEVICE=nvidia:

Test LEONIDA_VK_VALIDATION=0 LEONIDA_VK_VALIDATION=1
d3d12_queue_type_restrictions PASS PASS
d3d12_dxr_validation PASS PASS
d3d12_execute_indirect_validation PASS PASS
d3d12_close_parity PASS PASS
d3d12_com PASS PASS
  • d3d12_queue_type_restrictions: 38 calls (114 checks) on layer, 114 host-compared, 0 host-disagreed, 0 failures, 0 validation errors
  • d3d12_execute_indirect_validation: 49 parity cases (WARP=live, HW=NVIDIA GeForce RTX 2070 SUPER), positive GPU dispatch ok, 0 validation errors, 0 failures

Negative control: with runtime/shims/d3d12_com.cpp taken from the merge base e0816d6 and the test rebuilt, d3d12_queue_type_restrictions_test exits 1 with 114 host-compared, 0 host-disagreed, 70 failures (e.g. ClearRenderTargetView (COMPUTE): layer OK != expected FAIL). The PR's file was restored afterwards.

Not run: the full ctest suite.

AI-assisted.

@DenRakEiw

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto origin/main (dde82f2) -> 5ea6f5f, preserving the newly merged #6610/#6644/#6674 changes in
untime/shims/d3d12_com.cpp alongside the COPY/COMPUTE command-list recording restrictions.

Re-verified on NVIDIA GeForce RTX 5090 with LEONIDA_VK_VALIDATION=1 (0 VUIDs / 0 validation errors):

  • d3d12_queue_type_restrictions: 38 calls (114 checks) on layer, 114 host-compared, 0 host-disagreed, 0 failures, 0 validation errors
  • d3d12_close_parity: 113 cases, 78 match WARP, 20 known layer-stricter, 15 known layer-looser, 0 failures
  • d3d12_com: PASS (16 colour, depth and stencil texels matched; queue wait held the GPU)

AI-assisted (Gemini 4 Neon).

@AirKyzzZ

AirKyzzZ commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 5ea6f5f91 on RTX 2060 (NVIDIA 566.14), Windows 10 22H2 (19045), clang-cl 23.1.6 + lld-link (MSVC 14.44 STL), SDK 10.0.26100: fail, on the host comparison only

Built d3d12_queue_type_restrictions_test at the head as is, ctest -R "^d3d12_queue_type_restrictions$" fails: queue-type restrictions: 38 calls (114 checks) on layer, 114 host-compared, 0 host-disagreed, 55 failures, 0 validation errors. Every failure is layer OK, host FAIL (for example FAIL DrawInstanced (DIRECT): layer OK, host FAIL), and both host adapters show FAIL in every column, including the cases expected OK. There is no layer ... != expected line, and a run with LEONIDA_VK_VALIDATION=1 (Khronos layer, validation on) shows the same layer OK, host FAIL lines and no VUID- line.

The likely cause: record_and_close creates an ID3D12GraphicsCommandList8 and returns E_UNEXPECTED when that fails, and Windows 10's in-box d3d12.dll has no ID3D12GraphicsCommandList7 or 8 (d3d12_vulkan_device_test here prints the host runtime has no ID3D12GraphicsCommandList7). So the host verdicts are all FAIL and are still compared. Skipping the host when that interface is missing would fix it. Without the fix: with runtime/shims/d3d12_com.cpp reverted to dde82f27e, the layer-side failures appear too (FAIL ClearRenderTargetView (COMPUTE): layer OK != expected FAIL, and the same for COPY, ClearDepthStencilView, ResolveSubresource and SetGraphicsRootSignature), so the layer checks do cover the change. No game files. AI-assisted (Claude Code).

@DenRakEiw
DenRakEiw force-pushed the fix/d3d12-queue-type-restrictions branch from 5ea6f5f to 803e147 Compare November 23, 2026 18:41
@DenRakEiw

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto origin/main (6dda0630b, commit 803e14730), preserving both #6815's ClearState predication reset and this PR's COPY/COMPUTE command-list recording restrictions.

Re-verified on NVIDIA GeForce RTX 5090 with LEONIDA_VK_VALIDATION=1 (0 Vulkan validation errors):

  • d3d12_queue_type_restrictions: PASS (38 calls / 114 checks, 114 host-compared, 0 host-disagreed, 0 VUIDs)
  • d3d12_predication_atomic_copy: PASS (59 cases, 0 failures, 0 VUIDs)
  • d3d12_com: PASS (0 VUIDs)

AI-assisted (Gemini 4 Neon).

@DaviDreamerz

Copy link
Copy Markdown

Tested 803e14730 on Windows 11 (build 26300), MSVC 14.44 RelWithDebInfo, GeForce RTX 4070 Ti SUPER, NVIDIA 621.24: pass.

  • d3d12_queue_type_restrictions: 38 calls (114 checks) on the layer, 114 host-compared, 0 host-disagreed, 0 failures, 0 validation errors
  • Negative control: with only runtime/shims/d3d12_com.cpp from 867d922f0 in the same tree, the same test gives 68 failures, for example CopyRTAS (COPY): layer OK != expected FAIL and CopyRTAS (COPY): layer OK, host FAIL, so the new refusals are what this test measures
  • No game files (LEONIDA_GAME_DIR unset); synthetic only

AI-assisted: yes.

@optinium51-bot

Copy link
Copy Markdown

Tested 803e14730 merged onto main 867d922f0 (clean merge) on NVIDIA GeForce RTX 3060 (driver 616.92), Windows 11 26200, MSVC 14.52 (VS 2026), RelWithDebInfo + Ninja: no regression; the new test was not built.

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

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.

9 participants