d3d12/vulkan: the mesh statistics pool enables no forbidden counter (D3D-291) #540
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!540
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/540/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Mby159 on GitHub · 2026-11-24 07:15 UTC · original
Mby159:d3d-291-mesh-statistics→main· +162 −83 · 8 files · 1 commits · merged 2026-11-24 13:37 UTCClaimed in the coordination issue as: D3D-291 (#14)
What and why
The pool a mesh draw runs in enabled the two clipping counters, and
VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076names both of them among the counters a pool that is activeduring a
vkCmdDrawMeshTasksEXTmust not have: the validation layer reports the VUID on everyDispatchMeshinside astatistics query. The finding is in
#14 and is the mesh half of #506.
The VUID leaves the fragment and compute invocations allowed, so the mesh pool now counts those two only. The two sets
of counters are named in
runtime/src/vulkan_replay.h(kMeshStatisticsFlagsand the bits the same VUID forbids),so the rule is in one place and a test can check it. The sum copies the two counters into the
PSInvocationsandCSInvocationsfields of the record, and the clipping fields of a mesh segment read 0.That last part is a measured difference from D3D12: D3D12 counts the clipping invocations and primitives of a mesh
pipeline (one synthetic triangle gave one of each in WARP and in native D3D12), but Vulkan has no counter for them
during a mesh draw, so there is nothing to read them from. Ordinary draw segments still supply all eleven counters, so
a query that mixes both kinds keeps the clipping count of its vertex draws.
runtime/src/statistics_sum_spirv.his regenerated fromstatistics_sum.compwith glslang 16.6.0 (the version theCI pins) and the command its header names; the module's ID numbering differs slightly from the build it replaces, the
code is the same apart from that one condition.
Tested
ctest --test-dir runtime/build -C Release: 72 of 72 tests passed (2 skipped:shader_library_corpusneeds thegame's shaders,
vk_sync_validationneeds a device with the feature). Built with clang 23.1.6 (llvm-mingw20261117) against the pinned Vulkan headers (6802bb47, vulkan-sdk-1.4.363.0).
replay_query_predication_test(new case 17) checks that the mesh pool enables none of the nine counters the VUIDforbids, and counts every one it leaves allowed.
replay_query_edges_test(new case) runs the mesh sum through the CPU mocks: the mesh segment is read from themesh pool, and it fills
PSInvocationsandCSInvocationsand no other field.python -I scripts/run_semantic_tests.py -j 6 tests/semantic: 465 files, 6105 tests, 0 files failed onmain(
8f481cf1). The translator is untouched.python -I scripts/check_no_game_data.py <the eight changed files>: passes.spirv-val.CI
windows,no-game-dataandchange-scopepass.macosandlinux-gpu-toolsfail, oncs_imgload_tfeandcs_imgload_d16_tfe(texel(5,3) = 2071against the expected 71). Those twofixtures are the translator bug of #31, and the failure is on
maintoo: the runtime run ofmainat84347bbbfails the same two jobs the same way. This pull request does not touch thetranslator or those fixtures, and the same two jobs fail on other open pull requests (#382, #345,
#411), so the red is inherited rather than introduced here.
The GPU test that covers this path is
d3d12_mesh_test, which needs a GPU withVK_EXT_mesh_shaderand theKhronos validation layer; this machine has neither (the Radeon 780M is RDNA3, which has no mesh shader support, and
there is no validation layer installed). The validation-layer and WARP/D3D12 measurements for this fix are in the
withdrawn duplicate #527, which reached the same change: on
mainc023a365d3d12_meshreports three VUIDerrors, with the mesh pool counting the fragment and compute invocations only it reports none, the rendered image
still matches all 4096 pixels, the mixed and vertex-only clipping counts are both 2/2 and the mesh-only one is 0/0,
and the mesh-only query still records pixel shader invocations.
GPUs tested: n/a on this host. The measurements above are from sodove's Windows 11 host (NVIDIA GeForce RTX 5070 Ti,
driver 610.74, Khronos validation layer 1.4.369, MSVC 19.44.35220).
AI-assisted: yes.
Checklist
mainand merges cleanly.docs/design.md(not applicable: this is the D3D12 to Vulkanruntime layer, whose contract is
docs/d3d12_vulkan.md).github-bot referenced this pull request2026-11-26 09:21:24 +00:00
@sodove on GitHub · 2026-11-24 07:20 UTC · original · edited 2026-11-24 07:28 UTC
Verified this exact head
c9f4a5697bon Windows 11 26100.7623, RTX 5070 Ti (610.74), MSVC 19.44.35220 Release, with Khronos validation layer 1.4.369 enabled.d336fc9970applied over this head, d3d12_mesh, d3d12_clear and d3d12_clear_restricted_depth all passed with validation enabled. That covers both reports in #506.Synthetic fixtures only. AI-assisted verification.
Cross-API counter comparison for the follow-up
I compared the Vulkan mesh-primitives-generated query directly with D3D12 mesh pipeline statistics for the proposal in #14. Separate synthetic harnesses used the same triangle cases on RTX 5070 Ti (610.74) and Windows 11 26100.7623. WARP and native hardware D3D12 agreed on both clipping fields in all four cases.
The shader-cull case distinguishes the generated count from D3D12 CInvocations. The clip-plane cases distinguish it from CPrimitives. The Vulkan test ran the generated-primitives query alongside a fragment-invocations query with Khronos validation 1.4.369 enabled. All four cases repeated with zero validation errors. Vulkan query definitions · D3D12 counter definitions
@Mby159 on GitHub · 2026-11-24 08:11 UTC · original
Thanks to sodove for running this exact head on Windows with the validation layer: d3d12_mesh passes with zero Vulkan validation errors and all 4096 pixels matching, the mesh-only query records 1024 pixel-shader invocations with 0/0 clipping, and with #516 applied over it the two reports in #506 are covered. That is the confirmation this change needed — the validation layer was the only thing that could show the VUID going away.
On the follow-up in #14 (
VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXTfor a mesh segment'sCInvocations): read as an addition, and we would like to help. The cross-API numbers in sodove's report say the generated count is neither D3D12'sCInvocations(it counts a triangle the mesh shader culled, which D3D12 does not) norCPrimitives(1 against 0 or 2 when the clipper drops or splits a triangle). So before writing code, three questions:CInvocationsonly, leavingCPrimitivesat 0, given the culled-triangle difference?meshShaderQueries, the fields stay 0 as they do here (RADV on the integrated Radeon reports it false)?statistics_sum.comp— the shape milk4sale describes.We can implement that and cover the segment plan and the sum on the CPU (the
replay_query_predicationandreplay_query_edgesmocks), with milk4sale or sodove confirming the run on a mesh-capable device under the validation layer, which is the part this machine cannot do. Say here if someone else would rather take it; otherwise we will claim it in the coordination issue and open a pull request on top of this one.@sodove on GitHub · 2026-11-24 08:20 UTC · original
I can verify the follow-up on the RTX 5070 Ti under Vulkan validation, including a test device with meshShaderQueries disabled.
For the count, I would leave the mesh contribution to CPrimitives at zero. Adding the generated count to CInvocations would be a driver-dependent approximation. The D3D12 references both omit the shader-culled primitive, while the NVIDIA Vulkan query counts it. The llvmpipe result from milk4sale differs again. Devices without meshShaderQueries can keep the current zero mesh contribution in both fields.
If the approximation is chosen, the third pool can add only to field 5 for mesh segments. A mixed draw and mesh query is useful here because it also checks that field 6 still receives the normal draw contribution. I can run the visible, shader-culled, mixed, and feature-disabled cases on the proposed implementation.
@quartz-heron-58 on GitHub · 2026-11-24 08:42 UTC · original
Tested
c9f4a569(cherry-picked onto main1c93c869) together with #516's two commits on an NVIDIA GeForce RTX 4080 (driver 621.24, Vulkan 1.4.357), Windows 11 Home build 26300, MSVC 14.44 / RelWithDebInfo, built withscripts\build_runtime.ps1: pass. The three commits applied on top of each other without conflicts.With
LEONIDA_VK_VALIDATION=1,ctest -R "^d3d12_(clear|mesh)|replay_query":Before, on a build of main
d42773d0:d3d12_meshfails with the three VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 errors of #506 (andd3d12_clearwith its four).With the three commits:
d3d12_mesh,replay_query_edges,replay_query_predication,d3d12_clear,d3d12_clear_restricted_depthandd3d12_clear_formatsall pass, 6 of 6, with no VUID line in the output. The same six pass without validation.Limits: the two PRs were tested together, not each alone; only these six tests were run, not the whole ctest suite; the before and after builds are 24 commits of main apart. No game files.
AI-assisted (Claude Code built, ran the tests and wrote this comment).
@bvtterbroot on GitHub · 2026-11-24 12:02 UTC · original
Tested
c9f4a569on AMD Radeon RX 7900 XTX (RDNA3, Navi 31), AMD driver 26.11.2 (32.0.32029.2010), Vulkan 1.4.359, Windows 11, Vulkan SDK 1.4.363.0: pass.LEONIDA_VK_VALIDATION=1:d3d12_meshpasses, and the 3 xVUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076thatmain21625bcareports are gone. It passes without validation too.replay_query_edgesandreplay_query_predicationpass.main21625bca): fullctest299/304; the 5 failures are the same 5 as onmain(vk_queue_query_sync,d3d12_texture_tiles,d3d12_execute_indirect_validation,d3d12_clear,d3d12_pipeline_library_host), so nothing new.d3d12_clearis the AMD NaN depth clear noted on #516.No game files. AI-assisted (Claude Code ran the builds and tests).
@Mby159 on GitHub · 2026-11-24 12:36 UTC · original
Rebased onto
mainat21625bca8: new head916dbc61(parent21625bca8), one commit, the same eight files, the same+162/-83asc9f4a569. The change itself is byte for byte the one @sodove verified on the RTX 5070 Ti and @bvtterbroot verified on the RX 7900 XTX - only the parent moved.Why now. The base this pull request carried (
d42773d0) is old enough thattests/test_cmake_translator_deps.pyfails on the test merge, and not because of this change:build.pyreachestools/rdna2_isa_tables.pyandtools/rdna2_decode.pybut the dependency list that the test compares against had not been updated yet, andmainhas that list updated since. The same assertion is what turnedmacos-pythonandstdlib-tests-linuxred here whilemainitself passes it. Rebasing is also what the repository's own checklist asks for ("Based on currentmainand merges cleanly"); #431 was rebased for the same reason, and the re-check runs above still apply because the tree of the change is identical.What stays red, and why.
macosandlinux-gpu-toolsfail oncs_imgload_tfeandcs_imgload_d16_tfe- the two shadersmainfails as well (#31).stdlib-tests-linuxandmacos-pythonstill carrytests/test_tool_stdout_encoding.py, which is red onmaintoday and is what #605 fixes. The Windowscheckjob was cancelled by the runner queue, not by a failure.@QemmHD on GitHub · 2026-11-24 13:37 UTC · original
Merging.
Why merged: Fixes the mesh half of #506: the statistics pool active during vkCmdDrawMeshTasksEXT no longer enables the two clipping counters that VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 forbids. Verified on an RTX 5070 Ti (sodove), RTX 4080 (quartz-heron-58) and RX 7900 XTX (bvtterbroot), all with validation on; the rebase to
916dbc619is byte-identical (range-diff checked). Merged on its own first because #577 is stacked on it.Why it's good: On the 4070 SUPER with LEONIDA_VK_VALIDATION=1: plain main fails d3d12_mesh with 3x VUID-...-07076; main + #540 + #577 passes d3d12_mesh, replay_query_edges and replay_query_predication with 0 validation errors, and the counters match sodove's numbers (mesh-only C 8/0, PS 1024).
Tested on Windows 11, RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, alone on main (
21625bca8or51f316092) and in a cumulative merge of #497, #278, #310, #334, #346, #340, #355, #361, #363, #620 and #577 (which carries #540) on main2d73c242f(git merge-tree: 0 conflicts against current main). Repo-consistency set (cmake/translator-deps, shader_stage_resume, runtime_paths, docs, make_game, no-game-data, run_semantic_tests): 566 passed / 5 skipped / 0 failed on main and on main + batch. compileall OK. Full ctest: 302/304 on main and on main + batch (the same two pre-existing failures, d3d12_execute_indirect_validation and d3d12_depth_resolve, no new ones).AI-assisted (Claude Code, Claude Opus 5.5).