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

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/575
Author: @Mby159
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: d3d-mesh-clipping-counter


📝 Commits (2)

  • c9f4a56 d3d12/vulkan: the mesh statistics pool enables no forbidden counter (D3D-291)
  • 4875e01 d3d12/vulkan: a mesh segment's clipping invocations come from a mesh-primitives query (D3D-MESH-CLIPPING-COUNTER)

📊 Changes

8 files changed (+272 additions, -98 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+27 -16)
📝 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 (+21 -4)
📝 runtime/test/replay_query_edges_test.cpp (+76 -14)
📝 runtime/test/replay_query_predication_test.cpp (+22 -3)

📄 Description

Claimed in the coordination issue as: D3D-MESH-CLIPPING-COUNTER (#14)

Depends on: #540

What and why

D3D-291 leaves the clipping fields of a mesh segment at 0, because
VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 forbids the clipping counters in a
PIPELINE_STATISTICS pool that is active during a mesh draw. Where the device exposes
VK_EXT_mesh_shader with the meshShaderQueries feature, the number of primitives the mesh
shader emitted can come from a VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT query run around
the mesh segment instead — the addition @milk4sale describes in
#14.

That query needs a pool of its own type, so a third pool of the submission is created next to
the two the statistics split needs, begun and ended with each mesh segment. Its count is copied
to field 5 of the segment's record and statistics_sum.comp adds it as CInvocations.

CPrimitives stays 0. 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 — so there is nothing to
read it from. Where the device has no meshShaderQueries, the fields stay 0, as in #540.

The one divergence, documented rather than hidden. The count is not D3D12's number: Vulkan
counts a primitive the mesh shader culled with gl_CullPrimitiveEXT, which D3D12 does not
count, so a mesh segment's CInvocations can be higher than D3D12's. Both measurements show
it — @milk4sale's table on an RTX 4070 Ti and @sodove's cross-API comparison against native
D3D12 on the RTX 5070 Ti, where the generated count stayed at 1 for a triangle D3D12's
clipping counters reported as 0/0.

The files:

  • runtime/src/vulkan_backend.h: the pool of VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT,
    created only when the device has the feature, and the copy of its count into field 5 of the
    segment's record. The mesh_queries flag on the context says whether the feature is there.
  • runtime/src/vulkan_replay.h: the pool travels with the list, the segment and the resolve.
  • runtime/src/statistics_sum.comp: a mesh segment now also contributes counter 5.
  • runtime/src/statistics_sum_spirv.h: regenerated from statistics_sum.comp with glslang
    16.6.0 (the version the CI 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_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_predication_test: the mesh-primitives pool is the list's, and the mesh-only
    query's resolve sums its one mesh segment with it.
  • replay_query_edges_test (new case): a mesh segment's record carries the mesh-primitives
    count as CInvocations, the fragment and compute invocations as PSInvocations and
    CSInvocations, and nothing else.
  • python -I scripts/check_no_game_data.py <the eight changed files>: passes.
  • The regenerated SPIR-V passes spirv-val and matches statistics_sum.comp byte for byte
    when recompiled with the same glslang.

The GPU test that covers this path is d3d12_mesh_test, which needs a GPU with
VK_EXT_mesh_shader and the Khronos 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 test checks the counts against each other rather than against fixed numbers, because the
generated count is the driver's and depends on the mesh shader's output.

GPUs tested: n/a on this host. @sodove has offered to run this on the RTX 5070 Ti under the
validation layer, including a test device with meshShaderQueries disabled; @milk4sale measured
the query on an RTX 4070 Ti. Their numbers are quoted above, not mine.

No game files, no keys. AI-assisted: yes.

Checklist

  • Based on current main and merges cleanly.
  • 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/575 **Author:** [@Mby159](https://github.com/Mby159) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `d3d-mesh-clipping-counter` --- ### 📝 Commits (2) - [`c9f4a56`](https://github.com/ubiquitarianism/leonida/commit/c9f4a5697ba0b12eb326a7304b5fff81e7415f5e) d3d12/vulkan: the mesh statistics pool enables no forbidden counter (D3D-291) - [`4875e01`](https://github.com/ubiquitarianism/leonida/commit/4875e01456bf579e55fee3338992e6bea56716b0) d3d12/vulkan: a mesh segment's clipping invocations come from a mesh-primitives query (D3D-MESH-CLIPPING-COUNTER) ### 📊 Changes **8 files changed** (+272 additions, -98 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+27 -16) 📝 `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` (+21 -4) 📝 `runtime/test/replay_query_edges_test.cpp` (+76 -14) 📝 `runtime/test/replay_query_predication_test.cpp` (+22 -3) </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 ### What and why D3D-291 leaves the clipping fields of a mesh segment at 0, because `VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076` forbids the clipping counters in a `PIPELINE_STATISTICS` pool that is active during a mesh draw. Where the device exposes `VK_EXT_mesh_shader` with the `meshShaderQueries` feature, the number of primitives the mesh shader emitted can come from a `VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT` query run around the mesh segment instead — the addition @milk4sale describes in [#14](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7124875009). That query needs a pool of its own type, so a **third pool of the submission** is created next to the two the statistics split needs, begun and ended with each mesh segment. Its count is copied to field 5 of the segment's record and `statistics_sum.comp` adds it as `CInvocations`. `CPrimitives` stays 0. 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 — so there is nothing to read it from. Where the device has no `meshShaderQueries`, the fields stay 0, as in #540. **The one divergence, documented rather than hidden.** The count is not D3D12's number: Vulkan counts a primitive the mesh shader culled with `gl_CullPrimitiveEXT`, which D3D12 does not count, so a mesh segment's `CInvocations` can be higher than D3D12's. Both measurements show it — @milk4sale's table on an RTX 4070 Ti and @sodove's cross-API comparison against native D3D12 on the RTX 5070 Ti, where the generated count stayed at 1 for a triangle D3D12's clipping counters reported as 0/0. The files: - `runtime/src/vulkan_backend.h`: the pool of `VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT`, created only when the device has the feature, and the copy of its count into field 5 of the segment's record. The `mesh_queries` flag on the context says whether the feature is there. - `runtime/src/vulkan_replay.h`: the pool travels with the list, the segment and the resolve. - `runtime/src/statistics_sum.comp`: a mesh segment now also contributes counter 5. - `runtime/src/statistics_sum_spirv.h`: regenerated from `statistics_sum.comp` with glslang 16.6.0 (the version the CI 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_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_predication_test`: the mesh-primitives pool is the list's, and the mesh-only query's resolve sums its one mesh segment with it. - `replay_query_edges_test` (new case): a mesh segment's record carries the mesh-primitives count as `CInvocations`, the fragment and compute invocations as `PSInvocations` and `CSInvocations`, and nothing else. - `python -I scripts/check_no_game_data.py <the eight changed files>`: passes. - The regenerated SPIR-V passes `spirv-val` and matches `statistics_sum.comp` byte for byte when recompiled with the same glslang. The GPU test that covers this path is `d3d12_mesh_test`, which needs a GPU with `VK_EXT_mesh_shader` and the Khronos 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 test checks the counts against each other rather than against fixed numbers, because the generated count is the driver's and depends on the mesh shader's output. **GPUs tested: n/a on this host.** @sodove has offered to run this on the RTX 5070 Ti under the validation layer, including a test device with `meshShaderQueries` disabled; @milk4sale measured the query on an RTX 4070 Ti. Their numbers are quoted above, not mine. No game files, no keys. AI-assisted: yes. ### Checklist - [x] Based on current `main` and merges cleanly. - [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#619
No description provided.