[PR #577] [MERGED] d3d12/vulkan: a mesh segment's clipping invocations come from a mesh-primitives query (D3D-MESH-CLIPPING-COUNTER) #622

Closed
opened 2026-11-26 20:18:29 +01:00 by 4ld0 · 0 comments
Owner

📋 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)

  • 916dbc6 d3d12/vulkan: the mesh statistics pool enables no forbidden counter (D3D-291)
  • 1bb23a2 d3d12/vulkan: a mesh segment's clipping invocations come from a mesh-primitives query (D3D-MESH-CLIPPING-COUNTER)
  • 92977ee tests: 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 meshShaderQueries feature of VK_EXT_mesh_shader, the number of primitives the mesh
shader emitted comes from a VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT query instead: a third pool of the
submission, 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.comp adds it as CInvocations. CPrimitives stays 0, because
Vulkan has no clipped-primitive counter and D3D12's CPrimitives is the clipper's output: 0 when a triangle is
dropped, 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:

  • The count goes into CInvocations only. CPrimitives stays 0: the clipper's output is not a number Vulkan keeps
    for a mesh draw.
  • Where the device has no meshShaderQueries, the fields stay 0, as in #540. The feature is asked for when the
    device is created, and the pool is only made where the device has it.
  • A third per-submission pool of that query type, begun and ended with each mesh segment, with the count added as
    field 5 in statistics_sum.comp.

One divergence to document: Vulkan counts a primitive the mesh shader culled with gl_CullPrimitiveEXT, which D3D12
does not count, so the CInvocations of 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 resolve
    run 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 its
    count 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.comp and the regenerated runtime/src/statistics_sum_spirv.h: a mesh segment adds
    field 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 the
    meshShaderQueries feature 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 plan
    carries the pool, and the mesh sum through the CPU mocks fills CInvocations, PSInvocations and
    CSInvocations.
  • runtime/test/d3d12_mesh_test.cpp: the mesh statistics expectations follow the feature; the counts are compared
    with 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_corpus needs the
    game's shaders, vk_sync_validation needs a device with the feature). Built with clang 23.1.6 (llvm-mingw
    20261117) against the pinned Vulkan headers (6802bb47, vulkan-sdk-1.4.363.0).
  • replay_query_edges_test runs the mesh sum through the CPU mocks: the mesh segment is read from the mesh pool and
    the mesh-primitives pool, and it fills CInvocations, PSInvocations and CSInvocations and no other field.
  • replay_query_predication_test checks 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.
  • The regenerated SPIR-V 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_test cannot run. sodove offered the RTX 5070 Ti under
the 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

  • Based on the #540 head and merges cleanly after it.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption.
  • A new translator rule is in the contract table of docs/design.md (not applicable: this is the D3D12 to Vulkan
    runtime 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.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/577 **Author:** [@Mby159](https://github.com/Mby159) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `feature/d3d-mesh-clipping-counter` --- ### 📝 Commits (3) - [`916dbc6`](https://github.com/ubiquitarianism/leonida/commit/916dbc619df63fb169cf5e587f4d53d8884eaccd) d3d12/vulkan: the mesh statistics pool enables no forbidden counter (D3D-291) - [`1bb23a2`](https://github.com/ubiquitarianism/leonida/commit/1bb23a28036ffc7ec1c7207afe5fa6e9470153b3) d3d12/vulkan: a mesh segment's clipping invocations come from a mesh-primitives query (D3D-MESH-CLIPPING-COUNTER) - [`92977ee`](https://github.com/ubiquitarianism/leonida/commit/92977eee6c658d28a37f09615a7091afe26d61ff) tests: require a positive mesh clipping count when the feature is on ### 📊 Changes **11 files changed** (+289 additions, -98 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 Description Claimed in the coordination issue as: D3D-MESH-CLIPPING-COUNTER ([#14](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7126046233)) 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 `meshShaderQueries` feature of `VK_EXT_mesh_shader`, the number of primitives the mesh shader emitted comes from a `VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT` query instead: a third pool of the submission, 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.comp` adds it as `CInvocations`. `CPrimitives` stays 0, because Vulkan has no clipped-primitive counter and D3D12's `CPrimitives` is the clipper's output: 0 when a triangle is dropped, 2 when it is split. This is the addition milk4sale describes in [#14](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7124875009), measured on an RTX 4070 Ti and cross-checked by sodove against native D3D12 on the RTX 5070 Ti ([#14](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7124889756)). The three questions asked on #540 are answered: - The count goes into `CInvocations` only. `CPrimitives` stays 0: the clipper's output is not a number Vulkan keeps for a mesh draw. - Where the device has no `meshShaderQueries`, the fields stay 0, as in #540. The feature is asked for when the device is created, and the pool is only made where the device has it. - A third per-submission pool of that query type, begun and ended with each mesh segment, with the count added as field 5 in `statistics_sum.comp`. One divergence to document: Vulkan counts a primitive the mesh shader culled with `gl_CullPrimitiveEXT`, which D3D12 does not count, so the `CInvocations` of 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 resolve run 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 its count 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.comp` and the regenerated `runtime/src/statistics_sum_spirv.h`: a mesh segment adds field 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 the `meshShaderQueries` feature 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 plan carries the pool, and the mesh sum through the CPU mocks fills `CInvocations`, `PSInvocations` and `CSInvocations`. - `runtime/test/d3d12_mesh_test.cpp`: the mesh statistics expectations follow the feature; the counts are compared with 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_corpus` needs the game's shaders, `vk_sync_validation` needs a device with the feature). Built with clang 23.1.6 (llvm-mingw 20261117) against the pinned Vulkan headers (6802bb47, vulkan-sdk-1.4.363.0). - `replay_query_edges_test` runs the mesh sum through the CPU mocks: the mesh segment is read from the mesh pool and the mesh-primitives pool, and it fills `CInvocations`, `PSInvocations` and `CSInvocations` and no other field. - `replay_query_predication_test` checks 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. - The regenerated SPIR-V 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_test` cannot run. sodove offered the RTX 5070 Ti under the 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 - [x] Based on the #540 head and merges cleanly after it. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption. - [ ] A new translator rule is in the contract table of `docs/design.md` (not applicable: this is the D3D12 to Vulkan runtime layer, whose contract is `docs/d3d12_vulkan.md`). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:29 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#622
No description provided.