Skip to content

D3D12 layer: stream-output statistics query heaps (D3D-302) - #2562

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
justr4mzi:d3d-302-so-mesh-queries
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
justr4mzi:d3d-302-so-mesh-queries

Conversation

@justr4mzi

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-302 (#2300)

What and why

CreateQueryHeap(D3D12_QUERY_HEAP_TYPE_SO_STATISTICS) returned E_NOTIMPL (docs/d3d12_vulkan.md §4.6), so a title that makes one got nothing back. The layer has no stream output: a graphics PSO with StreamOutput entries is refused (d3d12_vulkan_device.cpp, the HS/DS/GS/SO check; #2109 keeps SO refused too) and SOSetTargets is not implemented. So no primitive ever reaches a stream, and every SO_STATISTICS_STREAM0..3 query is exactly {NumPrimitivesWritten 0, PrimitivesStorageNeeded 0}.

This PR makes such a heap without a VkQueryPool:

  • QueryHeap::create: SO_STATISTICS registers a QueryPool whose pool is null; the destructor removes any registered heap, and destroys the pool only when there is one.
  • query_result_size: 16 bytes for the four stream types (D3D12_QUERY_DATA_SO_STATISTICS, static_assert in the test); new is_so_statistics().
  • prepare: stream queries get their own branch, so they are not counted as a pipeline-statistics query (several streams can run at once, inside a statistics query and across an occlusion one).
  • plan_statistics_segments: an SO resolve does not split a running statistics query (it only fills zeros, nothing is dispatched).
  • emit_query: Begin/EndQuery on a pool-less heap record nothing; the resolve already took the zero-fill path (run.pool null -> vkCmdFillBuffer).
  • D3D12's call rules (begun and ended in the same list, heap/type pairing, ranges, offsets) are unchanged and still apply.

When stream output lands, the heap becomes a VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT pool with vkCmdBeginQueryIndexedEXT; Vulkan's two results are in the same order as D3D12's. Written in §4.6.

Not in this PR: the mesh/amplification counts of PIPELINE_STATISTICS1, which D3D-302 also lists. That is D3D-132 (@itsRevela, blocked by #1712), so I left it alone to avoid a duplicate.

Tested

  • Cross-built with clang-cl 19 + lld-link against an xwin splat (MSVC 14.44, Windows SDK 10.0.26100, runtime/cmake/clang-cl-xwin.cmake), run under Wine 9.0 on Linux with Mesa lavapipe (llvmpipe, LLVM 20.1.2). Not on real hardware: a GPU check (any vendor) would be welcome.
  • d3d12_vulkan_device_test: the SO heap is created; streams 0 and 3 run at once inside the statistics query and across the occlusion query; three queries resolved (one never begun) read 48 zero bytes over the 0xcd fill and nothing past them; an SO query in an occlusion heap is invalid_query; one begun and never ended is refused at Close. Pass. Negative control: expecting 1 instead of 0 fails at the new line.
  • command_list_test (query_result_size of stream 0 is now 16), predicated_copy_test, replay_copy_offset_test, replay_query_predication_test, replay_uav_clear_offset_test, vk_command_replay_test, clear_color_test, d3d12_state_map_test, replay_clear_gate_test, replay_readback_stages_test, replay_write_immediate_predication_test, typeless_rtv_test: all pass, same setup.
  • Not run: vk_binary_occlusion / vk_overlapping_occlusion (not configured in this build).

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

@duudiis

duudiis commented Nov 22, 2026

Copy link
Copy Markdown

Independent physical-GPU run at 70c9517 on Windows 11 / RTX 5070 (driver 621.24, MSVC 19.44, Windows SDK 10.0.26100). d3d12_vulkan_device, command_list, vk_binary_occlusion and vk_overlapping_occlusion all passed through CTest. I also ran the standalone vk_command_replay_test.exe successfully.

I additionally extended the overlapping-occlusion test locally to exercise the no-split rule: start all four pool-less SO streams, then end and resolve each while a pipeline-statistics query is still active. With both a nonzero buffer binding offset and a nonzero resolve offset, the 64 result bytes were zero and all guard bytes stayed at 0xcd. No extra VkQueryPool end was recorded, and the active query included its scheduled draw. The existing comparison of all 11 pipeline-statistics counters against the split-query run passed (6 IA vertices total across the two reference draws, 0 CS invocations).

@aguedou-34

Copy link
Copy Markdown

Tested 70c9517c6ad1a68e8f5209eaae5ebc746d4c2484 on Windows 11 with Vulkan validation enabled.

  • RTX 3070 Laptop, driver 591.59: 7/7 targeted CTests passed, including vk_binary_occlusion and vk_overlapping_occlusion.
  • Ryzen 7 5800H Radeon iGPU, driver 31.0.21921.1000: the focused SO test passed. The full selection was 6/7 on both the PR and the base, with the same sRGB clear mismatch against WARP.
  • On both GPUs, a test-only probe resolved SO statistics while a pipeline-statistics query was active. All 48 result bytes were zero, the guard stayed intact, and Vulkan validation reported no errors. The same probe on base 49475796c226c8511b9470bf97a4daf57b8af323 returned E_NOTIMPL at SO heap creation. The original test was restored.

Synthetic inputs only. Tested with assistance from OpenAI Codex.

@KiryaAfimin

Copy link
Copy Markdown

Tested 70c9517 on Windows 11 with a GeForce RTX 4070 (driver 621.01) and Vulkan validation enabled.

d3d12_vulkan_device passed. The three stream-output statistics queries resolved to 48 zero bytes, including the query that was never begun. The next 8 bytes retained the 0xcd fill.

vk_binary_occlusion and vk_overlapping_occlusion also passed on the 4070 with validation enabled. All 15 checks I ran passed, with no Vulkan validation errors reported.

@umnitus

umnitus commented Nov 22, 2026

Copy link
Copy Markdown

Independent Windows GPU check: PASS on RTX 3060 12 GB (driver 621.14, Vulkan 1.4.357, Windows 11 26H2, Ryzen 5 3600).

Head: 70c9517
Built the Release d3d12_vulkan_device_test target with CMake/Ninja and ran d3d12_vulkan_device_test.exe. The full executable exited 0.

The D3D-302 checks passed for streams 0 and 3. All three query slots, including the unused slot, read back as zero. The destination sentinel was preserved, and the mismatched heap/query type and unterminated query were rejected as expected.

AI-assisted test execution and write-up.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (MSVC 14.51, llvm-mc 23.1.6): pass. ctest: 124/124 on the RTX 4080 SUPER. On the Intel UHD 770 only the known d3d12_descriptor (min-LOD) and d3d12_subgroup (fragment probe) fail (#2716).

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 70c9517 on Windows 11 (26200), MSVC 19.4x (VS 2022 Build Tools), Ninja RelWithDebInfo: pass on both GPUs of a two-GPU PC.

  • NVIDIA GeForce RTX 5080, driver 616.92 (LEONIDA_VK_DEVICE=nvidia): ctest 108/108 passed.
  • AMD Radeon RDNA2 iGPU, driver 32.0.21045.16010 (LEONIDA_VK_DEVICE=radeon, LEONIDA_HOST_ADAPTER=radeon): ctest 108/108 passed.

No game files. AI-assisted check (Claude Code), Vonsek3.

@ddm-j

ddm-j commented Nov 22, 2026

Copy link
Copy Markdown

Tested 70c9517 under Wine 11.21 (Fedora 45) on AMD Radeon 610M (RDNA2 iGPU, RADV Mesa 26.2.6) and NVIDIA RTX 4070 Ti (615.78.08): pass

This adds an AMD GPU and Linux to the Windows NVIDIA checks above. The Windows runtime was cross-built with clang-cl 23.1.5 and xwin (MSVC 14.44, SDK 10.0.26100), and its ctest suite was run under Wine and Xvfb, one GPU at a time with LEONIDA_VK_DEVICE.

  • d3d12_vulkan_device, command_list, vk_binary_occlusion and vk_overlapping_occlusion pass on both GPUs.
  • The new stream-output checks are plain assertions with no host comparison, so they run in full under Wine. They cover the pool-less heap, six zero words and the untouched word after them, and the two invalid-query cases.
Wine ctest main 4947579 this PR
RADV 106 passed, 16 skipped, 2 failed same
NVIDIA 106 passed, 16 skipped, 2 failed same

The two failures are the same on main, and both come from this environment:

  • device_proxy: Fedora's Wine provides no host D3D12 device.
  • d3d12_present: it times out on a real GPU under Xvfb.

AI-assisted (Claude Code); numbers copied from the run logs.

CreateQueryHeap(D3D12_QUERY_HEAP_TYPE_SO_STATISTICS) returned E_NOTIMPL, so
a title that makes one got nothing. The layer has no stream output (a PSO
with StreamOutput entries is refused, SOSetTargets is not implemented), so
every SO_STATISTICS_STREAM0..3 query counts 0 written and 0 needed.

Such a heap is now made without a VkQueryPool: Begin/EndQuery record nothing
in Vulkan (the D3D12 call rules and the ended tracking still apply), the
queries overlap no occlusion or statistics query, and ResolveQueryData fills
16 zero bytes per query (D3D12_QUERY_DATA_SO_STATISTICS) with no statistics
split. When stream output lands this becomes a
VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT pool.

Mesh-shader statistics (PIPELINE_STATISTICS1) are left to D3D-132.
@justr4mzi

Copy link
Copy Markdown
Contributor Author

Rebased on main (f847748) as cd472ec: the only conflicts were docs §4.6 and the overlap counting in prepare, where main now counts overlapping occlusion and statistics queries; the SO branch sits next to it unchanged. d3d12_vulkan_device_test, command_list_test and vk_command_replay_test pass again (clang-cl cross-build, Wine 9.0 + lavapipe). Thanks @duudiis, @aguedou-34, @KiryaAfimin, @umnitus, @kapitche, @Vonsek and @ddm-j for the GPU runs.

AI-assisted.

@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested cd472ec 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 "command_list|d3d12_vulkan_device" (the tests this PR changes): pass on both GPUs (2/2 each). No game files.

AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit ccd1906 into ItsNotRexed:main Nov 23, 2026
3 of 10 checks passed
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.

9 participants