diff options
| author | traeb0n <masonbartelme@gmail.com> | 2026-11-21 16:17:23 -0600 |
|---|---|---|
| committer | traeb0n <masonbartelme@gmail.com> | 2026-11-21 21:30:47 -0600 |
| commit | 70791081828e75f82811baefc07912fc58f764ff (patch) | |
| tree | 0dd0f263e5d0406b2b517780e2179b83b642b866 /runtime/test/command_list_test.cpp | |
| parent | dedd75c1d1db4e042f559f0dd39e872313457bf4 (diff) | |
Runtime: query heaps on Vulkan (D3D-15)
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>
Diffstat (limited to 'runtime/test/command_list_test.cpp')
| -rw-r--r-- | runtime/test/command_list_test.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/runtime/test/command_list_test.cpp b/runtime/test/command_list_test.cpp index 49b7e27a8..d918cd67c 100644 --- a/runtime/test/command_list_test.cpp +++ b/runtime/test/command_list_test.cpp | |||
| @@ -229,5 +229,50 @@ int main() { | |||
| 229 | CHECK(std::get<Predication>(predicated.commands()[1]).offset == 16); | 229 | CHECK(std::get<Predication>(predicated.commands()[1]).offset == 16); |
| 230 | const auto& off = std::get<Predication>(predicated.commands()[2]); | 230 | const auto& off = std::get<Predication>(predicated.commands()[2]); |
| 231 | CHECK(off.buffer == 0 && off.offset == 0 && off.op == 0); | 231 | CHECK(off.buffer == 0 && off.offset == 0 && off.op == 0); |
| 232 | // Queries: timestamps only end; other queries are begun and ended in one list, with the same type, and are not | ||
| 233 | // begun twice or resolved while running. Resolve offsets are multiples of 8; a resolve of nothing records nothing. | ||
| 234 | namespace q = d3d12_query; | ||
| 235 | namespace h = d3d12_query_heap; | ||
| 236 | CHECK(list.reset()); | ||
| 237 | constexpr QueryHeapId heap = 70, other = 71; | ||
| 238 | CHECK(!list.begin_query({0, q::occlusion, 0})); | ||
| 239 | CHECK(!list.begin_query({heap, q::timestamp, 0})); | ||
| 240 | CHECK(list.end_query({heap, q::timestamp, 3})); | ||
| 241 | CHECK(list.end_query({heap, q::timestamp, 3})); // a timestamp can be written again | ||
| 242 | CHECK(!list.end_query({heap, q::occlusion, 1})); // never begun | ||
| 243 | CHECK(list.begin_query({heap, q::occlusion, 1})); | ||
| 244 | CHECK(!list.begin_query({heap, q::binary_occlusion, 1})); // already running | ||
| 245 | CHECK(list.begin_query({other, q::occlusion, 1})); // same index, another heap | ||
| 246 | CHECK(!list.end_query({heap, q::binary_occlusion, 1})); // begun with another type | ||
| 247 | CHECK(!list.resolve_queries({heap, q::occlusion, 0, 2, 9, 0})); // query 1 is running | ||
| 248 | CHECK(list.resolve_queries({heap, q::occlusion, 2, 2, 9, 0})); | ||
| 249 | CHECK(list.queries_open()); | ||
| 250 | CHECK(list.end_query({heap, q::occlusion, 1})); | ||
| 251 | CHECK(list.end_query({other, q::occlusion, 1})); | ||
| 252 | CHECK(!list.queries_open()); | ||
| 253 | CHECK(!list.resolve_queries({heap, q::occlusion, 0, 2, 9, 4})); // offset not a multiple of 8 | ||
| 254 | CHECK(!list.resolve_queries({heap, q::occlusion, 0, 2, 0, 8})); // no destination | ||
| 255 | CHECK(!list.resolve_queries({heap, q::occlusion, 0xffffffff, 2, 9, 8})); // range wraps | ||
| 256 | CHECK(list.resolve_queries({heap, q::occlusion, 0, 2, 9, 16})); | ||
| 257 | CHECK(list.resolve_queries({heap, q::occlusion, 0, 0, 9, 16})); // nothing to resolve | ||
| 258 | CHECK(list.close()); | ||
| 259 | CHECK(list.commands().size() == 8); | ||
| 260 | CHECK(std::get<EndQuery>(list.commands()[0]).index == 3 && std::get<EndQuery>(list.commands()[0]).type == q::timestamp); | ||
| 261 | CHECK(std::get<BeginQuery>(list.commands()[2]).heap == heap && std::get<BeginQuery>(list.commands()[3]).heap == other); | ||
| 262 | const auto& query_resolve = std::get<ResolveQueries>(list.commands()[7]); | ||
| 263 | CHECK(query_resolve.first == 0 && query_resolve.count == 2 && query_resolve.dst == 9 && query_resolve.offset == 16); | ||
| 264 | |||
| 265 | // A query still running at Close leaves the list closed and marked; Reset clears it. | ||
| 266 | CHECK(list.reset()); | ||
| 267 | CHECK(list.begin_query({heap, q::pipeline_statistics, 0})); | ||
| 268 | CHECK(list.close() && list.queries_open()); | ||
| 269 | CHECK(list.reset() && !list.queries_open()); | ||
| 270 | CHECK(list.begin_query({heap, q::pipeline_statistics, 0})); // free again after the reset | ||
| 271 | |||
| 272 | CHECK(query_fits_heap(h::occlusion, q::binary_occlusion) && !query_fits_heap(h::occlusion, q::timestamp)); | ||
| 273 | CHECK(query_fits_heap(h::copy_queue_timestamp, q::timestamp) && !query_fits_heap(h::timestamp, q::occlusion)); | ||
| 274 | CHECK(query_fits_heap(h::so_statistics, q::so_statistics_stream3) && !query_fits_heap(6, q::occlusion)); | ||
| 275 | CHECK(query_result_size(q::occlusion) == 8 && query_result_size(q::timestamp) == 8); | ||
| 276 | CHECK(query_result_size(q::pipeline_statistics) == 88 && query_result_size(q::so_statistics_stream0) == 0); | ||
| 232 | return 0; | 277 | return 0; |
| 233 | } | 278 | } |