d3d12: real SO_STATISTICS query pools (D3D-302) #1630
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1630
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1630/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@BubsMcgee on GitHub · 2026-11-25 06:21 UTC · original
BubsMcgee:stream-output→main· +231 −34 · 7 files · 5 commits · merged 2026-11-25 22:37 UTCClaimed in the coordination issue as: D3D-302 (claim: #1608)
Depends on: #1891
Lands only the real
SO_STATISTICSquery-pool part, on its own (the option aslan2142 offered). StreamOutput PSOs are still refused andSOSetTargetsis still not implemented; the capture path is not part of this PR.The device detect/enable and the
vk_pipeline_checkparity fix now live in #1891 (which adopts #1236). This PR is stacked on it and contains only the query pools:VK_EXT_transform_feedbackenabled (by #1891), anSO_STATISTICSheap is a realVK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXTpool, begun and ended indexed on the stream (vkCmdBeginQueryIndexedEXT/vkCmdEndQueryIndexedEXT).ResolveQueryDatacopies the two 64-bit results (NumPrimitivesWritten,PrimitivesStorageNeeded), 16 bytes per query, in the same order.VkQueryPooland resolves zeros, as before.When #1891 merges I will rebase this onto
main; the two foundation commits drop and only the query changes remain.The remaining
pipeline_cache_seedfailure on AMD is neither this PR nor #1891: adrianmjim rechecked on an RX 7900 XT and it fails identically on the basemainwithout either, from #1723'srobustBufferAccesschange. That is #1833, where I flagged a checker-vs-runtimebindlessinput mismatch (the checker's OR of update-after-bind flags vs the runtime's six-feature AND) to correct before relying on it.Tested on
main71a769d7d(Windows 11 Pro 26300, MSVC RelWithDebInfo, NVIDIA RTX 3080 Ti, driver 616.64, Vulkan SDK 1.4.363.0):d3d12_vulkan_device,d3d12_meshandpipeline_cache_seedpass, plain and withLEONIDA_VK_VALIDATION=1. AI-assisted.@adrianmjim on GitHub · 2026-11-25 07:54 UTC · original
Reviewed
cd65952f4applied ontomain42537e7b6, and ran it on an AMD Radeon RX 7900 XT. The AMD driver exposes the whole extension (transformFeedback,geometryStreams,transformFeedbackQueries,transformFeedbackRasterizationStreamSelect, 4 streams), so the new paths are live there.A regression on AMD:
pipeline_cache_seedfailsWith this PR,
ctest -R ^pipeline_cache_seed$fails 3 of 3 on the 7900 XT. It passes 3 of 3 onmainwith the same build setup:The runtime's device now enables
VK_EXT_transform_feedback, butruntime/test/vk_pipeline_check.cppdoes not, and AMD's driver makes that part of a pipeline's cache key. So the cachevk_pipeline_checkseeds offline no longer hits ingta6rt, and every pipeline is compiled again at run time. That is the same mismatch the tool already guards against for mesh shaders and maintenance8. I checked it with a two-line local change: linking aVkPhysicalDeviceTransformFeedbackFeaturesEXTwith the extension invk_pipeline_check's feature chain, next to the mesh-shader one. With that, the test passes 3 of 3 again. NVIDIA evidently leaves it out of the key, which is why it didn't show up on the 3080 Ti. The header comment ofvk_pipeline_check.cppanddocs/pipeline_check.md("The cache and the runtime's device") list the always-enabled extensions and would need the new one too.Problems in the capture path
None of these shows up in the tests, because no test binds a StreamOutput PSO.
1. The rasterization-stream struct has no
sType.VkPipelineRasterizationStateStreamCreateInfoEXT rasterization_stream{};leavessTypeat 0, which isVK_STRUCTURE_TYPE_APPLICATION_INFO. That is the case both in the PSO constructor and in the recipe member's default, andbuild()copies the recipe's value. For a StreamOutput PSO withRasterizedStream != 0(only accepted when geometryStreams is enabled),build()chains this struct intoraster.pNext, so the driver ignores or misreads it and the validation layers report it. It needs{VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_STREAM_CREATE_INFO_EXT}.2. Nothing makes the translated shaders capture anything. The README, the docs and the new comment in the PSO constructor say capture is driven by
XfbBuffer/XfbStride/XfbOffsetdecorations in the translated SPIR-V. But nothing emits them:tools/rdna2spirv.pynever writes anXfb*decoration or theXfbexecution mode, and the runtime's SPIR-V patching only touchesLocation. That is true onmainand with this PR. So whenever a StreamOutput pipeline draws with at least one SO target bound,vkCmdBeginTransformFeedbackEXTruns with a last pre-rasterization stage that does not declareXfb, which violates VUID-vkCmdBeginTransformFeedbackEXT-None-04128. In practice nothing is captured, yet the PSO is accepted as if it could be. TheD3D12_SO_DECLARATION_ENTRYlist is validated (and hashed into the PSO cache key) but never reaches the shaders or the capture setup.3. Capture buffers lack the transform-feedback usage bit. No buffer is created with
VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT. SO targets are resolved from their VAs like vertex buffers, so they land in the layer's ordinary buffers, and none of their usage lists has that bit (line numbers are inruntime/shims/d3d12_vulkan_device.cpponmain):create_arena, 10151)Binding them with
vkCmdBindTransformFeedbackBuffersEXTviolates VUID-vkCmdBindTransformFeedbackBuffersEXT-pBuffers-02360.4. Unbound lower slots are bound as
VK_NULL_HANDLE.begin_stream_outputsetscountto the highest bound slot + 1 and passesd.stream_output.data()for slots 0..count-1 in onevkCmdBindTransformFeedbackBuffersEXTcall. With slot 0 unbound and slot 1 bound (SOSetTargetswithStartSlot = 1, which D3D12 allows), slot 0 is still theVK_NULL_HANDLEthatreset()left there. Transform-feedback binds have no null-buffer allowance: every one of thebindingCountentries must be a valid buffer. So this needs one bind per contiguous run of bound slots. It also contradicts the comment onPreparedDraw::stream_output, which says only slots with a buffer are used.5. Each draw restarts the capture at byte 0.
vkCmdBeginTransformFeedbackEXT(..., nullptr, nullptr), and the matching End, use no counter buffers. D3D12 appends atBufferFilledSizeand writes it back after the draw. Here consecutive draws overwrite each other.BufferFilledSizeLocationis copied intofilled_size_vabut never used afterwards, so the count at that address is never read or written. The PR calls the write-back a follow-up, but the comment inprepare_draw("written after the draw") doesn't match the code yet. Using the filled-size VA as the counter buffer would be the direct mapping, and it also needsVK_BUFFER_USAGE_TRANSFORM_FEEDBACK_COUNTER_BUFFER_BIT_EXT.6. Smaller points:
RasterizedStream > 3returnsE_INVALIDARG. That also refusesD3D12_SO_NO_RASTERIZED_STREAM(0xFFFFFFFF), which is valid and common for stream-out-only passes; it maps to rasterizer discard.SemanticNameis refused. In D3D12 that is a gap entry, and itsComponentCountmay be more than 4.prepare_drawresolves the SO targets for every draw whenever the device has transform feedback, not only for StreamOutput pipelines. A stale SO target left bound makes every later ordinary draw in the list unresolvable (unresolved_at): by default each of those draws is dropped, and withLEONIDA_STRICT_REPLAY=1the whole list fails. The new test binds0x1000and draws nothing after it, so it does not hit this.SOSetTargetsin a bundle is deferred and replayed. D3D12 lists it among the calls not allowed in a bundle ("Recording command lists and bundles": the runtime drops the call). The neighbouringRSSetViewportsalready doescheck(false)there.prepare()neither refuses nor splits overlappingSO_STATISTICSqueries; it only rejects the same heap slot twice. Onmainthat was harmless, because no Vulkan query ran for them. Now they are realTRANSFORM_FEEDBACK_STREAM_EXTqueries, so two overlapping queries on the same stream (different slots or heaps) become two active indexed queries of the same type and index. Vulkan forbids that: VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753.Points 2 to 4 together mean a real StreamOutput draw is undefined behaviour on any driver, and can lose the device. Until the translator emits
Xfband the buffers carry the usage bit, it may be safer to keep refusing StreamOutput PSOs, and land the query part (SO_STATISTICSasTRANSFORM_FEEDBACK_STREAM_EXTpools) on its own.RX 7900 XT
d3d12_vulkan_device,d3d12_com,d3d12_query_rules,command_list,d3d12_state_map,replay_query_edges,replay_query_predication,vk_queue_query_sync): 8 of 8 pass, plain and withLEONIDA_VK_VALIDATION=1(validation on, no messages). The SO block ofd3d12_vulkan_devicenow runs realTRANSFORM_FEEDBACK_STREAM_EXTqueries on streams 0 and 3 here, and the resolved counts are 0.ctest -j 6: 397 of 402 with this PR, against 399 of 402 onmain. The difference ispipeline_cache_seed(above) andd3d12_indirect_rt, which failed once under-j 6and passes 3 of 3 alone, on both trees. The other three failures are the same onmain:d3d12_texture_tiles(#964),d3d12_clear, andd3d12_geometry_views(an AMD-without-Resizable-BAR failure onmain, unrelated).AMD driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022, RelWithDebInfo. No game files.
@aslan2142 on GitHub · 2026-11-25 09:11 UTC · original
Thanks for this. It can't be merged yet, for these reasons:
D3D-302has noclaiming:line from you in #14 or #1608. Please post the claim there first.VK_EXT_transform_feedbackitself, in the same two files as #1236. Please rebase onto #1236 once it's merged, and drop the duplicated device setup.VkPipelineRasterizationStateStreamCreateInfoEXThas nosType.Xfbdecorations.VK_NULL_HANDLE.vkCmdBeginTransformFeedbackEXTruns without counter buffers.vk_pipeline_checkdoesn't enable the extension, sopipeline_cache_seedfails on AMD.SO_STATISTICSpool part on its own.AI-assisted (Claude Code, Claude Opus 5.5).
@potatoe0100 on GitHub · 2026-11-25 10:37 UTC · original
NVIDIA data point for the
pipeline_cache_seedquestion: testedac4a992edmerged ontomain57ba40bd6(clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14 (VK_EXT_transform_feedbackwith 4 streams), VS 2022 RelWithDebInfo + Ninja.ctest -j 6: 408 of 408 passed on bothmainand this PR (same skips).pipeline_cache_seed: passes 3 of 3 with this PR, so thevk_pipeline_checkchange in this head keeps the cache hitting on NVIDIA.d3d12_vulkan_devicewithLEONIDA_VK_VALIDATION=1: exit 0, 0 VUIDs.Nothing here draws through a StreamOutput PSO, so this doesn't cover the review points above.
AI-assisted testing (non-developer tester).
@whoalin1 on GitHub · 2026-11-25 11:26 UTC · original
Independent verification (native Windows; RTX 4070 SUPER + AMD gfx1036 iGPU,
LEONIDA_VK_VALIDATION=1): builds clean; CPU/mock tests 5/5; GPU tests (d3d12_com, d3d12_vulkan_device incl. the new SOSetTargets/SO_STATISTICS block, vk_queue_query_sync, pipeline_cache_seed) pass on both GPUs; full ctest NV 400/401 (sole failure d3d12_pipeline_library_host 0xc0000409 is pre-existing/environmental — identical crash signature on other branches).Confirming the outstanding reviews independently — every cited defect verified in the diff, plus additional findings the reviews may not have covered:
VkPipelineRasterizationStateStreamCreateInfoEXTis value-initialized{}with no sType at both sites (~7590, ~8169) — sType stays APPLICATION_INFO when chained into raster.pNext.begin_stream_outputbindsVK_NULL_HANDLEfor unbound lower slots (TF binds have no null allowance) — needs per-contiguous-run binds.BufferFilledSizeLocation/filled_size_vais stored but never read or written — consecutive draws overwrite; no counter buffers.cd65952f4duplicate open #1236 verbatim; merge-base is old (c7e82e26e).pipeline_cache_seedAMD regression mechanism confirmed: vk_pipeline_check.cpp does not enable VK_EXT_transform_feedback while the runtime now does.Recommend the same conclusion as the existing reviews: not mergeable as-is; needs the Xfb decoration emission + TF usage bits + counter/fill semantics before it can pass validation on a real SO draw. AI-assisted verification.
@adrianmjim on GitHub · 2026-11-25 12:48 UTC · original
Rechecked
b4e4787d8on the RX 7900 XT (driver 32.0.32029.2010, Windows 11 26300, VS 2022 RelWithDebInfo). Thanks for splitting it. The query-only scope and thevk_pipeline_checkchange both look right.d3d12_vulkan_device,d3d12_com,d3d12_query_rules,replay_query_edges,replay_query_predication,vk_queue_query_sync,command_list) pass withLEONIDA_VK_VALIDATION=1, with no VUIDs.pipeline_cache_seedstill fails, but not because of this PR. It fails the same way, 3 of 3, on this PR's basemained94fbef9without it. #1723 (ba626820e) made the runtime's device enablerobustBufferAccess, withVK_EXT_robustness2'srobustBufferAccess2andnullDescriptor, for bounded indexed indirect draws.vk_pipeline_checkstill forcesrobustBufferAccessoff, and AMD keys pipelines on it.nullDescriptoralone is not enough;robustBufferAccessis the one that matters.So your transform-feedback line in the checker is needed and correct; there is now a second mismatch from
main. I'll open a separate PR for that one, so it doesn't hold this up.Whole
ctest -j 6on this head: 435 of 438 pass or skip. The failures ared3d12_texture_tiles,d3d12_clearandpipeline_cache_seed, all three onmaintoo.@adrianmjim on GitHub · 2026-11-25 12:49 UTC · original
The other
pipeline_cache_seedmismatch, from #1723's robustness choices, is #1833. With both, the seed passes on the RX 7900 XT.@BubsMcgee on GitHub · 2026-11-25 13:03 UTC · original
Addressed the review points on this update:
claiming: D3D-302is now posted — #1608.392053470) is #1236's device detect/enable, unchanged; the duplicated device setup is gone. When #1236 merges I will rebase ontomainand drop that copy.SOSetTargets, and has no capture code, so thesType/ Xfb / null-slot / counter-buffer points are not in this diff. That work stays on a separate local branch for a future capture PR.vk_pipeline_checknow enables the extension. The remainingpipeline_cache_seedfailure on AMD is #1723'srobustBufferAccess, tracked as #1833, and is not caused by this PR (adrianmjim recheckedb4e4787d8on an RX 7900 XT).vk_pipeline_checkfix, then the query pools.d3d12_vulkan_device,d3d12_meshandpipeline_cache_seedpass onmain98c2f7777+ #1236, plain and withLEONIDA_VK_VALIDATION=1, on an RTX 3080 Ti (driver 616.64).AI-assisted.
@BubsMcgee on GitHub · 2026-11-25 14:40 UTC · original
Restructured on top of #1891, which adopts #1236 and carries the
vk_pipeline_checkparity fix. The device detect/enable and thevk_pipeline_checkchange are no longer duplicated here; this PR is now only theSO_STATISTICSquery pools, stacked on #1891. Once #1891 merges I rebase ontomainand the two foundation commits drop.Also: the remaining AMD
pipeline_cache_seedmismatch is #1833 (robustBufferAccess), where I flagged that the checker passes an OR of update-after-bind flags while the runtime passes the six-featureinfo.bindlessAND, so it can still choose a different robustness setting on some devices.AI-assisted.
@BubsMcgee on GitHub · 2026-11-25 16:05 UTC · original
Merge order for the TF cluster is now on #1891 (the #1608 thread is rejecting writes at 640 comments): #1891 . This PR is step 2: rebase onto main the moment #1891 lands, dropping the three foundation commits. Ready otherwise.
@aslan2142 on GitHub · 2026-11-25 17:30 UTC · original
Thanks for narrowing it, @BubsMcgee. The claim is accepted. Still open:
SO_STATISTICSqueries on the same stream become two active indexed queries (VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753).prepare()should refuse or split them, with a test.transformFeedbackQueries, and onmaxTransformFeedbackStreamsfor streams above 0.AI-assisted (Claude Code, Claude Opus 5.5).
@BubsMcgee on GitHub · 2026-11-25 19:12 UTC · original
Acknowledged the three remaining items: (1) refuse or split two overlapping SO_STATISTICS queries on the same stream (VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753) with a test, (2) gate the pool on ransformFeedbackQueries and on maxTransformFeedbackStreams for streams above 0, (3) a test that fails without the change. I will take them in that order, rerun d3d12_vulkan_device/d3d12_state_map plain and with LEONIDA_VK_VALIDATION=1, then rebase onto main after #1891 lands.
@BubsMcgee on GitHub · 2026-11-25 19:25 UTC · original
Took the three review points in
369bb1c75:prepare()now keeps the active SO queries by heap and stream and returnsReplayResult::invalid_queryfor a second Begin on a stream already active in that pool (VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753). Different streams still run together. A test that fails without this is case 18 inreplay_query_predication_test.SO_STATISTICSheap only createsVK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXTwhenVK_EXT_transform_feedbackis on and itstransformFeedbackQueriesproperty is set andmaxTransformFeedbackStreamsis nonzero. A stream at or abovemaxTransformFeedbackStreamsruns nothing and resolves zero (the indexed begin is not issued, so no invalidindex), same path as a heap with no pool.docs/d3d12_vulkan.md§4.6 and the GPU test's comment now say what is gated.Tested
d3d12_vulkan_device,d3d12_state_mapandreplay_query_predicationon an RTX 3080 Ti (driver 616.64), plain and withLEONIDA_VK_VALIDATION=1; all pass. Still stacked on #1891, to be rebased ontomainwhen it lands.AI-assisted (Claude, opencode).
@aslan2142 on GitHub · 2026-11-25 22:37 UTC · original
Merged, thanks! Your three points are in, plus one maintainer commit on top (
6af9c80a9):mainmerged into the branch (dd6d3fd8a), with no conflicts.main1bf5eeafd+844519ab5: it merges cleanly; the semantic suite passes (493 files, 6,318 tests, 0 files failed); the 15 docs and writer tests pass;check_no_game_data.pyis clean on the 7 changed files.AI-assisted (Claude Code, Claude Opus 5.5).