[PR #540] [MERGED] d3d12/vulkan: the mesh statistics pool enables no forbidden counter (D3D-291) #586

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/540
Author: @Mby159
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD

Base: main ← Head: d3d-291-mesh-statistics


📝 Commits (1)

  • 916dbc6 d3d12/vulkan: the mesh statistics pool enables no forbidden counter (D3D-291)

📊 Changes

8 files changed (+162 additions, -83 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+17 -16)
📝 runtime/src/statistics_sum.comp (+4 -4)
📝 runtime/src/statistics_sum_spirv.h (+33 -37)
📝 runtime/src/vulkan_backend.h (+5 -8)
📝 runtime/src/vulkan_replay.h (+20 -4)
📝 runtime/test/d3d12_mesh_test.cpp (+7 -4)
📝 runtime/test/replay_query_edges_test.cpp (+61 -10)
📝 runtime/test/replay_query_predication_test.cpp (+15 -0)

📄 Description

Claimed 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-07076 names both of them among the counters a pool that is active
during a vkCmdDrawMeshTasksEXT must not have: the validation layer reports the VUID on every DispatchMesh inside a
statistics 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 (kMeshStatisticsFlags and 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 PSInvocations and
CSInvocations fields 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.h is 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 (new case 17) checks that the mesh pool enables none of the nine counters the VUID
    forbids, 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 the
    mesh pool, and it fills PSInvocations and CSInvocations and no other field.
  • python -I scripts/run_semantic_tests.py -j 6 tests/semantic: 465 files, 6105 tests, 0 files failed on main
    (8f481cf1). The translator is untouched.
  • python -I scripts/check_no_game_data.py <the eight changed files>: passes.
  • The regenerated SPIR-V passes spirv-val.

CI

windows, no-game-data and change-scope pass. macos and linux-gpu-tools fail, on
cs_imgload_tfe and cs_imgload_d16_tfe (texel(5,3) = 2071 against the expected 71). Those two
fixtures are the translator bug of #31, and the failure is on main too: the runtime run of
main at 84347bbb fails the same two jobs the same way. This pull request does not touch the
translator 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 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 validation-layer and WARP/D3D12 measurements for this fix are in the
withdrawn duplicate #527, which reached the same change: on main c023a365 d3d12_mesh reports three VUID
errors, 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

  • 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/540 **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:** `d3d-291-mesh-statistics` --- ### 📝 Commits (1) - [`916dbc6`](https://github.com/ubiquitarianism/leonida/commit/916dbc619df63fb169cf5e587f4d53d8884eaccd) d3d12/vulkan: the mesh statistics pool enables no forbidden counter (D3D-291) ### 📊 Changes **8 files changed** (+162 additions, -83 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+17 -16) 📝 `runtime/src/statistics_sum.comp` (+4 -4) 📝 `runtime/src/statistics_sum_spirv.h` (+33 -37) 📝 `runtime/src/vulkan_backend.h` (+5 -8) 📝 `runtime/src/vulkan_replay.h` (+20 -4) 📝 `runtime/test/d3d12_mesh_test.cpp` (+7 -4) 📝 `runtime/test/replay_query_edges_test.cpp` (+61 -10) 📝 `runtime/test/replay_query_predication_test.cpp` (+15 -0) </details> ### 📄 Description Claimed in the coordination issue as: D3D-291 ([#14](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7124368713)) ### What and why The pool a mesh draw runs in enabled the two clipping counters, and `VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076` names both of them among the counters a pool that is active during a `vkCmdDrawMeshTasksEXT` must not have: the validation layer reports the VUID on every `DispatchMesh` inside a statistics query. The finding is in [#14](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7121485368) 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` (`kMeshStatisticsFlags` and 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 `PSInvocations` and `CSInvocations` fields 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.h` is 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` (new case 17) checks that the mesh pool enables none of the nine counters the VUID forbids, 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 the mesh pool, and it fills `PSInvocations` and `CSInvocations` and no other field. - `python -I scripts/run_semantic_tests.py -j 6 tests/semantic`: 465 files, 6105 tests, 0 files failed on `main` (8f481cf1). The translator is untouched. - `python -I scripts/check_no_game_data.py <the eight changed files>`: passes. - The regenerated SPIR-V passes `spirv-val`. ### CI `windows`, `no-game-data` and `change-scope` pass. `macos` and `linux-gpu-tools` fail, on `cs_imgload_tfe` and `cs_imgload_d16_tfe` (`texel(5,3) = 2071` against the expected 71). Those two fixtures are the translator bug of #31, and the failure is on `main` too: the runtime run of `main` at `84347bbb` fails the same two jobs the same way. This pull request does not touch the translator 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 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 validation-layer and WARP/D3D12 measurements for this fix are in the withdrawn duplicate #527, which reached the same change: on `main` `c023a365` `d3d12_mesh` reports three VUID errors, 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 - [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:22 +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#586
No description provided.