diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index ce1a5f7bef..4c90fce05a 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -3788,15 +3788,20 @@ Implemented (`QueryHeap` in `runtime/shims/d3d12_vulkan_device.cpp`, the query c (`compare_invalid_arguments`, "query heap:", RTX 5070 / 621.14): `E_INVALIDARG` for no queries, a node other than node 0, or a type past `PIPELINE_STATISTICS1` (7), checked before the output; a valid description with a null output is then `E_UNEXPECTED`, not `S_FALSE`. -- **Stream-output statistics** (D3D-302). The layer has no stream output: a graphics PSO with `StreamOutput` - entries is refused and `SOSetTargets` is not implemented, so no primitive reaches a stream and every - `SO_STATISTICS_STREAM0..3` query counts 0 written and 0 needed. An `SO_STATISTICS` heap is therefore made without - a `VkQueryPool`: `BeginQuery`/`EndQuery` record nothing in Vulkan (D3D12's call rules are still kept, and the +- **Stream-output statistics** (D3D-302). The layer still refuses `StreamOutput` PSOs and does not implement + `SOSetTargets`, so no primitive reaches a stream yet. With `VK_EXT_transform_feedback` enabled on the device + (`D3D-TRANSFORM-FEEDBACK-DEVICE`) and its `transformFeedbackQueries` property set, an `SO_STATISTICS` heap is a + real `VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT` pool begun and ended indexed on the stream + (`vkCmdBeginQueryIndexedEXT` / `vkCmdEndQueryIndexedEXT`), and `ResolveQueryData` copies the two 64-bit results per + query (16 bytes: `NumPrimitivesWritten`, `PrimitivesStorageNeeded`), in the same order; with no stream output they + are 0. A stream at or above the device's `maxTransformFeedbackStreams` runs nothing and resolves zero, as if the + heap had no pool. Without the feature, the property, or a nonzero `maxTransformFeedbackStreams`, the heap is made + without a `VkQueryPool`: `BeginQuery`/`EndQuery` run nothing in Vulkan (D3D12's call rules are still kept, and the heap's queries track ended or not as the others do), they overlap no other query, and `ResolveQueryData` writes - zeros (`vkCmdFillBuffer`, 16 bytes per query: `NumPrimitivesWritten`, `PrimitivesStorageNeeded`), with no - statistics split since nothing is dispatched. When stream output lands, the heap becomes a - `VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT` pool begun with `vkCmdBeginQueryIndexedEXT` on the stream, whose two - results are in the same order. + zeros (`vkCmdFillBuffer`, 16 bytes per query), with no statistics split since nothing is dispatched. Two + overlapping `SO_STATISTICS` queries on one stream would be two active indexed queries in one pool + (`VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753`), so `prepare()` refuses such a list + (`ReplayResult::invalid_query`); queries on different streams are fine. - **Recording.** The list keeps D3D12's rules for the calls: timestamps only have `EndQuery`; every other query is begun and ended in the same list with the same type, is not begun again while it runs, and is not resolved while it runs; resolve offsets are multiples of 8. A list closed with a query still running reports `E_INVALIDARG` and diff --git a/runtime/shims/d3d12_com.h b/runtime/shims/d3d12_com.h index 124793da6e..e97cf43d28 100644 --- a/runtime/shims/d3d12_com.h +++ b/runtime/shims/d3d12_com.h @@ -217,13 +217,20 @@ struct VulkanDeviceInfo { // VK_EXT_mesh_shader's meshShaderQueries feature is enabled on `device`, so the clipping invocations of a mesh // segment come from a mesh-primitives query (D3D-MESH-CLIPPING-COUNTER). Without it they read 0. bool mesh_shader_queries = false; - // VK_EXT_transform_feedback with its transformFeedback feature is detected and enabled on `device` (D3D-302). - // Nothing uses it yet: a graphics PSO that declares StreamOutput is still refused and SOSetTargets is still not - // implemented. (#1630 adds the SO_STATISTICS query pools, which use it.) + // VK_EXT_transform_feedback with its transformFeedback feature is enabled on `device` (D3D-302): an + // SO_STATISTICS heap is a real VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT pool, begun and ended indexed on the + // stream. StreamOutput PSOs are still refused and SOSetTargets is still not implemented. bool transform_feedback = false; - // VK_EXT_transform_feedback's geometryStreams feature is enabled when the device offers it. Nothing rasterizes a - // StreamOutput RasterizedStream yet; it is here for the capture implementation that follows. + // VK_EXT_transform_feedback's geometryStreams feature is offered by the device. The device-enable chain requests + // it when present so the pipeline cache key matches vk_pipeline_check; nothing rasterizes a stream other than 0. bool transform_feedback_geometry_streams = false; + // VK_EXT_transform_feedback's transformFeedbackQueries property (D3D-302): the device can begin/end a + // VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT query. Without it an SO_STATISTICS heap is made without a pool and + // every SO_STATISTICS query resolves zero, even when the transformFeedback feature is enabled. + bool transform_feedback_queries = false; + // The device's maxTransformFeedbackStreams property: an SO_STATISTICS_STREAMn query runs only for n below it. + // Streams from this count up (to the D3D12 maximum of four) run nothing and resolve zero. + std::uint32_t max_transform_feedback_streams = 0; // The core features enabled on `device`. Graphics PSOs that need independentBlend, fillModeNonSolid, // depthBiasClamp or dualSrcBlend are refused unless it is set here. VkPhysicalDeviceFeatures features{}; diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index f62cf15f0c..3d2e928bdd 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -10759,11 +10759,17 @@ class QueryHeap final break; } case h::so_statistics: - // The layer has no stream output: a graphics PSO with StreamOutput entries is refused (E_NOTIMPL) and - // SOSetTargets is not implemented, so no primitive ever reaches a stream and every query of this heap - // counts 0 written and 0 needed. That needs no Vulkan pool: Begin/EndQuery run nothing and a resolve fills zeros. When stream - // output lands, this becomes a VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT pool (D3D-302). - return register_pool(desc); + // D3D-302: with VK_EXT_transform_feedback enabled, an SO_STATISTICS heap is a real transform-feedback + // pool whose queries begin/end on a stream (vkCmdBeginQueryIndexedEXT); a resolve copies 16 bytes per + // query (NumPrimitivesWritten, PrimitivesStorageNeeded), in the same order. StreamOutput PSOs are still + // refused and SOSetTargets is still not implemented, so no primitive reaches a stream yet and every + // query counts 0. The pool needs the transformFeedbackQueries property and at least one stream; without + // them (or without the feature) the heap is made without a pool and every query resolves to zero. + if (!device_.info.transform_feedback || !device_.info.transform_feedback_queries || + !device_.info.max_transform_feedback_streams) + return register_pool(desc); + info.queryType = VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT; + break; case h::pipeline_statistics: if (!device_.info.pipeline_statistics_query) { log_once("pipeline-statistics query heap: pipelineStatisticsQuery not enabled; type", desc.Type); @@ -10792,6 +10798,9 @@ class QueryHeap final pool.count = desc.Count; pool.precise = device_.info.occlusion_query_precise; pool.ended.assign(desc.Count, false); + // D3D-302: a real transform-feedback pool queries streams below maxTransformFeedbackStreams; D3D12 has four. + if (pool_ && desc.Type == leonida::d3d12_query_heap::so_statistics) + pool.streams = std::min(4, device_.info.max_transform_feedback_streams); device_.context->add_query_pool(id(), pool); registered_ = true; return S_OK; @@ -17985,6 +17994,8 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin VkPhysicalDeviceMeshShaderFeaturesEXT mesh_features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT}; VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback_features{ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT}; + VkPhysicalDeviceTransformFeedbackPropertiesEXT transform_feedback_properties{ + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT}; { std::uint32_t extension_count = 0; vkEnumerateDeviceExtensionProperties(info.physical, nullptr, &extension_count, nullptr); @@ -18015,14 +18026,22 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin vkGetPhysicalDeviceFeatures2(info.physical, &features); info.transform_feedback = transform_feedback_features.transformFeedback == VK_TRUE; info.transform_feedback_geometry_streams = transform_feedback_features.geometryStreams == VK_TRUE; + // D3D-302: the queries and the stream count are properties, not features. + VkPhysicalDeviceProperties2 properties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, + &transform_feedback_properties}; + vkGetPhysicalDeviceProperties2(info.physical, &properties); + info.transform_feedback_queries = transform_feedback_properties.transformFeedbackQueries == VK_TRUE; + info.max_transform_feedback_streams = transform_feedback_properties.maxTransformFeedbackStreams; } } if (!info.mesh_shader) std::fprintf(stderr, "[rt] d3d12: the GPU has no VK_EXT_mesh_shader: mesh-shader PSOs are unsupported\n"); if (!info.transform_feedback) std::fprintf(stderr, - "[rt] d3d12: the GPU has no VK_EXT_transform_feedback: stream output is unsupported and " - "SO_STATISTICS pools read zero\n"); + "[rt] d3d12: the GPU has no VK_EXT_transform_feedback: SO_STATISTICS query pools read zero\n"); + else if (!info.transform_feedback_queries || !info.max_transform_feedback_streams) + std::fprintf(stderr, "[rt] d3d12: the GPU has no transform-feedback queries (transformFeedbackQueries, " + "maxTransformFeedbackStreams): SO_STATISTICS query pools read zero\n"); if (has_as && has_dho && has_rq && chosen12.bufferDeviceAddress) { as_features.pNext = &rq_features; VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &as_features}; @@ -18058,8 +18077,8 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin // The mesh-primitives query, which counts the primitives a mesh shader emits (D3D-MESH-CLIPPING-COUNTER). enable_mesh.meshShaderQueries = info.mesh_shader_queries ? VK_TRUE : VK_FALSE; - // D3D-302: StreamOutput PSOs, SOSetTargets and real SO_STATISTICS queries need transformFeedback; geometryStreams - // is only requested when the device already offers it (RasterizedStream != 0 is the one thing it gates). + // D3D-302: real SO_STATISTICS queries need transformFeedback; geometryStreams is only requested when the device + // already offers it, so the enable chain matches vk_pipeline_check's (a driver keys the pipeline cache on it). VkPhysicalDeviceTransformFeedbackFeaturesEXT enable_transform_feedback{ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT}; enable_transform_feedback.transformFeedback = VK_TRUE; diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index ecc2eef9cd..68ab9b194d 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h @@ -130,7 +130,8 @@ struct VulkanDeviceFunctions { X(vkCreatePipelineCache) X(vkDestroyPipelineCache) X(vkGetPipelineCacheData) X(vkMergePipelineCaches) \ X(vkCreateEvent) X(vkDestroyEvent) X(vkResetEvent) X(vkCmdSetEvent) X(vkCmdWaitEvents) X(vkCmdDrawMeshTasksEXT) \ X(vkCreateRenderPass2) X(vkDestroyRenderPass) X(vkCreateFramebuffer) X(vkDestroyFramebuffer) \ - X(vkCmdBeginRenderPass) X(vkCmdEndRenderPass) + X(vkCmdBeginRenderPass) X(vkCmdEndRenderPass) \ + X(vkCmdBeginQueryIndexedEXT) X(vkCmdEndQueryIndexedEXT) #define LEONIDA_VK_MEMBER(name) PFN_##name name = nullptr; LEONIDA_VK_DEVICE_FUNCTIONS(LEONIDA_VK_MEMBER) #undef LEONIDA_VK_MEMBER @@ -165,6 +166,9 @@ struct VulkanDeviceFunctions { return vkCmdBeginRendering && vkCmdEndRendering && vkCmdBindVertexBuffers2 && vkCmdSetPrimitiveTopology && vkCmdSetPrimitiveRestartEnable; } + // VK_EXT_transform_feedback is enabled on the device: the indexed-query entry points are loaded, so an + // SO_STATISTICS heap can be a real transform-feedback pool (D3D-302). + bool transform_feedback = false; }; // Both kinds of compute resolve use the same storage buffer, descriptor set and pipeline layout. @@ -1090,6 +1094,8 @@ class VulkanContext { GraphicsIndirectCapabilities indirect = {}) : device_(device), tracker_(separate_depth_stencil_layouts), ray_tracing_(ray_tracing) { loaded_ = vk.load(get, device); + // VK_EXT_transform_feedback: enabled on the device when its indexed-query entry points resolved (D3D-302). + vk.transform_feedback = vk.vkCmdBeginQueryIndexedEXT && vk.vkCmdEndQueryIndexedEXT; if (loaded_ && gpu_labels_.initialize(device, get)) { replay_.gpu_label = [this](VkCommandBuffer cb, const label::Write& write) { gpu_labels_.record(cb, write); }; } @@ -1125,6 +1131,11 @@ class VulkanContext { replay_.reset_query_pool = vk.vkCmdResetQueryPool; replay_.begin_query = vk.vkCmdBeginQuery; replay_.end_query = vk.vkCmdEndQuery; + // VK_EXT_transform_feedback (D3D-302), loaded when the device enabled it: indexed SO_STATISTICS queries. + if (vk.transform_feedback) { + replay_.begin_query_indexed = vk.vkCmdBeginQueryIndexedEXT; + replay_.end_query_indexed = vk.vkCmdEndQueryIndexedEXT; + } replay_.write_timestamp = vk.vkCmdWriteTimestamp; replay_.copy_query_pool_results = vk.vkCmdCopyQueryPoolResults; replay_.bind_pipeline = vk.vkCmdBindPipeline; diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index 449f8de5d9..d84f26ccfc 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h @@ -844,14 +844,19 @@ struct OcclusionResult { // A D3D12 query heap on Vulkan. The host tracks which queries hold a result. A resolve of a query that // was never ended writes zeros instead of waiting on it. struct QueryPool { - // Null for a stream-output statistics heap: the layer has no stream output (PSOs with StreamOutput entries are - // refused), so every SO_STATISTICS_STREAMn query counts 0 written and 0 needed, and a resolve fills zeros. + // Null for a stream-output statistics heap on a device without VK_EXT_transform_feedback (D3D-302): every + // SO_STATISTICS_STREAMn query then counts 0 written and 0 needed, and a resolve fills zeros. With the feature + // it is a VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT pool, begun/ended indexed on the stream. VkQueryPool pool = VK_NULL_HANDLE; std::uint32_t heap_type = 0; // d3d12_query_heap std::uint32_t count = 0; bool precise = false; // occlusionQueryPrecise: D3D12_QUERY_TYPE_OCCLUSION counts exact samples std::vector ended; std::unordered_map occlusion; + // Transform-feedback streams the pool can query (D3D-302): 0 when it has no pool, otherwise the device's + // maxTransformFeedbackStreams clamped to D3D12's four. SO_STATISTICS_STREAMn with n at or above this runs nothing + // and resolves zero. + std::uint32_t streams = 0; }; // A compute pipeline as replay needs it. code_base is the console VA of the shader's FSSM blob (push-constant @@ -1175,6 +1180,10 @@ struct ReplayFunctions { PFN_vkCmdResetQueryPool reset_query_pool = nullptr; // queries, with fill_buffer for unavailable results PFN_vkCmdBeginQuery begin_query = nullptr; PFN_vkCmdEndQuery end_query = nullptr; + // VK_EXT_transform_feedback (D3D-302): SO_STATISTICS queries begin/end indexed on a stream. Null when the device + // lacks the feature. + PFN_vkCmdBeginQueryIndexedEXT begin_query_indexed = nullptr; + PFN_vkCmdEndQueryIndexedEXT end_query_indexed = nullptr; PFN_vkCmdWriteTimestamp write_timestamp = nullptr; PFN_vkCmdCopyQueryPoolResults copy_query_pool_results = nullptr; // Set only where a copy of timestamp results is not ordered after the timestamps written before it (MoltenVK on @@ -3387,6 +3396,8 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun out.unpredicated_copies = 0; const bool queries = vk.reset_query_pool && vk.begin_query && vk.end_query && vk.write_timestamp && vk.copy_query_pool_results && vk.fill_buffer && vk.query_pool; + // An SO_STATISTICS query on a real transform-feedback heap additionally needs the indexed begin/end (D3D-302). + const bool so_queries = vk.begin_query_indexed && vk.end_query_indexed; // Vulkan allows one active query per type. Overlapping ordinary and binary occlusion share one physical // segment pool, and overlapping statistics split into the statistics pool (D3D-252); a physical query of a // type is still open at most once at any point, because each event closes the one open slot and opens a new @@ -3394,6 +3405,10 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun VkDeviceAddress indirect_list_budget = 0; std::size_t ordinary_active = 0, binary_active = 0, statistics_active_count = 0; bool overlaps = false, statistics_overlaps = false, statistics_active = false; + // Streams with an active SO_STATISTICS query in this list, one bit each (D3D-302). Two active transform-feedback + // queries on one stream break VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753 anywhere in the command buffer, + // whatever their pools, so prepare refuses a second Begin on an active stream. + std::uint32_t so_active = 0; out.wrote_readback = false; out.readback_src_stages = 0; @@ -3942,7 +3957,23 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun overlaps |= begin && (ordinary_active || binary_active); if (begin) ++binary_active; else --binary_active; } else if (is_so_statistics(range.type)) { - // No Vulkan query runs for it (QueryPool::pool is null), so it overlaps nothing. + // A real transform-feedback heap queries on a stream (D3D-302). Stream n runs only when the + // heap's pool covers it; then the indexed commands are required. Without a pool (the feature is + // off or has no transformFeedbackQueries) or past maxTransformFeedbackStreams it runs nothing + // and resolves zero. Two overlapping queries on one stream cannot both be active in one command + // buffer, even in two heaps (VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753), so a second Begin + // is refused. + const std::uint32_t stream = range.type - d3d12_query::so_statistics_stream0; + if (heap->pool && stream < heap->streams) { + if (!so_queries) return unsupported_at(__LINE__); + const std::uint32_t bit = 1u << stream; // stream < heap->streams <= 4 + if (begin) { + if (so_active & bit) return ReplayResult::invalid_query; + so_active |= bit; + } else { + so_active &= ~bit; + } + } } else { statistics_overlaps |= begin && statistics_active_count; if (begin) ++statistics_active_count; else --statistics_active_count; @@ -4256,12 +4287,16 @@ class QueryReplay { query.statistics_end != detail::PreparedQuery::no_segment; const std::uint32_t size = query_result_size(resolve.type); const auto offset = list.commands[query.command].binding.buffer_offset + resolve.offset; + // A stream past the pool's maxTransformFeedbackStreams ran nothing (D3D-302): its resolve is zeros. + const std::uint32_t so_stream = + is_so_statistics(resolve.type) ? resolve.type - d3d12_query::so_statistics_stream0 : 0; + const bool so_runs = !is_so_statistics(resolve.type) || so_stream < query.heap->streams; for (std::uint32_t i = 0; i < resolve.count; ++i) { const auto index = resolve.first + i; const auto value = lookup(*query.heap, index); if (binary && value.ended && !uncounted) return unsupported_at(__LINE__); needs_binary |= binary && value.ended; - detail::QueryResolveRun run{value.ended ? query.heap->pool : VK_NULL_HANDLE, + detail::QueryResolveRun run{value.ended && so_runs ? query.heap->pool : VK_NULL_HANDLE, index, 1, offset + VkDeviceSize(i) * size}; if (value.occlusion.segments) { if (resolve.type != d3d12_query::occlusion && !binary && !statistics) @@ -4385,17 +4420,34 @@ inline void emit_query(const PreparedList& list, const detail::PreparedQuery& qu begin_statistics(); return; } - // A heap without a Vulkan pool (stream-output statistics: the layer has no stream output) runs nothing for - // BeginQuery and EndQuery; its resolves were planned as zero fills. + // A heap without a Vulkan pool (stream-output statistics on a device without VK_EXT_transform_feedback) runs + // nothing for BeginQuery and EndQuery; its resolves were planned as zero fills. if (!heap.pool && !std::holds_alternative(command)) return; + // An SO_STATISTICS_STREAMn query begins/ends indexed on that stream (D3D-302): the query type's stream index is + // the `index` argument of vkCmdBeginQueryIndexedEXT / vkCmdEndQueryIndexedEXT. A stream past the pool's + // maxTransformFeedbackStreams runs nothing, like a heap without a pool: its resolves were planned as zero fills. + const auto so_stream = [](std::uint32_t type) -> std::uint32_t { + return is_so_statistics(type) ? type - d3d12_query::so_statistics_stream0 : 0; + }; + const auto so_runs = [&](std::uint32_t type) { + return !is_so_statistics(type) || so_stream(type) < heap.streams; + }; if (const auto* begin = std::get_if(&command)) { + if (!so_runs(begin->type)) return; vk.reset_query_pool(cb, heap.pool, begin->index, 1); - const bool precise = begin->type == d3d12_query::occlusion && heap.precise; - vk.begin_query(cb, heap.pool, begin->index, precise ? VK_QUERY_CONTROL_PRECISE_BIT : 0); + if (is_so_statistics(begin->type)) { + vk.begin_query_indexed(cb, heap.pool, begin->index, so_stream(begin->type), 0); + } else { + const bool precise = begin->type == d3d12_query::occlusion && heap.precise; + vk.begin_query(cb, heap.pool, begin->index, precise ? VK_QUERY_CONTROL_PRECISE_BIT : 0); + } } else if (const auto* end = std::get_if(&command)) { + if (!so_runs(end->type)) return; if (end->type == d3d12_query::timestamp) { vk.reset_query_pool(cb, heap.pool, end->index, 1); vk.write_timestamp(cb, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, heap.pool, end->index); + } else if (is_so_statistics(end->type)) { + vk.end_query_indexed(cb, heap.pool, end->index, so_stream(end->type)); } else { vk.end_query(cb, heap.pool, end->index); } diff --git a/runtime/test/d3d12_vulkan_device_test.cpp b/runtime/test/d3d12_vulkan_device_test.cpp index 9df462d3fd..2b4e48ac7c 100644 --- a/runtime/test/d3d12_vulkan_device_test.cpp +++ b/runtime/test/d3d12_vulkan_device_test.cpp @@ -6766,8 +6766,11 @@ int main() { EXPECT(SUCCEEDED(device->CreateQueryHeap(&query_desc, IID_PPV_ARGS(×tamps.p)))); query_desc = {D3D12_QUERY_HEAP_TYPE_OCCLUSION, 0, 0}; EXPECT(device->CreateQueryHeap(&query_desc, IID_PPV_ARGS(&refused.p)) == E_INVALIDARG && !refused.p); - // The layer has no stream output, so stream-output statistics heaps are made without a Vulkan pool and - // every query reads zero (D3D-302). + // D3D-302: an SO_STATISTICS heap is a real transform-feedback pool on a device with + // VK_EXT_transform_feedback whose transformFeedbackQueries property is set (indexed on the stream); without + // them the heap is made without a Vulkan pool and every query reads zero. A stream past + // maxTransformFeedbackStreams reads zero too. StreamOutput PSOs are still refused, so no stream output runs + // and the resolved counts are 0 in either case. query_desc = {D3D12_QUERY_HEAP_TYPE_SO_STATISTICS, 3, 0}; EXPECT(SUCCEEDED(device->CreateQueryHeap(&query_desc, IID_PPV_ARGS(&so.p)))); query_desc = {D3D12_QUERY_HEAP_TYPE_PIPELINE_STATISTICS, 2, 0}; diff --git a/runtime/test/replay_query_predication_test.cpp b/runtime/test/replay_query_predication_test.cpp index 87056a4990..352067bca5 100644 --- a/runtime/test/replay_query_predication_test.cpp +++ b/runtime/test/replay_query_predication_test.cpp @@ -7,7 +7,8 @@ // inside ordinary, the composite sum-and-normalize binary resolve, helper dispatches inside overlapping statistics // queries, the single-list refusal (D3D-252) and, with a pool, its replay (D3D-399). Cases 15 and 16 check queries // that hold mesh draws, split between the full and the mesh-compatible pool, alone and overlapping (D3D-291). No GPU or -// game data. +// game data. Case 18 checks SO_STATISTICS: overlapping queries on one stream are refused +// (VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753) and streams past maxTransformFeedbackStreams resolve zero (D3D-302). #include "../src/vulkan_replay.h" #include #include @@ -774,6 +775,105 @@ int main() { "the mesh pool counts the fragment and compute invocations"); } + // 18. D3D-302: two overlapping SO_STATISTICS queries on one stream would be two active indexed queries in one + // pool (VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753). prepare() refuses them; different streams are fine. + // A stream past the pool's maxTransformFeedbackStreams runs nothing and resolves zero. + { + QueryPool so{handle(8), d3d12_query_heap::so_statistics, 4, false, + std::vector(4, false), {}, 4}; + ReplayFunctions indexed = vk; + indexed.query_pool = [&](QueryHeapId id) -> QueryPool* { return id == 8 ? &so : nullptr; }; + indexed.begin_query_indexed = +[](VkCommandBuffer, VkQueryPool pool, std::uint32_t index, + std::uint32_t stream, VkQueryControlFlags) { + g_trace->events.push_back(query_event("begin_indexed", pool, index) + "/" + std::to_string(stream)); + }; + indexed.end_query_indexed = +[](VkCommandBuffer, VkQueryPool pool, std::uint32_t index, + std::uint32_t stream) { + g_trace->events.push_back(query_event("end_indexed", pool, index) + "/" + std::to_string(stream)); + }; + + { + CommandList list; + expect(list.begin_query({8, d3d12_query::so_statistics_stream0, 0}), "record SO begin stream 0"); + expect(list.begin_query({8, d3d12_query::so_statistics_stream0, 1}), "record second SO begin stream 0"); + expect(list.end_query({8, d3d12_query::so_statistics_stream0, 1}), "record second SO end stream 0"); + expect(list.end_query({8, d3d12_query::so_statistics_stream0, 0}), "record SO end stream 0"); + expect(list.close(), "close overlapping SO stream list"); + PreparedList prepared; + expect(prepare(list, resolve, indexed, prepared) == ReplayResult::invalid_query, + "two overlapping SO_STATISTICS queries on one stream are refused"); + } + { + CommandList list; + expect(list.begin_query({8, d3d12_query::so_statistics_stream0, 0}), "record SO begin stream 0"); + expect(list.begin_query({8, d3d12_query::so_statistics_stream0 + 1, 1}), "record SO begin stream 1"); + expect(list.end_query({8, d3d12_query::so_statistics_stream0 + 1, 1}), "record SO end stream 1"); + expect(list.end_query({8, d3d12_query::so_statistics_stream0, 0}), "record SO end stream 0"); + expect(list.close(), "close two-stream SO list"); + PreparedList prepared; + expect(prepare(list, resolve, indexed, prepared) == ReplayResult::success, + "overlapping SO_STATISTICS queries on different streams are fine"); + } + // The VUID holds per command buffer, not per pool: one stream in two heaps is refused too, while queries that + // take turns on that stream are fine. + QueryPool so2{handle(9), d3d12_query_heap::so_statistics, 4, false, + std::vector(4, false), {}, 4}; + ReplayFunctions two_heaps = indexed; + two_heaps.query_pool = [&](QueryHeapId id) -> QueryPool* { + return id == 8 ? &so : id == 9 ? &so2 : nullptr; + }; + { + CommandList list; + expect(list.begin_query({8, d3d12_query::so_statistics_stream0, 0}), "record SO begin stream 0, heap 8"); + expect(list.begin_query({9, d3d12_query::so_statistics_stream0, 0}), "record SO begin stream 0, heap 9"); + expect(list.end_query({9, d3d12_query::so_statistics_stream0, 0}), "record SO end stream 0, heap 9"); + expect(list.end_query({8, d3d12_query::so_statistics_stream0, 0}), "record SO end stream 0, heap 8"); + expect(list.close(), "close two-heap SO stream list"); + PreparedList prepared; + expect(prepare(list, resolve, two_heaps, prepared) == ReplayResult::invalid_query, + "overlapping SO_STATISTICS queries on one stream in two heaps are refused"); + } + { + CommandList list; + expect(list.begin_query({8, d3d12_query::so_statistics_stream0, 0}), "record SO begin stream 0, heap 8"); + expect(list.end_query({8, d3d12_query::so_statistics_stream0, 0}), "record SO end stream 0, heap 8"); + expect(list.begin_query({9, d3d12_query::so_statistics_stream0, 0}), "record SO begin stream 0, heap 9"); + expect(list.end_query({9, d3d12_query::so_statistics_stream0, 0}), "record SO end stream 0, heap 9"); + expect(list.close(), "close two-heap SO stream list in turn"); + PreparedList prepared; + expect(prepare(list, resolve, two_heaps, prepared) == ReplayResult::success, + "SO_STATISTICS queries on one stream in two heaps, one after the other, are fine"); + } + // A one-stream pool: stream 0 runs, stream 1 is zero-filled and emits nothing. + so.streams = 1; + { + Trace trace; + g_trace = &trace; + CommandList list; + expect(list.begin_query({8, d3d12_query::so_statistics_stream0 + 1, 0}), "record unsupported SO begin"); + expect(list.end_query({8, d3d12_query::so_statistics_stream0 + 1, 0}), "record unsupported SO end"); + expect(list.resolve_queries({8, d3d12_query::so_statistics_stream0 + 1, 0, 1, 1, 0}), + "record unsupported SO resolve"); + expect(list.close(), "close unsupported stream list"); + expect(replay(list, VK_NULL_HANDLE, resolve, indexed) == ReplayResult::success, + "a stream past maxTransformFeedbackStreams replays"); + expect(trace.fills == 1 && trace.events == std::vector{"fill"}, + "a stream past maxTransformFeedbackStreams emits no query and resolves zero"); + } + { + Trace trace; + g_trace = &trace; + CommandList list; + expect(list.begin_query({8, d3d12_query::so_statistics_stream0, 0}), "record supported SO begin"); + expect(list.end_query({8, d3d12_query::so_statistics_stream0, 0}), "record supported SO end"); + expect(list.close(), "close supported stream list"); + expect(replay(list, VK_NULL_HANDLE, resolve, indexed) == ReplayResult::success, + "stream 0 on a one-stream pool replays"); + expect(trace.events == std::vector{"begin_indexed 8:0/0", "end_indexed 8:0/0"}, + "stream 0 on a one-stream pool begins and ends indexed on stream 0"); + } + } + if (failures) return 1; std::puts("replay_query_predication_test: query resolves suspend conditional rendering around fills, copies and dispatches"); return 0;