Skip to content

d3d12: defer DispatchMesh in bundles and fix closed-list early return - #7487

Closed
DenRakEiw wants to merge 1 commit into
ProjectLeonida:mainfrom
DenRakEiw:fix/d3d12-dispatch-mesh-bundle
Closed

DenRakEiw wants to merge 1 commit into
ProjectLeonida:mainfrom
DenRakEiw:fix/d3d12-dispatch-mesh-bundle

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Claim: #7231 (comment)

Summary

  • Defer ID3D12GraphicsCommandList6::DispatchMesh inside D3D12_COMMAND_LIST_TYPE_BUNDLE via defer([=](GraphicsCommandList& l) { l.record_dispatch_mesh(x, y, z); }, true), matching DrawInstanced, DrawIndexedInstanced, and Dispatch so mesh draws recorded in bundles inherit the executing direct list's render targets, viewport, scissor, and root state (and replay without duplicate trace lines).
  • Check list_.closed() before the empty-viewport early return in
    ecord_dispatch_mesh so calling DispatchMesh on an already-closed direct list consistently flags invalid_ regardless of whether a viewport was bound.
  • Strictly scoped to DispatchMesh in
    untime/shims/d3d12_com.cpp (no changes to COPY/COMPUTE queue-type checks or other draw/dispatch methods).

Empirical D3D12 Verification (Windows 11, RTX 5090 + WARP, ms_6_5/ps_6_5)

  • Bundle with initial mesh PSO + parent root signature/args: �undle->Close() == S_OK, parent->Close() == S_OK, renders expected pixels (255,0,0,255) on both NVIDIA GeForce RTX 5090 and WARP.
  • Bundle with SetPipelineState(mesh_pso) + parent root signature/args: �undle->Close() == S_OK, parent->Close() == S_OK, renders expected pixels (255,0,0,255) on both RTX 5090 and WARP.
  • Oversized grid (65536, 1, 1) in a bundle: �undle->Close() == S_OK on both RTX 5090 and WARP (deferred to parent execution, where the layer fails parent Close() with E_INVALIDARG).
  • Closed-list DispatchMesh (with and without viewport on DIRECT, and on a closed BUNDLE): second Close() returns E_FAIL on both RTX 5090 and WARP.

Tests (NVIDIA GeForce RTX 5090, LEONIDA_VK_VALIDATION=1)

  • d3d12_com: Passed (0 VUIDs)
  • d3d12_close_parity: Passed (0 VUIDs)
  • d3d12_bundle: Passed (0 VUIDs)
  • d3d12_bundle_forbidden: Passed (0 VUIDs)
  • d3d12_mesh: Passed without validation (all 4096 direct pixels + all 4096 bundle pixels matched across inherited PSO, initial PSO, and bundle-set PSO, plus oversized-grid bundle and closed-list checks); under LEONIDA_VK_VALIDATION=1 (Vulkan SDK 1.4.363.0), 0 VUIDs in all direct and bundle DispatchMesh sections (3 pre-existing VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 errors only in the untouched D3D-291 pipeline statistics query section).

AI-assisted (Gemini 4 Neon).

…ewport early return

Defer ID3D12GraphicsCommandList6::DispatchMesh in D3D12_COMMAND_LIST_TYPE_BUNDLE via defer(..., true) into a private record_dispatch_mesh helper, matching DrawInstanced/DrawIndexedInstanced/Dispatch so bundles can record mesh draws and replay them without duplicate trace lines.

Check list_.closed() before the empty-viewport early return in record_dispatch_mesh so calling DispatchMesh on an already-closed direct list consistently marks the list invalid regardless of whether a viewport was bound.

Add bundle DispatchMesh (inherited PSO/root signature, initial PSO, bundle-set PSO, oversized grid) and closed-list DispatchMesh coverage in d3d12_mesh_test.

AI-assisted (Gemini 4 Neon).
@ECHOZwei

Copy link
Copy Markdown

Tested bf96608869438c3d3ec6b9511eac41a045c13d7d on Windows (MSVC 14.51 / Visual Studio Community 2026, RelWithDebInfo, Vulkan SDK 1.4.363.0) on two GPUs (synthetic tests only; no game files): pass

  • Built d3d12_com_test, d3d12_close_parity_test, d3d12_bundle_test, d3d12_bundle_forbidden_test, and d3d12_mesh_test cleanly (0 new warnings).
  • NVIDIA GeForce RTX 4080 SUPER (driver 621.01):
    • ctest --test-dir runtime/build -C RelWithDebInfo -R ^(d3d12_com|d3d12_close_parity|d3d12_bundle|d3d12_bundle_forbidden)$ with LEONIDA_VK_VALIDATION=1: 4/4 passed (9.14s), 0 validation errors.
    • d3d12_mesh: passed (0.51s, mesh tier 1; all direct + bundle DispatchMesh 4096-pixel, oversized-grid, closed-list, and statistics checks passed).
  • AMD Radeon(TM) Graphics iGPU (driver 25.10, LEONIDA_VK_DEVICE=AMD):
    • Same 4 tests with LEONIDA_VK_VALIDATION=1: 4/4 passed (6.13s), 0 validation errors.
    • d3d12_mesh: cleanly skipped (exit 77; no VK_EXT_mesh_shader, refusal path verified).
  • git diff --check and python -I scripts/check_no_game_data.py runtime/shims/d3d12_com.cpp runtime/test/d3d12_mesh_test.cpp: clean (exit 0).
  • Code review: defer(..., true) and moving list_.closed() ahead of the empty-viewport early return in record_dispatch_mesh are clean and match the existing draw/dispatch deferral pattern.

AI-assisted.

@nnonno91

Copy link
Copy Markdown

Independent synthetic Windows verification of #7487 (bf96608) on current main 867d922 with #8200 (95597e4), #7256 (e83aa4e) and #7112 (9e9bb63). Those three PRs were common to both builds. Windows 11 build 26200, native x64 Release, MSVC 19.51, Vulkan Headers 1.4.363, Khronos validation 1.4.357 and LEONIDA_VK_VALIDATION=1. The Radeon gfx1036 (32.0.21042.62) and RTX 5090 (617.42) both ran the mesh section. AI-assisted.

Case Before #7487, both GPUs With #7487, both GPUs
Bundle whose mesh PSO and root state come from the DIRECT parent Bundle Close returns E_INVALIDARG, before any render Bundle Close returns S_OK. The image with inherited, initial, and bundle-set PSOs matches 4,096/4,096 pixels.
DispatchMesh after closing a DIRECT list with a viewport A second Close returns E_FAIL. Queue submission is refused. Same
DispatchMesh after closing a DIRECT list with no viewport A second Close returns E_FAIL. ExecuteCommandLists accepts the list. A second Close still returns E_FAIL. ExecuteCommandLists refuses it (ReplayResult::unsupported).

The local diagnostic runs the closed DIRECT cases first and checks the queue result to distinguish the two implementations. The separately built control has byte-identical fixture source and leaves d3d12_com.cpp at main. The patched build also passed the oversized-grid and closed BUNDLE checks, and matched all 4,096 pixels in the original direct draw.

The patched mesh diagnostic passed three times per GPU with zero Vulkan validation errors. All five focused CTests also passed three times per GPU: d3d12_mesh, d3d12_com, d3d12_close_parity, d3d12_bundle and d3d12_bundle_forbidden.

Raxstreams added a commit to Raxstreams/Leonida that referenced this pull request Nov 23, 2026
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.

4 participants