upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorBubsMcgee <alexbraden99@gmail.com>2026-11-25 06:38:37 -0500
committerBubsMcgee <alexbraden99@gmail.com>2026-11-25 09:56:34 -0500
commite5a49762248fdebb0575c1b9e07bbb1a1fcf126b (patch)
tree2a18b48574b03c7c52ad7c28034ccf97f847b359 /runtime/src
parentb9739b70d322a55bde016b92d0b8bb9691638d0e (diff)
d3d12: real SO_STATISTICS query pools (D3D-302)
With VK_EXT_transform_feedback enabled on the device, an SO_STATISTICS heap is a real VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT pool, begun and ended indexed on the stream (vkCmdBeginQueryIndexedEXT / vkCmdEndQueryIndexedEXT). ResolveQueryData copies the two 64-bit results (NumPrimitivesWritten, PrimitivesStorageNeeded) in the same order. The layer still refuses StreamOutput PSOs and still does not implement SOSetTargets, so no primitive reaches a stream yet and the counts stay 0; without the feature the heap is made without a VkQueryPool and resolves zeros, as before.
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/vulkan_backend.h13
-rw-r--r--runtime/src/vulkan_replay.h35
2 files changed, 40 insertions, 8 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h
index 145fa11ee..d86b3ded7 100644
--- a/runtime/src/vulkan_backend.h
+++ b/runtime/src/vulkan_backend.h
@@ -130,7 +130,8 @@ struct VulkanDeviceFunctions {
130 X(vkCreatePipelineCache) X(vkDestroyPipelineCache) X(vkGetPipelineCacheData) X(vkMergePipelineCaches) \ 130 X(vkCreatePipelineCache) X(vkDestroyPipelineCache) X(vkGetPipelineCacheData) X(vkMergePipelineCaches) \
131 X(vkCreateEvent) X(vkDestroyEvent) X(vkResetEvent) X(vkCmdSetEvent) X(vkCmdWaitEvents) X(vkCmdDrawMeshTasksEXT) \ 131 X(vkCreateEvent) X(vkDestroyEvent) X(vkResetEvent) X(vkCmdSetEvent) X(vkCmdWaitEvents) X(vkCmdDrawMeshTasksEXT) \
132 X(vkCreateRenderPass2) X(vkDestroyRenderPass) X(vkCreateFramebuffer) X(vkDestroyFramebuffer) \ 132 X(vkCreateRenderPass2) X(vkDestroyRenderPass) X(vkCreateFramebuffer) X(vkDestroyFramebuffer) \
133 X(vkCmdBeginRenderPass) X(vkCmdEndRenderPass) 133 X(vkCmdBeginRenderPass) X(vkCmdEndRenderPass) \
134 X(vkCmdBeginQueryIndexedEXT) X(vkCmdEndQueryIndexedEXT)
134#define LEONIDA_VK_MEMBER(name) PFN_##name name = nullptr; 135#define LEONIDA_VK_MEMBER(name) PFN_##name name = nullptr;
135 LEONIDA_VK_DEVICE_FUNCTIONS(LEONIDA_VK_MEMBER) 136 LEONIDA_VK_DEVICE_FUNCTIONS(LEONIDA_VK_MEMBER)
136#undef LEONIDA_VK_MEMBER 137#undef LEONIDA_VK_MEMBER
@@ -165,6 +166,9 @@ struct VulkanDeviceFunctions {
165 return vkCmdBeginRendering && vkCmdEndRendering && vkCmdBindVertexBuffers2 && vkCmdSetPrimitiveTopology && 166 return vkCmdBeginRendering && vkCmdEndRendering && vkCmdBindVertexBuffers2 && vkCmdSetPrimitiveTopology &&
166 vkCmdSetPrimitiveRestartEnable; 167 vkCmdSetPrimitiveRestartEnable;
167 } 168 }
169 // VK_EXT_transform_feedback is enabled on the device: the indexed-query entry points are loaded, so an
170 // SO_STATISTICS heap can be a real transform-feedback pool (D3D-302).
171 bool transform_feedback = false;
168}; 172};
169 173
170// Both kinds of compute resolve use the same storage buffer, descriptor set and pipeline layout. 174// Both kinds of compute resolve use the same storage buffer, descriptor set and pipeline layout.
@@ -1090,6 +1094,8 @@ public:
1090 GraphicsIndirectCapabilities indirect = {}) 1094 GraphicsIndirectCapabilities indirect = {})
1091 : device_(device), tracker_(separate_depth_stencil_layouts), ray_tracing_(ray_tracing) { 1095 : device_(device), tracker_(separate_depth_stencil_layouts), ray_tracing_(ray_tracing) {
1092 loaded_ = vk.load(get, device); 1096 loaded_ = vk.load(get, device);
1097 // VK_EXT_transform_feedback: enabled on the device when its indexed-query entry points resolved (D3D-302).
1098 vk.transform_feedback = vk.vkCmdBeginQueryIndexedEXT && vk.vkCmdEndQueryIndexedEXT;
1093 if (loaded_ && gpu_labels_.initialize(device, get)) { 1099 if (loaded_ && gpu_labels_.initialize(device, get)) {
1094 replay_.gpu_label = [this](VkCommandBuffer cb, const label::Write& write) { gpu_labels_.record(cb, write); }; 1100 replay_.gpu_label = [this](VkCommandBuffer cb, const label::Write& write) { gpu_labels_.record(cb, write); };
1095 } 1101 }
@@ -1125,6 +1131,11 @@ public:
1125 replay_.reset_query_pool = vk.vkCmdResetQueryPool; 1131 replay_.reset_query_pool = vk.vkCmdResetQueryPool;
1126 replay_.begin_query = vk.vkCmdBeginQuery; 1132 replay_.begin_query = vk.vkCmdBeginQuery;
1127 replay_.end_query = vk.vkCmdEndQuery; 1133 replay_.end_query = vk.vkCmdEndQuery;
1134 // VK_EXT_transform_feedback (D3D-302), loaded when the device enabled it: indexed SO_STATISTICS queries.
1135 if (vk.transform_feedback) {
1136 replay_.begin_query_indexed = vk.vkCmdBeginQueryIndexedEXT;
1137 replay_.end_query_indexed = vk.vkCmdEndQueryIndexedEXT;
1138 }
1128 replay_.write_timestamp = vk.vkCmdWriteTimestamp; 1139 replay_.write_timestamp = vk.vkCmdWriteTimestamp;
1129 replay_.copy_query_pool_results = vk.vkCmdCopyQueryPoolResults; 1140 replay_.copy_query_pool_results = vk.vkCmdCopyQueryPoolResults;
1130 replay_.bind_pipeline = vk.vkCmdBindPipeline; 1141 replay_.bind_pipeline = vk.vkCmdBindPipeline;
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h
index e20a29105..9480105d9 100644
--- a/runtime/src/vulkan_replay.h
+++ b/runtime/src/vulkan_replay.h
@@ -822,8 +822,9 @@ struct OcclusionResult {
822// A D3D12 query heap on Vulkan. The host tracks which queries hold a result. A resolve of a query that 822// A D3D12 query heap on Vulkan. The host tracks which queries hold a result. A resolve of a query that
823// was never ended writes zeros instead of waiting on it. 823// was never ended writes zeros instead of waiting on it.
824struct QueryPool { 824struct QueryPool {
825 // Null for a stream-output statistics heap: the layer has no stream output (PSOs with StreamOutput entries are 825 // Null for a stream-output statistics heap on a device without VK_EXT_transform_feedback (D3D-302): every
826 // refused), so every SO_STATISTICS_STREAMn query counts 0 written and 0 needed, and a resolve fills zeros. 826 // SO_STATISTICS_STREAMn query then counts 0 written and 0 needed, and a resolve fills zeros. With the feature
827 // it is a VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT pool, begun/ended indexed on the stream.
827 VkQueryPool pool = VK_NULL_HANDLE; 828 VkQueryPool pool = VK_NULL_HANDLE;
828 std::uint32_t heap_type = 0; // d3d12_query_heap 829 std::uint32_t heap_type = 0; // d3d12_query_heap
829 std::uint32_t count = 0; 830 std::uint32_t count = 0;
@@ -1066,6 +1067,10 @@ struct ReplayFunctions {
1066 PFN_vkCmdResetQueryPool reset_query_pool = nullptr; // queries, with fill_buffer for unavailable results 1067 PFN_vkCmdResetQueryPool reset_query_pool = nullptr; // queries, with fill_buffer for unavailable results
1067 PFN_vkCmdBeginQuery begin_query = nullptr; 1068 PFN_vkCmdBeginQuery begin_query = nullptr;
1068 PFN_vkCmdEndQuery end_query = nullptr; 1069 PFN_vkCmdEndQuery end_query = nullptr;
1070 // VK_EXT_transform_feedback (D3D-302): SO_STATISTICS queries begin/end indexed on a stream. Null when the device
1071 // lacks the feature.
1072 PFN_vkCmdBeginQueryIndexedEXT begin_query_indexed = nullptr;
1073 PFN_vkCmdEndQueryIndexedEXT end_query_indexed = nullptr;
1069 PFN_vkCmdWriteTimestamp write_timestamp = nullptr; 1074 PFN_vkCmdWriteTimestamp write_timestamp = nullptr;
1070 PFN_vkCmdCopyQueryPoolResults copy_query_pool_results = nullptr; 1075 PFN_vkCmdCopyQueryPoolResults copy_query_pool_results = nullptr;
1071 // Set only where a copy of timestamp results is not ordered after the timestamps written before it (MoltenVK on 1076 // Set only where a copy of timestamp results is not ordered after the timestamps written before it (MoltenVK on
@@ -3240,6 +3245,8 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun
3240 out.unpredicated_copies = 0; 3245 out.unpredicated_copies = 0;
3241 const bool queries = vk.reset_query_pool && vk.begin_query && vk.end_query && vk.write_timestamp && 3246 const bool queries = vk.reset_query_pool && vk.begin_query && vk.end_query && vk.write_timestamp &&
3242 vk.copy_query_pool_results && vk.fill_buffer && vk.query_pool; 3247 vk.copy_query_pool_results && vk.fill_buffer && vk.query_pool;
3248 // An SO_STATISTICS query on a real transform-feedback heap additionally needs the indexed begin/end (D3D-302).
3249 const bool so_queries = vk.begin_query_indexed && vk.end_query_indexed;
3243 // Vulkan allows one active query per type. Overlapping ordinary and binary occlusion share one physical 3250 // Vulkan allows one active query per type. Overlapping ordinary and binary occlusion share one physical
3244 // segment pool, and overlapping statistics split into the statistics pool (D3D-252); a physical query of a 3251 // segment pool, and overlapping statistics split into the statistics pool (D3D-252); a physical query of a
3245 // type is still open at most once at any point, because each event closes the one open slot and opens a new 3252 // type is still open at most once at any point, because each event closes the one open slot and opens a new
@@ -3784,7 +3791,10 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun
3784 overlaps |= begin && (ordinary_active || binary_active); 3791 overlaps |= begin && (ordinary_active || binary_active);
3785 if (begin) ++binary_active; else --binary_active; 3792 if (begin) ++binary_active; else --binary_active;
3786 } else if (is_so_statistics(range.type)) { 3793 } else if (is_so_statistics(range.type)) {
3787 // No Vulkan query runs for it (QueryPool::pool is null), so it overlaps nothing. 3794 // A real transform-feedback heap queries on a stream (D3D-302); without a pool (the feature is
3795 // off) it overlaps nothing and runs nothing. Both cases are handled; the indexed commands are
3796 // required when the heap has a pool.
3797 if (heap->pool && !so_queries) return unsupported_at(__LINE__);
3788 } else { 3798 } else {
3789 statistics_overlaps |= begin && statistics_active_count; 3799 statistics_overlaps |= begin && statistics_active_count;
3790 if (begin) ++statistics_active_count; else --statistics_active_count; 3800 if (begin) ++statistics_active_count; else --statistics_active_count;
@@ -4227,17 +4237,28 @@ inline void emit_query(const PreparedList& list, const detail::PreparedQuery& qu
4227 begin_statistics(); 4237 begin_statistics();
4228 return; 4238 return;
4229 } 4239 }
4230 // A heap without a Vulkan pool (stream-output statistics: the layer has no stream output) runs nothing for 4240 // A heap without a Vulkan pool (stream-output statistics on a device without VK_EXT_transform_feedback) runs
4231 // BeginQuery and EndQuery; its resolves were planned as zero fills. 4241 // nothing for BeginQuery and EndQuery; its resolves were planned as zero fills.
4232 if (!heap.pool && !std::holds_alternative<ResolveQueries>(command)) return; 4242 if (!heap.pool && !std::holds_alternative<ResolveQueries>(command)) return;
4243 // An SO_STATISTICS_STREAMn query begins/ends indexed on that stream (D3D-302): the query type's stream index is
4244 // the `index` argument of vkCmdBeginQueryIndexedEXT / vkCmdEndQueryIndexedEXT.
4245 const auto so_stream = [](std::uint32_t type) -> std::uint32_t {
4246 return is_so_statistics(type) ? type - d3d12_query::so_statistics_stream0 : 0;
4247 };
4233 if (const auto* begin = std::get_if<BeginQuery>(&command)) { 4248 if (const auto* begin = std::get_if<BeginQuery>(&command)) {
4234 vk.reset_query_pool(cb, heap.pool, begin->index, 1); 4249 vk.reset_query_pool(cb, heap.pool, begin->index, 1);
4235 const bool precise = begin->type == d3d12_query::occlusion && heap.precise; 4250 if (is_so_statistics(begin->type)) {
4236 vk.begin_query(cb, heap.pool, begin->index, precise ? VK_QUERY_CONTROL_PRECISE_BIT : 0); 4251 vk.begin_query_indexed(cb, heap.pool, begin->index, so_stream(begin->type), 0);
4252 } else {
4253 const bool precise = begin->type == d3d12_query::occlusion && heap.precise;
4254 vk.begin_query(cb, heap.pool, begin->index, precise ? VK_QUERY_CONTROL_PRECISE_BIT : 0);
4255 }
4237 } else if (const auto* end = std::get_if<EndQuery>(&command)) { 4256 } else if (const auto* end = std::get_if<EndQuery>(&command)) {
4238 if (end->type == d3d12_query::timestamp) { 4257 if (end->type == d3d12_query::timestamp) {
4239 vk.reset_query_pool(cb, heap.pool, end->index, 1); 4258 vk.reset_query_pool(cb, heap.pool, end->index, 1);
4240 vk.write_timestamp(cb, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, heap.pool, end->index); 4259 vk.write_timestamp(cb, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, heap.pool, end->index);
4260 } else if (is_so_statistics(end->type)) {
4261 vk.end_query_indexed(cb, heap.pool, end->index, so_stream(end->type));
4241 } else { 4262 } else {
4242 vk.end_query(cb, heap.pool, end->index); 4263 vk.end_query(cb, heap.pool, end->index);
4243 } 4264 }