diff options
| author | BubsMcgee <alexbraden99@gmail.com> | 2026-11-25 14:24:41 -0500 |
|---|---|---|
| committer | BubsMcgee <alexbraden99@gmail.com> | 2026-11-25 14:24:41 -0500 |
| commit | 369bb1c753e312b2ffe796fa79f1a13dbea63188 (patch) | |
| tree | f03431d41316e31b94c1ef3b863b27c955748365 /runtime/src | |
| parent | e5a49762248fdebb0575c1b9e07bbb1a1fcf126b (diff) | |
d3d12: gate SO_STATISTICS pools and refuse per-stream overlap (D3D-302)
The three review points on #1630:
- prepare() refuses two overlapping SO_STATISTICS queries on one stream: two
active indexed queries in one pool break
VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753. Queries on different streams
are fine.
- The transform-feedback pool now also needs the transformFeedbackQueries
property, and a stream at or above maxTransformFeedbackStreams runs nothing
and resolves zero instead of issuing an invalid indexed begin.
- replay_query_predication case 18 fails without both: the overlapping-stream
list is invalid_query and a stream past the pool's stream count fills zeros.
Tested: d3d12_vulkan_device, d3d12_state_map and replay_query_predication pass
plain and with LEONIDA_VK_VALIDATION=1 (RTX 3080 Ti, driver 616.64). AI-assisted.
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/vulkan_replay.h | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index 9480105d9..46bf58c3f 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h | |||
| @@ -831,6 +831,10 @@ struct QueryPool { | |||
| 831 | bool precise = false; // occlusionQueryPrecise: D3D12_QUERY_TYPE_OCCLUSION counts exact samples | 831 | bool precise = false; // occlusionQueryPrecise: D3D12_QUERY_TYPE_OCCLUSION counts exact samples |
| 832 | std::vector<bool> ended; | 832 | std::vector<bool> ended; |
| 833 | std::unordered_map<std::uint32_t, OcclusionResult> occlusion; | 833 | std::unordered_map<std::uint32_t, OcclusionResult> occlusion; |
| 834 | // Transform-feedback streams the pool can query (D3D-302): 0 when it has no pool, otherwise the device's | ||
| 835 | // maxTransformFeedbackStreams clamped to D3D12's four. SO_STATISTICS_STREAMn with n at or above this runs nothing | ||
| 836 | // and resolves zero. | ||
| 837 | std::uint32_t streams = 0; | ||
| 834 | }; | 838 | }; |
| 835 | 839 | ||
| 836 | // A compute pipeline as replay needs it. code_base is the console VA of the shader's FSSM blob (push-constant | 840 | // A compute pipeline as replay needs it. code_base is the console VA of the shader's FSSM blob (push-constant |
| @@ -3254,6 +3258,9 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3254 | VkDeviceAddress indirect_list_budget = 0; | 3258 | VkDeviceAddress indirect_list_budget = 0; |
| 3255 | std::size_t ordinary_active = 0, binary_active = 0, statistics_active_count = 0; | 3259 | std::size_t ordinary_active = 0, binary_active = 0, statistics_active_count = 0; |
| 3256 | bool overlaps = false, statistics_overlaps = false, statistics_active = false; | 3260 | bool overlaps = false, statistics_overlaps = false, statistics_active = false; |
| 3261 | // SO_STATISTICS queries active in a pool, by heap and stream (D3D-302): two on one stream would break | ||
| 3262 | // VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753, so prepare refuses them. | ||
| 3263 | std::map<std::pair<QueryHeapId, std::uint32_t>, bool> so_active; | ||
| 3257 | out.wrote_readback = false; | 3264 | out.wrote_readback = false; |
| 3258 | out.readback_src_stages = 0; | 3265 | out.readback_src_stages = 0; |
| 3259 | 3266 | ||
| @@ -3791,10 +3798,21 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3791 | overlaps |= begin && (ordinary_active || binary_active); | 3798 | overlaps |= begin && (ordinary_active || binary_active); |
| 3792 | if (begin) ++binary_active; else --binary_active; | 3799 | if (begin) ++binary_active; else --binary_active; |
| 3793 | } else if (is_so_statistics(range.type)) { | 3800 | } else if (is_so_statistics(range.type)) { |
| 3794 | // A real transform-feedback heap queries on a stream (D3D-302); without a pool (the feature is | 3801 | // A real transform-feedback heap queries on a stream (D3D-302). Stream n runs only when the |
| 3795 | // off) it overlaps nothing and runs nothing. Both cases are handled; the indexed commands are | 3802 | // heap's pool covers it; then the indexed commands are required. Without a pool (the feature is |
| 3796 | // required when the heap has a pool. | 3803 | // off or has no transformFeedbackQueries) or past maxTransformFeedbackStreams it runs nothing |
| 3797 | if (heap->pool && !so_queries) return unsupported_at(__LINE__); | 3804 | // and resolves zero. Two overlapping queries on one stream cannot both be active in one pool |
| 3805 | // (VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753), so a second Begin is refused. | ||
| 3806 | const std::uint32_t stream = range.type - d3d12_query::so_statistics_stream0; | ||
| 3807 | if (heap->pool && stream < heap->streams) { | ||
| 3808 | if (!so_queries) return unsupported_at(__LINE__); | ||
| 3809 | const auto key = std::make_pair(range.heap, stream); | ||
| 3810 | if (begin) { | ||
| 3811 | if (!so_active.emplace(key, true).second) return ReplayResult::invalid_query; | ||
| 3812 | } else { | ||
| 3813 | so_active.erase(key); | ||
| 3814 | } | ||
| 3815 | } | ||
| 3798 | } else { | 3816 | } else { |
| 3799 | statistics_overlaps |= begin && statistics_active_count; | 3817 | statistics_overlaps |= begin && statistics_active_count; |
| 3800 | if (begin) ++statistics_active_count; else --statistics_active_count; | 3818 | if (begin) ++statistics_active_count; else --statistics_active_count; |
| @@ -4108,12 +4126,16 @@ public: | |||
| 4108 | query.statistics_end != detail::PreparedQuery::no_segment; | 4126 | query.statistics_end != detail::PreparedQuery::no_segment; |
| 4109 | const std::uint32_t size = query_result_size(resolve.type); | 4127 | const std::uint32_t size = query_result_size(resolve.type); |
| 4110 | const auto offset = list.commands[query.command].binding.buffer_offset + resolve.offset; | 4128 | const auto offset = list.commands[query.command].binding.buffer_offset + resolve.offset; |
| 4129 | // A stream past the pool's maxTransformFeedbackStreams ran nothing (D3D-302): its resolve is zeros. | ||
| 4130 | const std::uint32_t so_stream = | ||
| 4131 | is_so_statistics(resolve.type) ? resolve.type - d3d12_query::so_statistics_stream0 : 0; | ||
| 4132 | const bool so_runs = !is_so_statistics(resolve.type) || so_stream < query.heap->streams; | ||
| 4111 | for (std::uint32_t i = 0; i < resolve.count; ++i) { | 4133 | for (std::uint32_t i = 0; i < resolve.count; ++i) { |
| 4112 | const auto index = resolve.first + i; | 4134 | const auto index = resolve.first + i; |
| 4113 | const auto value = lookup(*query.heap, index); | 4135 | const auto value = lookup(*query.heap, index); |
| 4114 | if (binary && value.ended && !uncounted) return unsupported_at(__LINE__); | 4136 | if (binary && value.ended && !uncounted) return unsupported_at(__LINE__); |
| 4115 | needs_binary |= binary && value.ended; | 4137 | needs_binary |= binary && value.ended; |
| 4116 | detail::QueryResolveRun run{value.ended ? query.heap->pool : VK_NULL_HANDLE, | 4138 | detail::QueryResolveRun run{value.ended && so_runs ? query.heap->pool : VK_NULL_HANDLE, |
| 4117 | index, 1, offset + VkDeviceSize(i) * size}; | 4139 | index, 1, offset + VkDeviceSize(i) * size}; |
| 4118 | if (value.occlusion.segments) { | 4140 | if (value.occlusion.segments) { |
| 4119 | if (resolve.type != d3d12_query::occlusion && !binary && !statistics) | 4141 | if (resolve.type != d3d12_query::occlusion && !binary && !statistics) |
| @@ -4241,11 +4263,16 @@ inline void emit_query(const PreparedList& list, const detail::PreparedQuery& qu | |||
| 4241 | // nothing for BeginQuery and EndQuery; its resolves were planned as zero fills. | 4263 | // nothing for BeginQuery and EndQuery; its resolves were planned as zero fills. |
| 4242 | if (!heap.pool && !std::holds_alternative<ResolveQueries>(command)) return; | 4264 | 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 | 4265 | // 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. | 4266 | // the `index` argument of vkCmdBeginQueryIndexedEXT / vkCmdEndQueryIndexedEXT. A stream past the pool's |
| 4267 | // maxTransformFeedbackStreams runs nothing, like a heap without a pool: its resolves were planned as zero fills. | ||
| 4245 | const auto so_stream = [](std::uint32_t type) -> std::uint32_t { | 4268 | const auto so_stream = [](std::uint32_t type) -> std::uint32_t { |
| 4246 | return is_so_statistics(type) ? type - d3d12_query::so_statistics_stream0 : 0; | 4269 | return is_so_statistics(type) ? type - d3d12_query::so_statistics_stream0 : 0; |
| 4247 | }; | 4270 | }; |
| 4271 | const auto so_runs = [&](std::uint32_t type) { | ||
| 4272 | return !is_so_statistics(type) || so_stream(type) < heap.streams; | ||
| 4273 | }; | ||
| 4248 | if (const auto* begin = std::get_if<BeginQuery>(&command)) { | 4274 | if (const auto* begin = std::get_if<BeginQuery>(&command)) { |
| 4275 | if (!so_runs(begin->type)) return; | ||
| 4249 | vk.reset_query_pool(cb, heap.pool, begin->index, 1); | 4276 | vk.reset_query_pool(cb, heap.pool, begin->index, 1); |
| 4250 | if (is_so_statistics(begin->type)) { | 4277 | if (is_so_statistics(begin->type)) { |
| 4251 | vk.begin_query_indexed(cb, heap.pool, begin->index, so_stream(begin->type), 0); | 4278 | vk.begin_query_indexed(cb, heap.pool, begin->index, so_stream(begin->type), 0); |
| @@ -4254,6 +4281,7 @@ inline void emit_query(const PreparedList& list, const detail::PreparedQuery& qu | |||
| 4254 | vk.begin_query(cb, heap.pool, begin->index, precise ? VK_QUERY_CONTROL_PRECISE_BIT : 0); | 4281 | vk.begin_query(cb, heap.pool, begin->index, precise ? VK_QUERY_CONTROL_PRECISE_BIT : 0); |
| 4255 | } | 4282 | } |
| 4256 | } else if (const auto* end = std::get_if<EndQuery>(&command)) { | 4283 | } else if (const auto* end = std::get_if<EndQuery>(&command)) { |
| 4284 | if (!so_runs(end->type)) return; | ||
| 4257 | if (end->type == d3d12_query::timestamp) { | 4285 | if (end->type == d3d12_query::timestamp) { |
| 4258 | vk.reset_query_pool(cb, heap.pool, end->index, 1); | 4286 | vk.reset_query_pool(cb, heap.pool, end->index, 1); |
| 4259 | vk.write_timestamp(cb, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, heap.pool, end->index); | 4287 | vk.write_timestamp(cb, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, heap.pool, end->index); |