d3d12/vulkan: a mesh segment's clipping invocations come from a mesh-primitives query (D3D-MESH-CLIPPING-COUNTER) #577
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!577
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/577/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 08:55 UTC · original
Mby159:feature/d3d-mesh-clipping-counter→main· +289 −98 · 11 files · 3 commits · merged 2026-11-24 13:38 UTCClaimed in the coordination issue as: D3D-MESH-CLIPPING-COUNTER (#14)
Depends on: #540 (this is the follow-up that pull request asks for).
What and why
#540 leaves the clipping fields of a mesh segment at 0: VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 forbids the
clipping counters in a pipeline-statistics pool that is active during a mesh draw, and Vulkan has no other counter for
them during one. D3D12 does count the clipping invocations and primitives of a mesh pipeline, so the two numbers differ.
Where the device has the
meshShaderQueriesfeature ofVK_EXT_mesh_shader, the number of primitives the meshshader emitted comes from a
VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXTquery instead: a third pool of thesubmission, begun and ended with each mesh segment, next to the two the statistics split needs. Its count is copied to
field 5 of the segment's record and
statistics_sum.compadds it asCInvocations.CPrimitivesstays 0, becauseVulkan has no clipped-primitive counter and D3D12's
CPrimitivesis the clipper's output: 0 when a triangle isdropped, 2 when it is split.
This is the addition milk4sale describes in
#14, measured on an RTX 4070 Ti and
cross-checked by sodove against native D3D12 on the RTX 5070 Ti
(#14). The three questions asked on
#540 are answered:
CInvocationsonly.CPrimitivesstays 0: the clipper's output is not a number Vulkan keepsfor a mesh draw.
meshShaderQueries, the fields stay 0, as in #540. The feature is asked for when thedevice is created, and the pool is only made where the device has it.
field 5 in
statistics_sum.comp.One divergence to document: Vulkan counts a primitive the mesh shader culled with
gl_CullPrimitiveEXT, which D3D12does not count, so the
CInvocationsof a mesh segment can be higher than D3D12's. Both measurements above show it.What changed
runtime/src/vulkan_replay.h: the segment pool keeps the mesh-primitives pool, the prepared list and the resolverun carry it, and a mesh segment begins and ends that query with its statistics segment.
runtime/src/vulkan_backend.h: the third pool is made where the device has the feature, and the sum copies itscount into the clipping-invocations field. A mesh chunk is cleared first, so the field reads 0 where the device has
no mesh-primitives count.
runtime/src/statistics_sum.compand the regeneratedruntime/src/statistics_sum_spirv.h: a mesh segment addsfield 5 as well. The module is regenerated with glslang 16.6.0, the version the CI pins, with the command its
header names; the ID numbering differs slightly from the build it replaces, the code is the same apart from that one
condition.
runtime/shims/d3d12_com.h,runtime/shims/d3d12_vulkan_device.cpp: the device enables themeshShaderQueriesfeature where the GPU has it, and the layer is told.runtime/test/vk_test_device.h: the test device enables the same feature.runtime/test/replay_query_predication_test.cpp,runtime/test/replay_query_edges_test.cpp: the resolve plancarries the pool, and the mesh sum through the CPU mocks fills
CInvocations,PSInvocationsandCSInvocations.runtime/test/d3d12_mesh_test.cpp: the mesh statistics expectations follow the feature; the counts are comparedwith each other, not written down, because how many primitives reach the fragment shader is the driver's.
docs/d3d12_vulkan.md: the new paragraph.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_edges_testruns the mesh sum through the CPU mocks: the mesh segment is read from the mesh pool andthe mesh-primitives pool, and it fills
CInvocations,PSInvocationsandCSInvocationsand no other field.replay_query_predication_testchecks that the resolve plan hands the mesh-primitives pool to the sum.python -I scripts/check_no_game_data.py <the eleven changed files>: passes.spirv-val.The GPU half is not run here: this machine's Radeon 780M is RDNA3, which has no mesh shader support, so the
mesh-primitives query cannot be created on it and
d3d12_mesh_testcannot run. sodove offered the RTX 5070 Ti underthe Khronos validation layer, and milk4sale the RTX 4070 Ti; the test compares the counts with each other rather
than writing driver-dependent numbers down, so the run confirms the wiring and the field, not an exact count. A run
with the feature disabled is the other half of the check: the fields must read 0 there.
GPUs tested: n/a on this host.
AI-assisted: yes.
Checklist
docs/design.md(not applicable: this is the D3D12 to Vulkanruntime layer, whose contract is
docs/d3d12_vulkan.md).@Mby159 on GitHub · 2026-11-24 08:55 UTC · original
This is the follow-up to #540, stacked on its head: until #540 merges, the diff here shows both changes (the branch is
c9f4a569plus this commit). The branch itself is one commit on top of #540.Three things to make the design explicit, answering the questions asked on #540:
CInvocationsonly.CPrimitivesstays 0: Vulkan keeps no clipped-primitive counter, and D3D12'sCPrimitivesis the clipper's output (0 when a triangle is dropped, 2 when it is split). The generated count is 1 in both of those cases.meshShaderQueries, the fields stay 0, as in #540. The feature is asked for when the device is created, and the third pool is only made where the device has it.statistics_sum.compadds asCInvocations.One divergence, which the documentation now states: Vulkan counts a primitive the mesh shader culled with
gl_CullPrimitiveEXT, which D3D12 does not count, so a mesh segment'sCInvocationscan be higher than D3D12's. milk4sale's table and sodove's cross-API comparison both show it.The GPU half is what is missing here. This machine's Radeon 780M is RDNA3, which has no mesh shader support, so the mesh-primitives query cannot be created on it and
d3d12_mesh_testcannot run. The test compares the counts with each other rather than writing driver-dependent numbers down, so the run confirms the wiring and the field, not an exact count. The other half is a device without the feature: the fields must read 0 there.sodove offered the RTX 5070 Ti under the Khronos validation layer, and milk4sale the RTX 4070 Ti. Either would do; say here and I will hand the GPU runs over instead.
What ran here:
ctest --test-dir runtime/build -C Releaseon the delivered tree (upstreamd42773d0plus #540 plus this change), 71 of 72 passed and 2 skipped; the one failure isvk_queue_query_sync, which fails the same way on the unmodifiedd42773d0tree (4 of 5 runs), so it is not this change.replay_query_edges_testruns the mesh sum through the CPU mocks and checks that the mesh segment is read from the mesh pool and the mesh-primitives pool, and that it fillsCInvocations,PSInvocationsandCSInvocations.replay_query_predication_testchecks that the resolve plan hands the pool to the sum. The semantic suite: 465 files, 6105 tests, 0 files failed.check_no_game_data.pypasses on all eleven changed files, and the regenerated SPIR-V passesspirv-val.AI-assisted: yes.
@Mby159 on GitHub · 2026-11-24 08:58 UTC · original
Note on the duplicate: #575 is the same work, published a moment earlier from a session whose state was lost. It is closed in favour of this one. It never asks for the
meshShaderQueriesfeature, socontext_.mesh_querieswould stay false and the third pool would never be made, and itsd3d12_mesh_test.cppreads a member the branch does not add, so it does not build. The three files that fix that are here: the feature is asked for when the device is created (runtime/shims/d3d12_vulkan_device.cpp,runtime/shims/d3d12_com.h) and the test device enables it (runtime/test/vk_test_device.h).Review this pull request.
@sodove on GitHub · 2026-11-24 10:05 UTC · original
Windows GPU verification of exact head
62c8311on RTX 5070 Ti (610.74), MSVC Release and Khronos validation 1.4.369. The stock mesh test and both replay-query tests passed (3/3). The mesh test matched all 4,096 pixels, with zero validation errors.I also printed the counters from the stock synthetic draw with a test-only change. With
meshShaderQueriesenabled, the mesh-onlyCInvocationswas 8, the mixed result after subtracting its vertex-only contribution was 10, and meshCPrimitiveswas 0. With the feature disabled at Vulkan device creation, all three counters were 0. Both runs again matched 4,096 pixels and had zero validation errors.One test gap showed up in a negative control. I left the Vulkan feature enabled and passed false only in the layer's test device options. The stock enabled-feature assertion still passed with both invocation counts at zero. Asserting a positive mesh-only count for this visible synthetic draw would catch that loss of wiring while keeping the exact count driver-independent.
AI-assisted, synthetic tests only.
@Mby159 on GitHub · 2026-11-24 10:18 UTC · original
@sodove your negative control found a real gap in the test, and it is fixed in
972a1e47(parent62c8311, the head you verified).What the control showed: with the layer reporting the feature but the mesh-primitives pool never created, both counts stay at 0 and the enabled-feature assertion still held, because it compared
0 >= 0. The enabled branch now asks for a positive count:mesh_onlyis query 1, theDispatchMesh(2, 2, 1)draw whose red tint fills the top-left quadrant, so the mesh shader emits at least one primitive on any correct driver. The number stays driver-dependent, so the test asks for a positive count and not for a number. The disabled case is unchanged and stays pinned at zero (mesh_clipping == 0andmesh_only.CInvocations == 0).Your numbers are consistent with this: mesh-only
CInvocationswas 8, and the mixed range's mesh share was 10, which is theDispatchMesh(2, 2)draw plus theDispatchMesh(1, 1)one.This is a test-only change, so the implementation is exactly the head you verified. The new head is
972a1e47- could you re-run the mesh test on it, so the pull request carries a verification of the exact head?Local verification is limited, and I want to be exact about it: this machine's GPU has no
VK_EXT_mesh_shader, so the mesh block is skipped here, and the file does not compile here at all - the repository'sd3d12_com.hwants the SDK'sd3d12.hand MinGW's is older (ID3D12GraphicsCommandList8andD3D12_RASTERIZER_DESC2are missing), so the file needs the CI Windows build. The added block was compiled on its own with-Wall -Wextra -Wsign-compareand is clean, andpython -I scripts/check_no_game_data.pyon the file passes.AI-assisted (MiniMax Code).
@sodove on GitHub · 2026-11-24 10:25 UTC · original
@Mby159 Confirmed on exact head
972a1e47: the stockd3d12_meshtest built with MSVC Release and passed on the RTX 5070 Ti (610.74), matching 4,096 pixels under Khronos validation 1.4.369 with zero validation errors.The same test-only probe still reports 8 mesh-only clipping invocations and 10 mesh invocations added to the mixed range. Disabling the device feature gave zero and passed. Keeping it enabled on the device but disconnecting only the layer option now fails specifically at
mesh_only.CInvocations > 0with no validation errors. The new assertion catches the missing wiring.AI-assisted, synthetic tests only.
@Mby159 on GitHub · 2026-11-24 12:36 UTC · original
Rebased onto
mainat21625bca8together with #540: new head92977eee(parent1bb23a28= #540's new head916dbc61). The three commits are the same three -d3d12/vulkan: the mesh statistics pool enables no forbidden counter,d3d12/vulkan: a mesh segment's clipping invocations come from a mesh-primitives query,tests: require a positive mesh clipping count when the feature is on- and the diff againstmainis the same eleven files and the same+289/-98as on972a1e47.Why now. The base this pull request carried (
7430f59b) is old enough thattests/test_cmake_translator_deps.pyfails on the test merge, for a reason that has nothing to do with this change:build.pyreachestools/rdna2_isa_tables.pyandtools/rdna2_decode.py, and the dependency list the test compares against was updated onmainafterwards.mainpasses that test today; the test merge of this pull request did not.The verification still applies. @sodove's negative-control run was on
972a1e47: the same content now sits on92977eee, including themesh_only.CInvocations > 0assertion that the control trips, and the counts it measured - 8 mesh-only clipping invocations, 10 in the mixed range, 0 with the device feature off - are unchanged by the rebase.What stays red, and why.
macosandlinux-gpu-toolsfail oncs_imgload_tfeandcs_imgload_d16_tfe, the two shadersmainfails as well (#31). The Windows job'scrt_timed_waitis a timing-sensitive test, and the same job passed on #540's head minutes earlier.@QemmHD on GitHub · 2026-11-24 13:38 UTC · original
Merging.
Why merged: Stacked on #540: the clipping invocations of a mesh segment now come from a mesh-pipeline query, so CInvocations/CPrimitives stay correct for mixed vertex + mesh work. sodove verified the exact head, including the disconnected-feature negative control that found (and now proves fixed) a gap in the test.
Why it's good: The embedded SPIR-V in statistics_sum_spirv.h was recompiled from the PR's .comp: all 431 words are identical and spirv-val passes. d3d12_mesh with validation: 0 errors, mixed C 12 vs vertex-only C 2, so the mesh share is 10, as expected.
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).