mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:05:53 +01:00
[PR #577] [MERGED] d3d12/vulkan: a mesh segment's clipping invocations come from a mesh-primitives query (D3D-MESH-CLIPPING-COUNTER) #622
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#622
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/577
Author: @Mby159
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD
Base:
main← Head:feature/d3d-mesh-clipping-counter📝 Commits (3)
916dbc6d3d12/vulkan: the mesh statistics pool enables no forbidden counter (D3D-291)1bb23a2d3d12/vulkan: a mesh segment's clipping invocations come from a mesh-primitives query (D3D-MESH-CLIPPING-COUNTER)92977eetests: require a positive mesh clipping count when the feature is on📊 Changes
11 files changed (+289 additions, -98 deletions)
View changed files
📝
docs/d3d12_vulkan.md(+27 -16)📝
runtime/shims/d3d12_com.h(+3 -0)📝
runtime/shims/d3d12_vulkan_device.cpp(+4 -0)📝
runtime/src/statistics_sum.comp(+6 -4)📝
runtime/src/statistics_sum_spirv.h(+31 -34)📝
runtime/src/vulkan_backend.h(+41 -14)📝
runtime/src/vulkan_replay.h(+48 -9)📝
runtime/test/d3d12_mesh_test.cpp(+27 -4)📝
runtime/test/replay_query_edges_test.cpp(+76 -14)📝
runtime/test/replay_query_predication_test.cpp(+22 -3)📝
runtime/test/vk_test_device.h(+4 -0)📄 Description
Claimed 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).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.