Repository navigation
Runtime: query heaps on Vulkan: occlusion, timestamps, pipeline statistics (D3D-15) - #278
Conversation
400adde to
6af02e6
Compare
|
Tested 6af02e6 on RTX 3060 Ti (Ampere), NVIDIA 621.24, Windows 11, MSVC 14.44, Vulkan SDK 1.4.363.1: pass.
AI-assisted (Claude Code). |
|
Tested 6af02e6 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass
The first run had No game files used. AI-assisted run (Claude Code). |
|
Thanks @NWX10 and @kotorvr for testing. Rebased onto |
6af02e6 to
5aad6c7
Compare
|
Tested 5aad6c7 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass
This re-tests the new head. My earlier pass was on 6af02e6. No game files used. AI-assisted run (Claude Code). |
|
Tested: PR head 5aad6c7 merged onto main 4abd545, ctest 19/19. |
|
Tested
No game files involved. AI-assisted (Claude Code). |
0b8520f to
7079108
Compare
CreateQueryHeap makes one VkQueryPool per heap: occlusion (OCCLUSION and BINARY_OCCLUSION queries), timestamp and copy-queue timestamp, and pipeline statistics (all eleven Vulkan counters, whose order is the field order of D3D12_QUERY_DATA_PIPELINE_STATISTICS). Other heap types are logged and refused with E_NOTIMPL. BeginQuery, EndQuery and ResolveQueryData are recorded in the command-list IR with D3D12's rules for the calls, and replayed as vkCmdResetQueryPool + vkCmdBeginQuery/vkCmdEndQuery, vkCmdWriteTimestamp at BOTTOM_OF_PIPE and vkCmdCopyQueryPoolResults (64-bit, WAIT). Heap types, index ranges and the destination buffer are checked before anything is written. A query that was never ended resolves to zeros instead of stalling the GPU on WAIT_BIT. GetTimestampFrequency is 1e9 / timestampPeriod. The devices enable occlusionQueryPrecise and pipelineStatisticsQuery where the GPU has them. Overlapping queries of one kind (valid D3D12, one active query per type in Vulkan) are refused as unsupported, and binary occlusion is not clamped to 0/1 yet; both are written down in docs/d3d12_vulkan.md section 4.6. Tested on an RTX 5070 (driver 621.01) under VK_LAYER_KHRONOS_validation. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Rebased onto Retested on the RTX 5070 (621.01), Windows 11, MSVC 14.44, Vulkan SDK 1.4.363: AI-assisted (Claude Code). |
…icked values A reused or lower fence value makes SetEventOnCompletion return at once, so a block read results the GPU had not written yet (ProjectLeonida#278 hit this twice after rebases). Every wait on the main fence now goes through submit_and_wait, which signals the next value and waits for it, including the query blocks that landed with 10 and 11. Fences that belong to one block (ms_fence, the standalone device's) keep their own values.
…icked values A reused or lower fence value makes SetEventOnCompletion return at once, so a block read results the GPU had not written yet (#278 hit this twice after rebases). Every wait on the main fence now goes through submit_and_wait, which signals the next value and waits for it, including the query blocks that landed with 10 and 11. Fences that belong to one block (ms_fence, the standalone device's) keep their own values.
Claimed in #156 as: D3D-15
What and why
Query heaps were planned in
docs/d3d12_vulkan.md§4.6 but not implemented anywhere, soCreateQueryHeap,BeginQuery/EndQuery/ResolveQueryDataandGetTimestampFrequencywere logging stubs. This adds them on the Vulkan device:Heaps (
QueryHeapinruntime/shims/d3d12_vulkan_device.cpp): oneVkQueryPoolperID3D12QueryHeap, registered with theVulkanContextby its pointer value, like resources.OCCLUSIONheaps hold bothOCCLUSIONandBINARY_OCCLUSIONqueries.TIMESTAMPandCOPY_QUEUE_TIMESTAMPheaps are refused if the queue family hastimestampValidBits == 0.PIPELINE_STATISTICSheaps count all eleven Vulkan counters (0x7ff). Their result order matches the field order ofD3D12_QUERY_DATA_PIPELINE_STATISTICS, so each 88-byte result is copied unchanged.SO_STATISTICS,VIDEO_DECODE_STATISTICSandPIPELINE_STATISTICS1are logged and returnE_NOTIMPL.IR (
runtime/src/command_list.h): newBeginQuery,EndQueryandResolveQueriescommands. Recording enforces D3D12's rules:EndQuery;A list closed with a query still running returns
E_INVALIDARGand is refused at execution.Replay (
runtime/src/vulkan_replay.h):preparechecks heap/type pairing, index ranges and the destination buffer bounds (ReplayResult::invalid_query) before anything is written.emitproduces:BeginQuery:vkCmdResetQueryPoolof that one query, thenvkCmdBeginQuery(withPRECISEforOCCLUSIONwhen available).EndQuery: reset, thenvkCmdWriteTimestampatBOTTOM_OF_PIPE.ResolveQueryData:vkCmdCopyQueryPoolResultswith64_BIT | WAIT.vkCmdFillBuffer) instead of lettingWAIT_BITstall the GPU forever.Queue:
GetTimestampFrequency=1e9 / timestampPeriod.Both device paths (caller-owned through
VulkanDeviceInfo, and standalone) enableocclusionQueryPreciseandpipelineStatisticsQuerywhen the GPU has them.Known gaps (written down in §4.6):
VUID-vkCmdBeginQuery-queryPool-01922; the validation layer caught this). D3D12 allows overlapping occlusion queries. A list that overlaps two occlusion queries (either kind) or two pipeline-statistics queries is refused asunsupportedinstead of emitting invalid Vulkan. The full fix is virtual queries that split and sum on resolve; the trace will show whether the game needs it.GetClockCalibrationisn't implemented.Overlaps: #258 (D3D-18 predication) adds to the same
Commandvariant and the sameprepare/emitdispatch; the conflict is additive. Rebased over #228'sResolveSubresource, which now sits beside the query commands.Tested
RTX 5070, NVIDIA driver 621.01, Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, rebased on
83d0637:d3d12_vulkan_device_testwithLEONIDA_VK_VALIDATION=1: passes, 0 validation errors (also passes without validation). New coverage:S_FALSEfor a null output,GetDevicereturning the proxy;GetTimestampFrequency(1 GHz here);0xcdfill at three offsets and checked for zeros (no draws exist yet);Closeresult andReplayResult.command_list_test: CPU-only pairing and alignment rules.d3d12_state_map_test: every new query enum is static-asserted against the SDK'sd3d12.h(10.0.26100), plus the 88-byte statistics struct.d3d12_com_testandvk_command_replay_test(both share the edited headers) pass under validation.ctest -E loader: 12/12 pass.python -m compileall -q make_game.py tools tests: ok.main:loader_testran for about 10 minutes, then exited with0xc0000409on this machine. It builds only frompe_loader.cppandregistry.cpp, which this PR doesn't touch. I can open an issue if it reproduces for others.AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator change.)🤖 Generated with Claude Code