Skip to content

Runtime: pipeline-statistics queries around mesh draws (D3D-291) - #2359

Open
LloydNicholson wants to merge 3 commits into
ItsNotRexed:mainfrom
LloydNicholson:runtime/mesh-statistics
Open

LloydNicholson wants to merge 3 commits into
ItsNotRexed:mainfrom
LloydNicholson:runtime/mesh-statistics

Conversation

@LloydNicholson

@LloydNicholson LloydNicholson commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as D3D-291: #2078 (comment)

Depends on: #1712 (D3D-29, mesh-shader PSOs and DispatchMesh). This branch is stacked on it, so until #1712 merges the diff also shows its two commits. The change here is the last commit, 940ab5d, on main f847748.

What and why

The problem. D3D12 allows DispatchMesh inside a PIPELINE_STATISTICS query and reads its IA/VS/GS/HS/DS fields as 0. Vulkan forbids vkCmdDrawMeshTasksEXT while a query with those counters is active (VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076). The heap's pool is always created with all eleven counters (0x7ff). Gen800 found this in review of #1712.

The fix reuses the D3D-162 split of a statistics query into physical segments:

  • Planning (plan_statistics_segments): a statistics query that holds a mesh draw is split, like one that holds a resolve or one of the other helpers. Mesh draws share the segment numbering of the helper splits.
    • A segment's first draw picks its pool: the submission's full pool, or a second pool with only CLIPPING_INVOCATIONS, CLIPPING_PRIMITIVES, FRAGMENT_SHADER_INVOCATIONS and COMPUTE_SHADER_INVOCATIONS.
    • A later draw of the other kind ends the segment and begins one of its own kind. A query that keeps switching kinds gets one segment per run.
    • Dispatches and segments without draws use the full pool, and ExecuteIndirect draws count as vertex draws.
  • Emit: the split points before draws use the per-command fields the helpers already have (Prepared::statistics_end/begin), so the draw itself still runs. Each draw has its own rendering scope, so the split stays outside rendering. The per-command split helpers, and emit_query's, now pick the pool by the segment's kind, since a helper or resolve can end a mesh segment.
  • Resolve: the sum copies a mesh segment's four counters into fields 5–8 of its record. statistics_sum.comp gains a mesh push constant and adds them as CInvocations, CPrimitives, PSInvocations and CSInvocations, so the other fields get nothing from that segment.
    • A query with only mesh draws is one mesh segment, and goes through the same sum.
    • statistics_sum_spirv.h is regenerated as its header says: glslangValidator -V --target-env vulkan1.0 -Os -g0, then spirv-val.
  • Refusal: without the compute helper there is no segment pool. A list that needs the split is then refused with unsupported rather than run unsplit around a mesh draw.
  • Docs: docs/d3d12_vulkan.md §4.6 has the rule.

Queries without mesh draws are planned exactly as before.

Mixed queries: a query over vertex and mesh draws counts both. The vertex draws' IA/VS counts are kept, and the mesh draws add their clipping, pixel and compute counts.

Rebased onto main f847748: main added D3D-252's overlapping statistics queries, with a second planner, plan_overlapping_statistics_segments. That planner now records each segment's kind and splits at a mesh/vertex switch the same way, so overlapping queries around mesh draws stay out of the forbidden state too. replay_query_edges_test (new on main) now calls sum_statistics with the mesh pool and kinds, and expects the 8-byte push constant.

Tested

AI-assisted (Claude Code). RX 9060 XT (RDNA4, GFX1200), RADV Mesa 27.0.0-devel, Nobara Linux. Windows binaries cross-built with clang-cl 22 and the 10.0.26100 SDK, run under Wine 11.22. Native tests built with GCC.

  • replay_query_predication_test cases 14 and 15 (CPU, new): case 14 is a single query; case 15 is the same split inside overlapping queries (D3D-252's planner, see below).
    • The query holds vertex, mesh, mesh and vertex draws. It splits before the first mesh draw and before the vertex draw after it, giving three segments with kinds full, mesh, full; the second mesh draw doesn't split. Its resolve sums all three.
    • A mesh-only query is one mesh segment, and its resolve goes through the sum with the mesh pool.
    • A vertex-only query is not split.
    • Planning is refused without the mesh pool, and without a segment pool. Cases 1–13 still pass.
  • d3d12_mesh_test (GPU, extended): three queries in one list, on a mixed, a mesh-only and a vertex-only range.
    • The vertex fields of the mixed and vertex-only queries are exactly 6 vertices and 2 primitives.
    • The mesh-only query reads 0 in IA/VS/GS/HS/DS/CS.
    • The mixed query has more clipping and pixel-shader invocations than the vertex-only one.
    • On RADV the clipping counts add up exactly: mixed 12 = vertex-only 2 + mesh 8 + 2. RADV's PSInvocations isn't the pixel count, so the test compares against the vertex-only query rather than an absolute number.
    • The D3D-29 pixel checks are unchanged: 4096/4096.
  • Validation: VK_LAYER_KHRONOS_validation 1.4.341 (Fedora) reports nothing beyond the two VUIDs that come from this host's environment.
    • ⚠️ I could not reproduce the error itself here. With the layer change undone, the same test also ran without a 07076 report on this layer version, though the layer contains the VUID. Gen800 saw it with SDK 1.4.363 on NVIDIA.
    • A run on Windows with a current SDK layer (@Gen800, or @undeadhuman37 on the RTX 4070 SUPER) would confirm the fix against the report.
  • D3D-162 paths: vk_overlapping_occlusion, vk_binary_occlusion, vk_predicated_copy, depth24_convert and replay_query_predication pass natively under validation, with no messages.
  • Native ctest: 41/41 passed (2 skipped). The query and helper tests (vk_overlapping_occlusion, vk_binary_occlusion, vk_predicated_copy, depth24_convert, replay_query_predication, replay_query_edges) pass under validation.
  • d3d12_* under Wine (53 tests): 6 fail, and all 6 fail the same way on main f847748 on this machine (d3d12_clear, d3d12_compute, d3d12_fence_timing, d3d12_private_data, d3d12_subresource_copy, d3d12_xdxr_rt).
  • Doc checks: tests/test_docs_links.py and tests/test_text_write_line_endings.py pass.

Not tested: Windows/MSVC with Microsoft's loader and a current validation layer; NVIDIA or Intel; ExecuteIndirect mesh draws, which the layer doesn't have yet.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • No translator rule changed.

🤖 Generated with Claude Code

@TricksterG

Copy link
Copy Markdown
Contributor

Tested on an NVIDIA GeForce RTX 5090 (Windows 11, driver 621.24, Vulkan SDK 1.4.363.0), built at ec3e628 (current head, same result as at 07f7530 before the rebase), LEONIDA_VK_VALIDATION=1.

replay_query_predication passes. d3d12_mesh fails with 3 validation errors, which are the VUID this PR targets:

validation: vkCmdDrawMeshTasksEXT(): query 1 in VkQueryPool 0x2f000000002f with type VK_QUERY_TYPE_PIPELINE_STATISTICS is active, which is invalid because it was created with pipelineStatistics (VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT|VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT)
(same for query 1 again and query 3)
3 validation errors
statistics, mixed: IA 6/2 VS 6 C 12/12 PS 3328 CS 0; mesh only: C 8/8 PS 1024; vertex only: C 2 PS 2048

VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 forbids CLIPPING_INVOCATIONS and CLIPPING_PRIMITIVES as well, not only IA/VS/GS/HS/DS. The mesh pool in vulkan_backend.h still includes both, and the code comment says the reverse. It should probably only keep FRAGMENT_SHADER_INVOCATIONS and COMPUTE_SHADER_INVOCATIONS, plus the mesh/task counters if wanted. That means reporting C 0/0 for mesh ranges, and the test expectations change with it. llvmpipe likely doesn't expose mesh shaders, so this path needs a real GPU to show up.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check: AMD Radeon RX 9070 (RDNA4), Windows 11, MSVC Release, Vulkan SDK 1.4.363. Tested head ec3e628 merged onto main 4947579 (clean merge), full build, full ctest -C Release -j 4: 100% tests passed out of 117 | new failures vs main: none. The main baseline on the same machine passes 107/107, so nothing regresses here.

AI-assisted (Claude Code); runs on my machine.

@Gen800

Gen800 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent verification on RTX 5060 Ti, NVIDIA 621.14, Windows 11 Pro, MSVC 19.44 + Ninja, Vulkan SDK/validation layer 1.4.363.0.

Tested PR head ec3e628d against #1712 47e8b421 and main 49475796.

Confirmed TricksterG's finding:

  • d3d12_mesh with LEONIDA_VK_VALIDATION=1: 3 × VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076, reproducible 5/5 runs.
  • Validation-layer loading confirmed through VK_LOADER_DEBUG=layer.
  • api_dump confirms the mesh query pool uses 0x4E0, including forbidden CLIPPING_INVOCATIONS and CLIPPING_PRIMITIVES bits.
  • Two errors originate from the mixed query's mesh draws; one from the mesh-only query.
  • Without validation, the full CTest suite completes successfully. With validation, only d3d12_mesh fails.

Additional findings:

The current test expects nonzero clipping statistics from mesh draws. Those values depend on counters Vulkan prohibits for this operation. The documentation in §4.6 and the comment in vulkan_backend.h also need correction.

Locally tested minimal fix (not pushed):

  • Keep only FRAGMENT_SHADER_INVOCATIONS and COMPUTE_SHADER_INVOCATIONS in the mesh-compatible pool.
  • Map mesh PSInvocations to slot 7.
  • Update the statistics sum shader, regenerate its SPIR-V header, and adjust the test expectations.

Results after this change:

  • 0 Vulkan validation errors, 5/5 runs
  • Mixed: IA 6/2, clipping 2/2, PS 3328
  • Mesh-only: clipping 0/0, PS 1024
  • Vertex-only: clipping 2, PS 2048

The full unmodified GPU suite had identical verdicts across the three tested revisions (139 passed, 46 skipped out of 185), and 2,567 semantic tests passed.

One design question: should mesh clipping counters explicitly return zero for now, with that limitation documented, or should mapping mesh-specific statistics be tracked separately?

The segment-splitting approach otherwise looks promising. I recommend correcting the query mask and expectations before merging.

Synthetic fixtures only; no game data. AI-assisted verification (Claude Code).

@umnitus

umnitus commented Nov 22, 2026

Copy link
Copy Markdown

Confirmed the RTX 5090 report on an RTX 3060 12 GB at ec3e628, Windows 11, driver 621.14, Vulkan 1.4.357, Khronos validation 1.4.363.

With LEONIDA_VK_VALIDATION=1, d3d12_mesh_test exited 1 in two consecutive runs. Each run reported exactly three VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 errors (query 1 twice and query 3 once), with both CLIPPING_INVOCATIONS and CLIPPING_PRIMITIVES set. The same binary exited 0 with validation off. replay_query_predication_test passed.

AI-assisted testing and write-up.

@Gabzinnn12

Copy link
Copy Markdown

Same on AMD: tested ec3e628 on AMD Radeon RX 7600 (RDNA3), AMD 26.11.2 (LLPC), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0. d3d12_mesh_test passes without validation; with LEONIDA_VK_VALIDATION=1 it reports the same 3 errors @TricksterG saw: VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 for queries 1 (twice) and 3, pool created with CLIPPING_INVOCATIONS|CLIPPING_PRIMITIVES. So it is not NVIDIA-specific.
The VUID lists both CLIPPING bits as forbidden while a mesh draw runs, so the mesh segments' second pool still trips it. Dropping those two bits from that pool would satisfy the VUID, but the statistics mapping and the test's expected mesh clipping counts would need to change with it.
#1712 at 47e8b42 passes d3d12_mesh_test with validation here. ctest (no validation): 0 failed out of 125.

AI-assisted (Claude Code, reviewed with Codex). No game files.

@LloydNicholson
LloydNicholson force-pushed the runtime/mesh-statistics branch from ec3e628 to 46f7314 Compare November 22, 2026 18:30
@FaKL-Code

Copy link
Copy Markdown
Contributor

Tested ec3e628 (merged onto main 4947579) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: fails under validation

  • Clean configure + build of runtime/ (Visual Studio generator, RelWithDebInfo): the only new warnings are two C4324s (structure padded for alignment) at runtime/test/d3d12_mesh_test.cpp:44, in the test's Subobject template; nothing new in the runtime itself.

  • ctest -C RelWithDebInfo -j 4: 117/117 passed without validation (loader run on its own; 7 skipped for missing inputs or optional components, gameinput disabled, as on main). d3d12_mesh prints statistics, mixed: IA 6/2 VS 6 C 12/12 PS 3328 CS 0; mesh only: C 8/8 PS 1024; vertex only: C 2 PS 2048.

  • With LEONIDA_VK_VALIDATION=1, d3d12_mesh fails: the layer from SDK 1.4.363.0 reports VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 three times and the test ends with "3 validation errors". The first one:

    vkCmdDrawMeshTasksEXT(): query 1 in VkQueryPool … with type VK_QUERY_TYPE_PIPELINE_STATISTICS is active, which is invalid because it was created with pipelineStatistics (VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT|VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT) which is incompatible with mesh shaders.

    The spec text it quotes lists CLIPPING_INVOCATIONS_BIT and CLIPPING_PRIMITIVES_BIT among the bits an active query must not contain during a mesh draw, together with IA, VS, GS and tessellation. The new mesh pool at runtime/src/vulkan_backend.h:1630 keeps both clipping bits, and the comment above it says 07076 allows them. On this SDK it doesn't. This is the same SDK as the original NVIDIA report, which may be why it didn't show up on your side.

    Dropping the two clipping bits from the mesh pool (FRAGMENT_SHADER_INVOCATIONS and COMPUTE_SHADER_INVOCATIONS only) and reading C as 0 for mesh-only segments, the way IA/VS already are, should clear it. The mesh-only C 8/8 above would then become 0.

  • The other 7 tests in the validation pass (command_list, d3d12_com, d3d12_vulkan_device, d3d12_fence_timing, d3d12_descriptor, d3d12_compute, d3d12_state_map) pass with validation.

AI-assisted (Claude).

@LloydNicholson
LloydNicholson force-pushed the runtime/mesh-statistics branch from 46f7314 to 940ab5d Compare November 22, 2026 20:18
itsRevela added a commit to itsRevela/Leonida that referenced this pull request Nov 22, 2026
ID3D12Device::CreateQueryHeap refused D3D12_QUERY_HEAP_TYPE_PIPELINE_STATISTICS1. It now creates one on a device
with VK_EXT_mesh_shader's meshShaderQueries (enabled with meshShader where the GPU has it, and reported through
OPTIONS9.MeshShaderPipelineStatsSupported); without it the heap is still refused with E_NOTIMPL. Built on D3D-291
(ItsNotRexed#2359), which splits a statistics query around mesh draws into full and mesh-pool segments.

- The heap's pool counts the 11 classic statistics plus TASK_SHADER_INVOCATIONS (0x800) and
  MESH_SHADER_INVOCATIONS (0x1000); Vulkan writes them in bit order after CSInvocations, the order of
  ASInvocations and MSInvocations. Neither bit is forbidden around vertex draws (only around
  vkCmdDrawClusterHUAWEI, VUID-07819).
- A query that holds a mesh draw is always split (VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076, D3D-291), so
  an unsplit query ran no mesh draw: the resolve copies its 13 statistics 112 bytes apart and writes MSPrimitives
  as 0.
- With a split PIPELINE_STATISTICS1 query in the submission, the mesh pool also counts task and mesh invocations
  (6 counters), and each mesh segment runs a VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT query of its index beside
  it; full segments run none. No VUID ties those queries to the draw kind (07068, 07070, 07071), but NVIDIA's
  Vulkan driver counts a VS draw's triangles in them and D3D12 does not, so MSPrimitives is counted only around
  mesh draws.
- A split PIPELINE_STATISTICS1 query always resolves through the sum. statistics_sum.comp takes the result width
  (11 or 14) as a push constant and maps a mesh segment's task and mesh invocations and primitives to fields 11-13.
  statistics_sum_spirv.h is regenerated with glslang 16.6.0 (-V --target-env vulkan1.0 -Os -g0; spirv-val clean).

Tested on Windows 11, NVIDIA GeForce RTX 3070 Ti, driver 610.88, without Vulkan validation layers (not installed):
ctest 125/125 passed, 8 skipped (game data, the validation layer, an RGB9E5 RTV); ItsNotRexed#2359's head alone: 124/124
passed, the same 8 skipped. New: d3d12_mesh_statistics runs one list on the layer and on host D3D12 (DXIL from
HLSL equivalents compiled at run time by the Windows SDK's dxcompiler.dll): a VS draw in PIPELINE_STATISTICS1 and
PIPELINE_STATISTICS queries, DispatchMesh(2,2,1) and (1,1,2), a query never ended, and a query split by a resolve
inside it, resolved at an offset. Every one of the 14 fields matches the host. replay_query_predication cases
10-12 cover the unsplit resolve, the primitives queries beside mesh segments only, the refusals and the 14-counter
sum; d3d12_query_rules compares PIPELINE_STATISTICS1 heap creation by count and node mask with WARP and the GPU.
The host's refusal HRESULT is unmeasured: every host adapter here (WARP, RTX 3070 Ti) supports these heaps.

Depends on: ItsNotRexed#1712, ItsNotRexed#2359
AI-assisted (Claude Code).
@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 940ab5d as-is (stacked on #1712) on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 142/142 without validation.
  • d3d12_mesh, replay_query_edges and replay_query_predication: pass 20 of 20 runs each.
  • Under LEONIDA_VK_VALIDATION=1: d3d12_mesh still fails with the three VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 errors reported above. The push after those reports didn't change this. The two replay tests pass.
  • For comparison, d3d12_mesh at Runtime: mesh-shader PSOs from pipeline state streams and DispatchMesh (D3D-29) #1712's head d8102a2 passes under validation with 0 messages, so the errors come from this PR's statistics queries.

AI-assisted (Claude Code).

@Ayinaki

Ayinaki commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested c3569af on RTX 5070, driver 616.86, Windows 10.0.26200: pass.

Built runtime with MSVC 14.52 (Visual Studio 18 2026, x64, RelWithDebInfo) and ran every target this PR touches, with LEONIDA_VK_DEVICE="RTX 5070". All four exit 0:

  • d3d12_mesh_test: "statistics, mixed: IA 6/2 VS 6 C 12/12 PS 3328 CS 0; mesh only: C 8/8 PS 1024; vertex only: C 2 PS 2048", with the D3D-29 mesh tier taken and the mesh/VS PSOs compared on the layer.
  • replay_query_edges_test: heap boundaries, chunking, persistent queries, predicated copies and queue ownership passed.
  • replay_query_predication_test: query resolve suspends conditional rendering around fills, copies and dispatches.
  • replay_cpu_bench: exits 0.

@sh1shu1

sh1shu1 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested c3569af on NVIDIA RTX 4070 SUPER (driver 616.92), Windows 11 26200, MSVC 14.44, Vulkan SDK 1.4.363, RelWithDebInfo: fail.

  • ctest: 171/174 passed; fails here, passes on main 98fa503: d3d12_mesh; dxgi_device, dxgi_swapchain fails on main 98fa503 too (not from this PR), same 9 skips as main 98fa503
  • d3d12_mesh, replay_query_edges, replay_query_predication: 2/3
  • run_gpu_tests (LEONIDA_VK_VALIDATION=1): 170/217 native, 201/217 with LEONIDA_W64_EMULATE=1, 0 failed; identical to main 98fa503
    AI-assisted (Claude Code, Claude Fable 5.1).

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested c3569af on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran ctest -R "^(d3d12_mesh|replay_query_edges|replay_query_predication)$" (the tests this PR changes). RTX 5080: 3/3 pass. Radeon: replay_query_edges and replay_query_predication pass, but d3d12_mesh FAILS (2/3; same on a second run). Output:

[rt] d3d12: ExecuteCommandLists failed: draw kind does not match the pipeline (mesh or vertex); nothing was submitted
line 474: mixed.GSInvocations == 0 && mixed.GSPrimitives == 0 && mixed.HSInvocations == 0 && mixed.DSInvocations == 0 && mixed.CSInvocations == 0
device: AMD Radeon(TM) Graphics
statistics, mixed: IA 6/2 VS 6 C 12/12 PS 3328 CS 0; mesh only: C 8/8 PS 1024; vertex only: C 2 PS 2048

I did not check whether main passes on the Radeon. No game files.

AI-assisted.

@XFlawless1

Copy link
Copy Markdown
Contributor

Tested c3569afe (on main 98fa503f) on Windows 11 Pro 26300, MSVC 19.44, Vulkan SDK 1.4.363.0, on the Radeon iGPU of a Ryzen 7 9800X3D (RDNA2, driver 32.0.21042.62) and an RTX 5080 (621.14). I found the cause of the Radeon d3d12_mesh failure @Vonsek reported. Running with validation on also shows a second problem, on both GPUs.

1. Radeon, line 474: AMD counts GS invocations without a GS, and native D3D12 does too

Printing all 11 fields, the Radeon's only wrong value is GSInvocations = 2. It isn't in the mesh segment: the vertex-only query reads GS 2/0 too, and the mesh-only query reads GS 0/0.

query (layer, this PR) IA VS GS inv/prim C inv/prim PS
Radeon, mixed 6/2 6 2/0 12/12 3328
Radeon, mesh only 0/0 0 0/0 8/8 1024
Radeon, vertex only 6/2 6 2/0 2/2 2048
RTX 5080, all three same same 0/0 same same

To check what D3D12 itself does, I ran a native D3D12 probe (no Leonida code): one VS+PS draw of 2 triangles, no GS, inside a PIPELINE_STATISTICS query.

native D3D12 adapter IA VS GS inv/prim C inv/prim
RTX 5080 6/2 6 0/0 2/2
AMD Radeon (same iGPU) 6/2 6 2/0 2/2
WARP 6/2 6 0/0 2/2

So passing the Vulkan count through matches AMD's own D3D12 driver, and the runtime is right. The test is too strict: it expects 0 on every vendor. Comparing the mixed query with the vertex-only one checks what the PR means, that mesh draws add no geometry work:

-            EXPECT(mixed.GSInvocations == 0 && mixed.GSPrimitives == 0 && mixed.HSInvocations == 0 &&
-                   mixed.DSInvocations == 0 && mixed.CSInvocations == 0);
+            // AMD counts GS invocations for a VS-only draw (native D3D12 does too), so compare with the vertex-only
+            // query: the mesh draws add no geometry, tessellation or compute work.
+            EXPECT(mixed.GSInvocations == vertex_only.GSInvocations && mixed.GSPrimitives == vertex_only.GSPrimitives &&
+                   mixed.HSInvocations == 0 && mixed.DSInvocations == 0 && mixed.CSInvocations == 0);

With that change, d3d12_mesh passes on both GPUs without validation. The mesh-only check (GS 0/0) can stay as it is: it holds on AMD too.

2. Both GPUs, with LEONIDA_VK_VALIDATION=1: VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076

With validation on, d3d12_mesh fails on both GPUs with 3 errors (queries 1 and 3, the two that hold mesh draws). The mesh pool (runtime/src/vulkan_backend.h:1865) has CLIPPING_INVOCATIONS | CLIPPING_PRIMITIVES | FRAGMENT_SHADER_INVOCATIONS | COMPUTE_SHADER_INVOCATIONS. The validation layer's text of 07076 lists CLIPPING_INVOCATIONS_BIT and CLIPPING_PRIMITIVES_BIT among the counters that must not be in an active query during a mesh draw. So the comment above it ("the counters a mesh draw allows ... clipping invocations and primitives") has the clipping pair backwards. Only fragment and compute invocations (plus the task/mesh bits with meshShaderQueries) are allowed. The earlier test runs here were without validation, which is why it didn't show. The values are plausible on both drivers today, but that's undefined behaviour.

Removing the two clipping bits leaves mesh draws with no source for CInvocations/CPrimitives, which host D3D12 reports (8/8 for the mesh-only query on NVIDIA). Two options I can see, both your call:

I haven't written either one, since it touches both PRs' shared statistics_sum.comp design.

Also ran replay_query_edges and replay_query_predication: pass on both GPUs. No game files.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested c3569af merged with main 98fa503 on Windows (MSVC 14.51, RelWithDebInfo, ninja): pass. ctest vk_queue_query_sync, d3d12_query_rules, d3d12_mesh, replay_query_predication and replay_query_edges 5/5 on RTX 4080 SUPER; on the UHD 770 selected with VK_LOADER_DRIVERS_DISABLE=nv and LEONIDA_VK_DEVICE=Intel; the tests print device: Intel(R) UHD Graphics 770: 4/5 pass and d3d12_mesh skips (no mesh shaders on this GPU). Negative control with main's runtime/shims/d3d12_com.cpp, d3d12_com.h, d3d12_vulkan_device.cpp and runtime/src command_list.h, shader_library.h, statistics_sum.*, vulkan_backend.h, vulkan_replay.h: replay_query_edges_test and replay_query_predication_test no longer compile (the mesh statistics members the PR adds are missing).

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested c3569afe on NVIDIA GeForce RTX 4090 (driver 621.01), Windows 11, MSVC 14.51, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.1: pass without validation. An AI tool helped me to do this test. No game files. This is a third RTX 40-series result, because the two results for this head are different (RTX 4070 SUPER: fail, RTX 4080 SUPER: pass).

Without validation

  • d3d12_mesh_test: 20 of 20 runs pass. Each run prints statistics, mixed: IA 6/2 VS 6 C 12/12 PS 3328 CS 0; mesh only: C 8/8 PS 1024; vertex only: C 2 PS 2048.
  • replay_query_edges_test and replay_query_predication_test: pass.

Thus the RTX 4090 agrees with the RTX 4080 SUPER. I cannot reproduce the failure from the RTX 4070 SUPER report. @sh1shu1, which line does d3d12_mesh print when it fails on your computer? And was LEONIDA_VK_VALIDATION=1 set for that ctest run? The next paragraph shows why I ask.

With LEONIDA_VK_VALIDATION=1

d3d12_mesh_test fails in 3 of 3 runs, with 3 VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 messages in each run. This confirms point 2 of the report from @XFlawless1 on a third NVIDIA GPU. I do not repeat the analysis.

AMD

My AMD Radeon(TM) Graphics (integrated, driver 32.0.21043.5001) has no VK_EXT_mesh_shader. The test stops with exit code 77 (only the refusal without it was checked). Thus I can not confirm or contradict the line 474 result on AMD.

Base

main (3faac557) has no d3d12_mesh_test target on this computer (the test comes with #1712). Thus I have no run of this test on main.

@oVolkra

oVolkra commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested c3569af (merged onto main 3faac55) on RTX 3060, driver 617.14, Windows 11: one new failure, d3d12_mesh (a test this PR adds). It fails only with validation on (LEONIDA_VK_VALIDATION=1) and passes without it. No other new failures vs main in ctest, the validation ctest run or the GPU tests (native and LEONIDA_W64_EMULATE=1).

With validation, the test fails on both ctest attempts with 3 validation errors: vkCmdDrawMeshTasksEXT() is recorded while a pipeline statistics query is active whose pipelineStatistics includes INPUT_ASSEMBLY_VERTICES / INPUT_ASSEMBLY_PRIMITIVES (the spec forbids these on active queries for mesh draws).

AI-assisted: the test run and this comment were prepared with Claude Code; the numbers above are its unedited output.

LloydNicholson and others added 3 commits November 23, 2026 13:41
…h (D3D-29)

The device enables VK_EXT_mesh_shader (meshShader) where the GPU has it
and reports MeshShaderTier 1 only then.

ID3D12Device2::CreatePipelineState parses pipeline state streams in the
d3dx12.h layout into the descriptions the existing PSO creators take, with
the runtime's defaults for missing subobjects. Streams the PC runtime
refuses are E_INVALIDARG; AS, depth bounds, split stencil masks and view
instancing are E_NOTIMPL with a log.

A mesh PSO is MS + PS with no vertex input or input assembly, and no
dynamic topology or strides. Its output sizes and workgroup are checked
against VkPhysicalDeviceMeshShaderPropertiesEXT.

DispatchMesh records a Draw with mesh set and replays as
vkCmdDrawMeshTasksEXT; a draw of the wrong kind for its pipeline fails
with ReplayResult::invalid_draw.

d3d12_mesh_test covers the refusals and checks a 2x2x1 and a 1x1x2 mesh
grid plus a VS PSO from a stream, pixel by pixel.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ates; mesh test skips without Vulkan

The stream parser keyed its duplicate check on the raw subobject type, so DEPTH_STENCIL with DEPTH_STENCIL1
(either order) or RASTERIZER with RASTERIZER2 was accepted; D3D12_PIPELINE_STATE_STREAM_DESC counts versions of
one subobject as the same one. The check now uses the base type, while the payload still follows the original
type. d3d12_mesh_test covers both mixed orders, RASTERIZER + RASTERIZER2, and each description alone.
Reported by Vonsek in review.

d3d12_mesh_test failed on a machine without a Vulkan device (the Windows CI runner) instead of exiting 77; it
now skips there like d3d12_draw_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
D3D12 allows DispatchMesh inside a PIPELINE_STATISTICS query and reads its input-assembly, vertex, geometry and
tessellation fields as 0; Vulkan forbids vkCmdDrawMeshTasksEXT while a query with those counters is active
(VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076), and the heap's pool has all eleven.

A statistics query that holds a mesh draw is now split like one that holds a resolve (D3D-162). Each segment's
first draw picks the submission's full pool or a second one with only the clipping, fragment and compute counters,
and a draw of the other kind starts a new segment. The statistics sum copies a mesh segment's four counters into
fields 5..8 of its record and statistics_sum.comp adds them to their D3D12 fields. A list that would need the split
without the compute helper is refused instead of running the query unsplit.

replay_query_predication_test checks the split points, segment kinds and resolve plan on the CPU; d3d12_mesh_test
resolves queries around mixed, mesh-only and vertex-only draws on the GPU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thehollowedone

Copy link
Copy Markdown

Native Windows recheck of 9d13a657 on 561b65a8. Windows 11, RTX 3080 Ti / 621.35, MSVC 19.44.35230, Vulkan SDK 1.4.363.0.

The earlier validation failure still occurs on this head. The focused mesh test matched all 4,096 pixels and passed the mixed, mesh-only and vertex-only counter assertions. With core and synchronization validation enabled, it failed with three VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 messages. All three identify the clipping invocation and primitive bits on the active mesh query pool. Those bits are still present in the mesh pool mask and are disallowed for active mesh draw queries by the Vulkan spec.

The scratch fixture ran the published valid draws and query cases with the exact PR runtime and shaders. Synthetic only. AI-assisted.

@sh1shu1

sh1shu1 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 9d13a65 on NVIDIA RTX 4070 SUPER (driver 616.92), Windows 11 26200, MSVC 14.44, Vulkan SDK 1.4.363, RelWithDebInfo: fail.

  • ctest: 243/248 passed; fails here, passes on main 561b65a: d3d12_mesh; d3d12_indirect_dispatch_count, d3d12_indirect_rt, dxgi_device, dxgi_swapchain fails on main 561b65a too (not from this PR), same 11 skips as main 561b65a
  • d3d12_mesh, replay_query_edges, replay_query_predication: 2/3
  • run_gpu_tests (LEONIDA_VK_VALIDATION=1): 183/232 native, 214/232 with LEONIDA_W64_EMULATE=1, 2 failed; ms_wave_info_s3 fails on main 561b65a too
    AI-assisted (Claude Code, Claude Fable 5.1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.