Skip to content

test(d3d12): cover DispatchMesh bundle replay (D3D-BUNDLE-DISPATCH-MESH) - #841

Closed
Maticcm wants to merge 3 commits into
ProjectLeonida:mainfrom
Maticcm:feat/d3d12-bundle-dispatch-mesh
Closed

Maticcm wants to merge 3 commits into
ProjectLeonida:mainfrom
Maticcm:feat/d3d12-bundle-dispatch-mesh

Conversation

@Maticcm

@Maticcm Maticcm commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Claim: D3D-BUNDLE-DISPATCH-MESH

Main picked up the DispatchMesh bundle implementation in 85f806b. This revision adds direct regression coverage and documents the behavior.

The synthetic mesh fixture executes the same bundle twice with different inherited root arguments. It resets the parent to a vertex PSO before a state-only bundle, then checks a direct mesh dispatch that depends on the bundle handing its PSO and root arguments back. It also checks that Close rejects an oversized grid, missing inherited root state and replay of an invalidated bundle.

Tested e6585b5 on Windows 11 with RTX 3080, NVIDIA driver 630.20. All 10 focused mesh, bundle, indirect-bundle, close-parity and root-layout CTests passed in each of two runs, with and without Vulkan validation. Both mesh variants matched all 4,096 expected pixels in both runs. Changed-file game-data and whitespace checks passed. Synthetic fixtures only.

AI-assisted with OpenAI Codex (GPT-6.2 Sol), with a separate reviewer.

Copilot AI balanced review requested due to automatic review settings November 24, 2026 14:26

@abnalstlll-byte abnalstlll-byte 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.

Audited and verified. Implements deferred DispatchMesh recording for D3D12 bundle command lists, validating dispatch grid dimensions (<= 65535) at record time and replaying calls onto the parent command list during ExecuteBundle. Includes comprehensive test additions in
untime/tests/d3d12_mesh_shader_test.cpp covering state inheritance, constant buffer offset updates across bundle executions, and negative error conditions. Approved.

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Defers ID3D12GraphicsCommandList6::DispatchMesh through the bundle replay path so bundles correctly inherit parent state at ExecuteBundle, and adds regression tests + documentation for the behavior.

Changes:

  • Route DispatchMesh recording through defer() and add record_dispatch_mesh() to replay with inherited parent state.
  • Add GPU + negative bundle coverage for deferred DispatchMesh behavior.
  • Document that DispatchMesh is deferred like draws/dispatches for bundle replay.
File Description
runtime/​shims/​d3d12_com.cpp Defers DispatchMesh via defer() and adds record_dispatch_mesh() for replay-time state snapshotting.
runtime/​test/​d3d12_mesh_test.cpp Adds bundle execution + negative tests validating deferred DispatchMesh semantics and error cases.
docs/​d3d12_vulkan.md Updates bundle behavior documentation to include deferred DispatchMesh.

Review effort: Lite

Comment on lines +560 to +568
const UINT64 bundle_fence = d.pipeline_statistics_query ? 4 : 3;
EXPECT(SUCCEEDED(queue->Signal(fence.p, bundle_fence)) &&
SUCCEEDED(fence->SetEventOnCompletion(bundle_fence, nullptr)));

std::array<std::uint8_t, size * 256> bundle_pixels{};
void* bundle_mapped = nullptr;
EXPECT(SUCCEEDED(readback->Map(0, nullptr, &bundle_mapped)));
std::memcpy(bundle_pixels.data(), bundle_mapped, bundle_pixels.size());
readback->Unmap(0, nullptr);
Comment thread runtime/shims/d3d12_com.cpp Outdated
Comment on lines +1420 to +1424
void record_dispatch_mesh(UINT x, UINT y, UINT z) {
if (!graphics_pipeline_ || !graphics_.layout) return check(false);
note_direct_heap_indexing(graphics_.layout);
if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; // as record_draw: nothing is rasterized
leonida::Draw draw{graphics_pipeline_, graphics_.data, draw_views(), depth_, {}, 0, viewport_,
scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0};
draw.mesh = true;
check(list_.draw(std::move(draw)));
if (defer([=](GraphicsCommandList& l) { l.record_dispatch_mesh(x, y, z); }, true)) return;
@Maticcm

Maticcm commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Addressed @copilot review comments (rebased onto current main):
1.
untime/shims/d3d12_com.cpp (DispatchMesh): replaced implicit [=] lambda capture with explicit [x, y, z].
2.
untime/shims/d3d12_com.cpp (
ecord_dispatch_mesh): confirmed
ecord_draw (L1408-1418) uses the exact same ordering (
ote_direct_heap_indexing before the empty-viewport early-return), so both paths behave identically.
3.
untime/test/d3d12_mesh_test.cpp: replaced the
ullptr event in the bundle fence wait with an explicit CreateEventW / WaitForSingleObject / CloseHandle wait before mapping
eadback.

Rebuilt d3d12_mesh_test and verified on NVIDIA GeForce RTX 3080 (LEONIDA_VK_VALIDATION=1, 0 validation errors). AI-assisted.

@Sangonapou

Copy link
Copy Markdown
Contributor

Tested a74ab14 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32, mesh shaders), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: pass

Built at this head with scripts\build_runtime.ps1 (MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0); llvm-mc 23.1.6, SPIRV-Tools 2026.4. No game files.

ctest -R ^d3d12_mesh$ -V: passed, D3D-29: mesh tier 1; ... DispatchMesh over X, Y and Z, deferred bundle DispatchMesh and a stream VS draw matched all 4096 pixels on the native mesh stage.

One observation, not a failure: the statistics line here reads statistics, mixed: IA 6/2 VS 6 C 12/2 PS 3328 CS 0; mesh only: C 8/0 PS 1024; vertex only: C 2 PS 2048, while on this card the same test printed C 12/12 and mesh only: C 8/8 on the heads of #424 and #815 (older bases). I have not checked whether the second clipper count changed on main or in this branch; mentioning it in case it is the bundle path.

@Timon360SB

Copy link
Copy Markdown
Contributor

Independent testing results

Verified deferred DispatchMesh execution in bundles on NVIDIA Blackwell hardware under native Windows, with Vulkan validation enabled.

Tested revisions

  • BASE: a28927849adb4e40dfdec8c32fb6758dcd205a37
  • HEAD: a74ab14076c803ecf7e9c34f6d2e1158e6d2d194

Test environment

Component Configuration
CPU AMD Ryzen 7 7800X3D
GPU NVIDIA GeForce RTX 5070 (Blackwell)
VRAM 12227 MiB
RAM 31.11 GiB
GPU driver 621.14
OS Windows 11 Pro, build 26200
Vulkan SDK 1.4.363.0
MSVC 19.44.35230
Windows SDK 10.0.26100.0

Test configuration

  • Build configuration: RelWithDebInfo.
  • Build generator: Ninja Multi-Config.
  • Build scope: selected targets.
  • Vulkan core, GPU-assisted and synchronization validation enabled.
  • Three repetitions per revision.
  • Synthetic fixtures only.

Both revisions compiled successfully.

CTest results

Test BASE HEAD
d3d12_mesh 3/3 3/3
d3d12_bundle 3/3 3/3
d3d12_bundle_forbidden 3/3 3/3
d3d12_close_parity 3/3 3/3
vk_sync_validation 3/3 3/3
Total 15/15 15/15

Combined: 30/30 PASS, with no failed or skipped CTest executions.

Deferred DispatchMesh

The mesh test reported mesh shader tier 1 support on the RTX 5070.

All three HEAD executions explicitly confirmed successful deferred bundle DispatchMesh behavior.

The relevant HEAD diagnostic was:

DispatchMesh over X, Y and Z, deferred bundle DispatchMesh and a stream VS draw matched all 4096 pixels
Verification HEAD result
DispatchMesh over X, Y and Z PASS
Deferred bundle DispatchMesh PASS
Pipeline stream VS draw PASS
Pixel comparison 4096/4096 matched
Oversized dispatch grids Rejected at Close
Invalid bundle replays Rejected at Close
Wrong-kind draws Rejected at execution
Mesh statistics queries Resolved successfully

The pipeline state stream checks also consistently reported nine invalid cases and two not-implemented cases being rejected.

Bundle regression coverage

The forbidden bundle calls test reported the same results on BASE and HEAD:

  • 10 calls checked on the layer.
  • 10 compared with the host.
  • 0 host disagreements.
  • 0 failures.

The close-parity test also remained unchanged:

Property BASE HEAD
Cases 113 113
Match WARP 82 82
Known layer-stricter cases 16 16
Known layer-looser cases 15 15
Not run 0 0
Failures 0 0

Vulkan validation

The synchronization self-test produced the expected intentional WRITE_AFTER_WRITE hazard without a barrier and zero validation errors with a barrier.

Limitations

  • Tested on one NVIDIA Blackwell GPU.
  • No second hardware configuration was available for this run.
  • Testing was limited to the five selected CTest tests and synthetic fixtures.
  • No real-title execution was performed.

Conclusion

Result: PASS — no regressions detected within the tested scope.

The new deferred bundle DispatchMesh scenario successfully matched all 4096 pixels in every HEAD repetition. Invalid bundle replays were rejected as expected, and the existing bundle and close-parity regression tests remained successful.

AI-assisted log analysis and report preparation.

@MoonEyes

Copy link
Copy Markdown
Collaborator

Hi @Maticcm, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/shims/d3d12_com.cpp), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

@Maticcm

Maticcm commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto da4fd4ea0bb687be9ffda5db7d2bebbe4e461a39 and retested candidate c89e101688df10b6111e4ab2516398505c3b2ec6. The conflict resolution preserves the current mesh root-window checks, mesh stubs, viewport arrays, depth bounds and pipeline requests. It moves state-dependent recording to bundle replay while keeping the trace and dispatch-grid validation at record time.

  • Full C++ runtime builds completed on both revisions. The candidate fixture on baseline production code failed at bundle Close(). On the candidate, the new bundle draw matched all 4,096 pixels.
  • Focused CTest on both revisions: 8 passed with one validation-only skip in default mode, and 9 passed with Vulkan validation enabled. The clipping statistics were unchanged across the two revisions on this GPU, including mixed 12/2 and mesh-only 8/0.
  • Full Windows CTest on each revision: 515 listed, 500 passed, 2 failed, 11 skipped, 2 disabled. The same depth-resolve fence-completion and PresentX resize failures occurred on baseline and candidate. The disabled tests require SDL3, and package-dependent tests used their normal skips.
  • The ms_ subset of run_gpu_tests.py matched on both revisions: 5 passed and 3 skipped in default subgroup mode, 8 passed with wave64 emulation. Source smoke, CTest registration, diff and game-data checks passed. Synthetic fixtures only.

GPUs tested: Profile M, NVIDIA GeForce RTX 3080 desktop (10 GiB), driver 630.20, Windows 11 build 26340, MSVC 19.50.35717, Vulkan SDK 1.4.363.1. AI-assisted (Codex).

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 28, 2026
@Maticcm

Maticcm commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

I compared the failing CI logs on c89e10168 against upstream runs.

  • The exact rebase base da4fd4ea0 has the same Python test failures: both f16-to-int16 modifier assertions, the macOS case/accents path test, and the Linux fallback stack-reserve assertion. Base CI · PR CI
  • The nearby main run at 5cb45921e has the same Linux pipeline_workers assertions and the same MoltenVK failures, including vk_bindless_dimensions and the three GPU fixture mismatches. Main Runtime · PR Runtime

Windows CI was still running when I checked. AI-assisted (Codex).

@Maticcm

Maticcm commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

The Windows Runtime job finished successfully on c89e10168. GitHub currently reports the rebased branch as mergeable. The upstream failure comparison covers the remaining red jobs. The rebased change is ready for another maintainer look.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
@Maticcm
Maticcm force-pushed the feat/d3d12-bundle-dispatch-mesh branch from c89e101 to 19b5988 Compare November 29, 2026 05:14
@Maticcm

Maticcm commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto ef329958483832297acb53e68be94b439e88a90e and retested PR head 19b598859d22eeddb5d99e4e5b4ef8fa278450c9. The resolution uses main's shared mesh root-window check in the deferred recorder. The dispatch grid check still runs when the call is recorded.

On Windows 11 with RTX 3080 (NVIDIA 630.20), all 10 focused mesh, bundle, indirect-bundle, root-layout and close-parity CTests passed both with and without Vulkan validation. The mesh and heavy-cache variants matched all 4,096 pixels, including the deferred bundle draw. No validation errors were reported. Changed-file game-data and whitespace checks passed. Synthetic fixtures only. AI-assisted with OpenAI Codex.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
@enlight3d

Copy link
Copy Markdown
Contributor

RUN of #841 (red/green, GPU box, merged build)

Heads: PR head 19b598859d22, main 54b2a81e95c4. Tested as main + PR head (git merge --no-ff, local only): merged cleanly, no conflicts.

Commands (VS 2022 x64 environment, from the worktree root):
cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build -j 8 --target d3d12_mesh_test d3d12_bundle_test gta6rt
ctest -R "^(d3d12_mesh|d3d12_mesh_heavy_cache)$" --output-on-failure -j1
Also run, as the neighbour that exercises bundles in the same file: ctest -R "^d3d12_bundle$" -j1

  • Red, behavioural (the PR's d3d12_com.cpp reverted to main's, the PR's test kept; it still compiles, so not a build failure): d3d12_mesh and d3d12_mesh_heavy_cache both fail at d3d12_mesh_test.cpp line 864, bundle->Close() == S_OK: on main a DispatchMesh recorded in a bundle is not deferred, is checked against the (not yet inherited) graphics state at record time and makes the bundle's Close return E_INVALIDARG. The earlier checks of that test (the direct-list and ExecuteIndirect mesh cases) pass on main, so the failure is the bundle case.
  • Green, merged: d3d12_mesh Passed, d3d12_mesh_heavy_cache Passed, d3d12_bundle Passed, none skipped (the RTX 3090 runs the mesh pipelines).
  • Link: no new imports vs main (dumpbin /imports of gta6rt.exe, DLL!symbol, sorted: 700 entries on main and on main + PR, identical).

Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo, -DLEONIDA_REQUIRE_VULKAN=ON, Vulkan SDK 1.4.363.1.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
@Maticcm
Maticcm force-pushed the feat/d3d12-bundle-dispatch-mesh branch from 19b5988 to df84037 Compare November 29, 2026 14:49
@Maticcm

Maticcm commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on bd643e46e784daf6bf3a45d09f0ec20e669c4ddb. Head df8403726024cc07ed964972d808c1e8608d0f48 preserves main’s ExecuteIndirect documentation and adds the direct DispatchMesh coverage. GitHub reports the branch as mergeable.

RTX 3080 on Windows 11 passed 10/10 focused tests both with and without Vulkan validation. The normal and heavy-cache mesh variants each matched all 4,096 pixels. No validation errors were reported. Changed-file game-data and whitespace checks passed. Synthetic fixtures only. AI-assisted with OpenAI Codex.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
@fiestorra

Copy link
Copy Markdown
Contributor

Independent verification on this machine (Windows 11, RTX 4090, MSVC 19.44.35226), with a negative control that bites on both tests.

1. It applies. merge-tree clean; the commits cherry-pick onto main 4014af7fe without a conflict. Three files: docs/d3d12_vulkan.md, runtime/shims/d3d12_com.cpp (the change) and runtime/test/d3d12_mesh_test.cpp.

2. With the branch, both tests pass:

ctest -R 'd3d12_mesh'
100% tests passed, 0 tests failed out of 2

3. The control - revert only the shim, keep the test:

git checkout origin/main -- runtime/shims/d3d12_com.cpp
cmake --build … --target d3d12_mesh_test
ctest -R 'd3d12_mesh' --output-on-failure
0% tests passed, 2 tests failed out of 2
[rt] d3d12: ExecuteCommandLists failed: draw kind does not match the pipeline (mesh or vertex); nothing …

Both bite, and the run-time line names the rule the change adds: a draw whose kind does not match the bound pipeline (mesh or vertex) must be refused at ExecuteCommandLists rather than reaching the device. main's shim lets it through, and the test then fails on the pixels or the state that result from it.

What I did not test: whether the shim refuses every mismatched combination the pipeline state allows, and the docs half of the change (documentation).

Why I am commenting: I verify open pull requests that replay onto current main by applying them in a scratch worktree, building the targets their tests name in ctest --show-only=json-v1, running them, and then reverting only the source change to see which tests stop passing.

Written with an AI assistant.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 30, 2026
@Maticcm Maticcm changed the title d3d12: defer DispatchMesh in bundles (D3D-BUNDLE-DISPATCH-MESH) test(d3d12): cover DispatchMesh bundle replay (D3D-BUNDLE-DISPATCH-MESH) Nov 30, 2026
@Maticcm
Maticcm force-pushed the feat/d3d12-bundle-dispatch-mesh branch from df84037 to e6585b5 Compare November 30, 2026 16:20
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 30, 2026
@aslan2142

Copy link
Copy Markdown
Collaborator

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

@aslan2142 aslan2142 closed this Dec 1, 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.

9 participants