Repository navigation
Runtime: pipeline-statistics queries around mesh draws (D3D-291) - #2359
LloydNicholson wants to merge 3 commits into
Conversation
07f7530 to
ec3e628
Compare
|
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),
VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 forbids |
|
Windows + GPU check: AMD Radeon RX 9070 (RDNA4), Windows 11, MSVC Release, Vulkan SDK 1.4.363. Tested head ec3e628 merged onto AI-assisted (Claude Code); runs on my machine. |
|
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 Confirmed TricksterG's finding:
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 Locally tested minimal fix (not pushed):
Results after this change:
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). |
|
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. |
|
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. AI-assisted (Claude Code, reviewed with Codex). No game files. |
ec3e628 to
46f7314
Compare
|
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
AI-assisted (Claude). |
46f7314 to
940ab5d
Compare
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).
|
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:
AI-assisted (Claude Code). |
940ab5d to
c3569af
Compare
|
Tested c3569af on RTX 5070, driver 616.86, Windows 10.0.26200: pass. Built
|
|
Tested c3569af on NVIDIA RTX 4070 SUPER (driver 616.92), Windows 11 26200, MSVC 14.44, Vulkan SDK 1.4.363, RelWithDebInfo: fail.
|
|
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 I did not check whether main passes on the Radeon. No game files. AI-assisted. |
|
Tested 1. Radeon,
|
| 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:
- Count them from a
VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXTquery around mesh segments. Runtime: PIPELINE_STATISTICS1 query heaps with mesh counts (D3D-132) #2870 already adds that pool for MSPrimitives, @itsRevela. That would be the natural place, and it also changes Runtime: PIPELINE_STATISTICS1 query heaps with mesh counts (D3D-132) #2870's note that Runtime: pipeline-statistics queries around mesh draws (D3D-291) #2359 fixes VUID-07076. - Report 0 for mesh segments' clipping counters, and document that as a known difference.
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).
|
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 |
|
Tested Without validation
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 With
AMD My AMD Radeon(TM) Graphics (integrated, driver 32.0.21043.5001) has no Base
|
|
Tested c3569af (merged onto main 3faac55) on RTX 3060, driver 617.14, Windows 11: one new failure, With validation, the test fails on both ctest attempts with 3 validation errors: AI-assisted: the test run and this comment were prepared with Claude Code; the numbers above are its unedited output. |
…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>
c3569af to
9d13a65
Compare
|
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 The scratch fixture ran the published valid draws and query cases with the exact PR runtime and shaders. Synthetic only. AI-assisted. |
|
Tested 9d13a65 on NVIDIA RTX 4070 SUPER (driver 616.92), Windows 11 26200, MSVC 14.44, Vulkan SDK 1.4.363, RelWithDebInfo: fail.
|
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, onmainf847748.What and why
The problem. D3D12 allows
DispatchMeshinside aPIPELINE_STATISTICSquery and reads its IA/VS/GS/HS/DS fields as 0. Vulkan forbidsvkCmdDrawMeshTasksEXTwhile 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:
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.CLIPPING_INVOCATIONS,CLIPPING_PRIMITIVES,FRAGMENT_SHADER_INVOCATIONSandCOMPUTE_SHADER_INVOCATIONS.ExecuteIndirectdraws count as vertex draws.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, andemit_query's, now pick the pool by the segment's kind, since a helper or resolve can end a mesh segment.statistics_sum.compgains ameshpush constant and adds them asCInvocations,CPrimitives,PSInvocationsandCSInvocations, so the other fields get nothing from that segment.statistics_sum_spirv.his regenerated as its header says:glslangValidator -V --target-env vulkan1.0 -Os -g0, thenspirv-val.unsupportedrather than run unsplit around a mesh draw.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
mainf847748:mainadded 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 onmain) now callssum_statisticswith 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_testcases 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).d3d12_mesh_test(GPU, extended): three queries in one list, on a mixed, a mesh-only and a vertex-only range.PSInvocationsisn't the pixel count, so the test compares against the vertex-only query rather than an absolute number.VK_LAYER_KHRONOS_validation1.4.341 (Fedora) reports nothing beyond the two VUIDs that come from this host's environment.vk_overlapping_occlusion,vk_binary_occlusion,vk_predicated_copy,depth24_convertandreplay_query_predicationpass natively under validation, with no messages.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 onmainf847748 on this machine (d3d12_clear,d3d12_compute,d3d12_fence_timing,d3d12_private_data,d3d12_subresource_copy,d3d12_xdxr_rt).tests/test_docs_links.pyandtests/test_text_write_line_endings.pypass.Not tested: Windows/MSVC with Microsoft's loader and a current validation layer; NVIDIA or Intel;
ExecuteIndirectmesh draws, which the layer doesn't have yet.Checklist
🤖 Generated with Claude Code