Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2019-2022 The Khronos Group Inc. |
| 2 | * Copyright (c) 2019-2022 Valve Corporation |
| 3 | * Copyright (c) 2019-2022 LunarG, Inc. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | * Author: John Zulauf <jzulauf@lunarg.com> |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 18 | * Author: Locke Lin <locke@lunarg.com> |
| 19 | * Author: Jeremy Gebben <jeremyg@lunarg.com> |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <limits> |
| 23 | #include <vector> |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 24 | #include <memory> |
| 25 | #include <bitset> |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 26 | #include "synchronization_validation.h" |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 27 | #include "sync_utils.h" |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 28 | |
John Zulauf | ea943c5 | 2022-02-22 11:05:17 -0700 | [diff] [blame] | 29 | // Utilities to DRY up Get... calls |
| 30 | template <typename Map, typename Key = typename Map::key_type, typename RetVal = layer_data::optional<typename Map::mapped_type>> |
| 31 | RetVal GetMappedOptional(const Map &map, const Key &key) { |
| 32 | RetVal ret_val; |
| 33 | auto it = map.find(key); |
| 34 | if (it != map.cend()) { |
| 35 | ret_val.emplace(it->second); |
| 36 | } |
| 37 | return ret_val; |
| 38 | } |
| 39 | template <typename Map, typename Fn> |
| 40 | typename Map::mapped_type GetMapped(const Map &map, const typename Map::key_type &key, Fn &&default_factory) { |
| 41 | auto value = GetMappedOptional(map, key); |
| 42 | return (value) ? *value : default_factory(); |
| 43 | } |
| 44 | |
| 45 | template <typename Map, typename Fn> |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 46 | typename Map::mapped_type GetMappedInsert(Map &map, const typename Map::key_type &key, Fn &&emplace_factory) { |
John Zulauf | ea943c5 | 2022-02-22 11:05:17 -0700 | [diff] [blame] | 47 | auto value = GetMappedOptional(map, key); |
| 48 | if (value) { |
| 49 | return *value; |
| 50 | } |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 51 | auto insert_it = map.emplace(std::make_pair(key, emplace_factory())); |
John Zulauf | ea943c5 | 2022-02-22 11:05:17 -0700 | [diff] [blame] | 52 | assert(insert_it.second); |
| 53 | |
| 54 | return insert_it.first->second; |
| 55 | } |
| 56 | |
| 57 | template <typename Map, typename Key = typename Map::key_type, typename Mapped = typename Map::mapped_type, |
| 58 | typename Value = typename Mapped::element_type> |
| 59 | Value *GetMappedPlainFromShared(const Map &map, const Key &key) { |
| 60 | auto value = GetMappedOptional<Map, Key>(map, key); |
| 61 | if (value) return value->get(); |
| 62 | return nullptr; |
| 63 | } |
| 64 | |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 65 | static bool SimpleBinding(const BINDABLE &bindable) { return !bindable.sparse && bindable.Binding(); } |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 66 | |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 67 | static bool SimpleBinding(const IMAGE_STATE &image_state) { |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 68 | bool simple = |
Jeremy Gebben | 82e11d5 | 2021-07-26 09:19:37 -0600 | [diff] [blame] | 69 | SimpleBinding(static_cast<const BINDABLE &>(image_state)) || image_state.IsSwapchainImage() || image_state.bind_swapchain; |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 70 | |
| 71 | // If it's not simple we must have an encoder. |
| 72 | assert(!simple || image_state.fragment_encoder.get()); |
| 73 | return simple; |
| 74 | } |
| 75 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 76 | static const ResourceAccessRange kFullRange(std::numeric_limits<VkDeviceSize>::min(), std::numeric_limits<VkDeviceSize>::max()); |
| 77 | static const std::array<AccessAddressType, static_cast<size_t>(AccessAddressType::kTypeCount)> kAddressTypes = { |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 78 | AccessAddressType::kLinear, AccessAddressType::kIdealized}; |
| 79 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 80 | static constexpr AccessAddressType GetAccessAddressType(const BUFFER_STATE &) { return AccessAddressType::kLinear; }; |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 81 | static AccessAddressType GetAccessAddressType(const IMAGE_STATE &image) { |
| 82 | return SimpleBinding(image) ? AccessContext::ImageAddressType(image) : AccessAddressType::kIdealized; |
| 83 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 84 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 85 | static const char *string_SyncHazardVUID(SyncHazard hazard) { |
| 86 | switch (hazard) { |
| 87 | case SyncHazard::NONE: |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 88 | return "SYNC-HAZARD-NONE"; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 89 | break; |
| 90 | case SyncHazard::READ_AFTER_WRITE: |
| 91 | return "SYNC-HAZARD-READ_AFTER_WRITE"; |
| 92 | break; |
| 93 | case SyncHazard::WRITE_AFTER_READ: |
| 94 | return "SYNC-HAZARD-WRITE_AFTER_READ"; |
| 95 | break; |
| 96 | case SyncHazard::WRITE_AFTER_WRITE: |
| 97 | return "SYNC-HAZARD-WRITE_AFTER_WRITE"; |
| 98 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 99 | case SyncHazard::READ_RACING_WRITE: |
| 100 | return "SYNC-HAZARD-READ-RACING-WRITE"; |
| 101 | break; |
| 102 | case SyncHazard::WRITE_RACING_WRITE: |
| 103 | return "SYNC-HAZARD-WRITE-RACING-WRITE"; |
| 104 | break; |
| 105 | case SyncHazard::WRITE_RACING_READ: |
| 106 | return "SYNC-HAZARD-WRITE-RACING-READ"; |
| 107 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 108 | default: |
| 109 | assert(0); |
| 110 | } |
| 111 | return "SYNC-HAZARD-INVALID"; |
| 112 | } |
| 113 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 114 | static bool IsHazardVsRead(SyncHazard hazard) { |
| 115 | switch (hazard) { |
| 116 | case SyncHazard::NONE: |
| 117 | return false; |
| 118 | break; |
| 119 | case SyncHazard::READ_AFTER_WRITE: |
| 120 | return false; |
| 121 | break; |
| 122 | case SyncHazard::WRITE_AFTER_READ: |
| 123 | return true; |
| 124 | break; |
| 125 | case SyncHazard::WRITE_AFTER_WRITE: |
| 126 | return false; |
| 127 | break; |
| 128 | case SyncHazard::READ_RACING_WRITE: |
| 129 | return false; |
| 130 | break; |
| 131 | case SyncHazard::WRITE_RACING_WRITE: |
| 132 | return false; |
| 133 | break; |
| 134 | case SyncHazard::WRITE_RACING_READ: |
| 135 | return true; |
| 136 | break; |
| 137 | default: |
| 138 | assert(0); |
| 139 | } |
| 140 | return false; |
| 141 | } |
| 142 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 143 | static const char *string_SyncHazard(SyncHazard hazard) { |
| 144 | switch (hazard) { |
| 145 | case SyncHazard::NONE: |
| 146 | return "NONR"; |
| 147 | break; |
| 148 | case SyncHazard::READ_AFTER_WRITE: |
| 149 | return "READ_AFTER_WRITE"; |
| 150 | break; |
| 151 | case SyncHazard::WRITE_AFTER_READ: |
| 152 | return "WRITE_AFTER_READ"; |
| 153 | break; |
| 154 | case SyncHazard::WRITE_AFTER_WRITE: |
| 155 | return "WRITE_AFTER_WRITE"; |
| 156 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 157 | case SyncHazard::READ_RACING_WRITE: |
| 158 | return "READ_RACING_WRITE"; |
| 159 | break; |
| 160 | case SyncHazard::WRITE_RACING_WRITE: |
| 161 | return "WRITE_RACING_WRITE"; |
| 162 | break; |
| 163 | case SyncHazard::WRITE_RACING_READ: |
| 164 | return "WRITE_RACING_READ"; |
| 165 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 166 | default: |
| 167 | assert(0); |
| 168 | } |
| 169 | return "INVALID HAZARD"; |
| 170 | } |
| 171 | |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 172 | static const SyncStageAccessInfoType *SyncStageAccessInfoFromMask(SyncStageAccessFlags flags) { |
| 173 | // Return the info for the first bit found |
| 174 | const SyncStageAccessInfoType *info = nullptr; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 175 | for (size_t i = 0; i < flags.size(); i++) { |
| 176 | if (flags.test(i)) { |
| 177 | info = &syncStageAccessInfoByStageAccessIndex[i]; |
| 178 | break; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | return info; |
| 182 | } |
| 183 | |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 184 | static std::string string_SyncStageAccessFlags(const SyncStageAccessFlags &flags, const char *sep = "|") { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 185 | std::string out_str; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 186 | if (flags.none()) { |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 187 | out_str = "0"; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 188 | } else { |
| 189 | for (size_t i = 0; i < syncStageAccessInfoByStageAccessIndex.size(); i++) { |
| 190 | const auto &info = syncStageAccessInfoByStageAccessIndex[i]; |
| 191 | if ((flags & info.stage_access_bit).any()) { |
| 192 | if (!out_str.empty()) { |
| 193 | out_str.append(sep); |
| 194 | } |
| 195 | out_str.append(info.name); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 196 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 197 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 198 | if (out_str.length() == 0) { |
| 199 | out_str.append("Unhandled SyncStageAccess"); |
| 200 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 201 | } |
| 202 | return out_str; |
| 203 | } |
| 204 | |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 205 | std::ostream &operator<<(std::ostream &out, const ResourceUsageRecord &record) { |
| 206 | out << "command: " << CommandTypeString(record.command); |
| 207 | out << ", seq_no: " << record.seq_num; |
| 208 | if (record.sub_command != 0) { |
| 209 | out << ", subcmd: " << record.sub_command; |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 210 | } |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 211 | return out; |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 212 | } |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 213 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 214 | static std::string string_UsageIndex(SyncStageAccessIndex usage_index) { |
| 215 | const char *stage_access_name = "INVALID_STAGE_ACCESS"; |
| 216 | if (usage_index < static_cast<SyncStageAccessIndex>(syncStageAccessInfoByStageAccessIndex.size())) { |
| 217 | stage_access_name = syncStageAccessInfoByStageAccessIndex[usage_index].name; |
| 218 | } |
| 219 | return std::string(stage_access_name); |
| 220 | } |
| 221 | |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 222 | struct SyncNodeFormatter { |
| 223 | const debug_report_data *report_data; |
| 224 | const BASE_NODE *node; |
| 225 | const char *label; |
| 226 | |
| 227 | SyncNodeFormatter(const SyncValidator &sync_state, const CMD_BUFFER_STATE *cb_state) |
| 228 | : report_data(sync_state.report_data), node(cb_state), label("command_buffer") {} |
| 229 | SyncNodeFormatter(const SyncValidator &sync_state, const QUEUE_STATE *q_state) |
| 230 | : report_data(sync_state.report_data), node(q_state), label("queue") {} |
| 231 | }; |
| 232 | |
| 233 | std::ostream &operator<<(std::ostream &out, const SyncNodeFormatter &formater) { |
| 234 | if (formater.node) { |
| 235 | out << ", " << formater.label << ": " << formater.report_data->FormatHandle(formater.node->Handle()).c_str(); |
| 236 | if (formater.node->Destroyed()) { |
| 237 | out << " (destroyed)"; |
| 238 | } |
| 239 | } else { |
| 240 | out << ", " << formater.label << ": null handle"; |
| 241 | } |
| 242 | return out; |
| 243 | } |
| 244 | |
| 245 | std::ostream &operator<<(std::ostream &out, const HazardResult &hazard) { |
| 246 | assert(hazard.usage_index < static_cast<SyncStageAccessIndex>(syncStageAccessInfoByStageAccessIndex.size())); |
| 247 | const auto &usage_info = syncStageAccessInfoByStageAccessIndex[hazard.usage_index]; |
| 248 | const auto *info = SyncStageAccessInfoFromMask(hazard.prior_access); |
| 249 | const char *stage_access_name = info ? info->name : "INVALID_STAGE_ACCESS"; |
| 250 | out << "("; |
| 251 | if (!hazard.recorded_access.get()) { |
| 252 | // if we have a recorded usage the usage is reported from the recorded contexts point of view |
| 253 | out << "usage: " << usage_info.name << ", "; |
| 254 | } |
| 255 | out << "prior_usage: " << stage_access_name; |
| 256 | if (IsHazardVsRead(hazard.hazard)) { |
| 257 | const auto barriers = hazard.access_state->GetReadBarriers(hazard.prior_access); |
| 258 | out << ", read_barriers: " << string_VkPipelineStageFlags2KHR(barriers); |
| 259 | } else { |
| 260 | SyncStageAccessFlags write_barrier = hazard.access_state->GetWriteBarriers(); |
| 261 | out << ", write_barriers: " << string_SyncStageAccessFlags(write_barrier); |
| 262 | } |
| 263 | return out; |
| 264 | } |
| 265 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 266 | struct NoopBarrierAction { |
| 267 | explicit NoopBarrierAction() {} |
| 268 | void operator()(ResourceAccessState *access) const {} |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 269 | const bool layout_transition = false; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 270 | }; |
| 271 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 272 | static void InitSubpassContexts(VkQueueFlags queue_flags, const RENDER_PASS_STATE &rp_state, const AccessContext *external_context, |
| 273 | std::vector<AccessContext> &subpass_contexts) { |
| 274 | const auto &create_info = rp_state.createInfo; |
| 275 | // Add this for all subpasses here so that they exsist during next subpass validation |
| 276 | subpass_contexts.clear(); |
| 277 | subpass_contexts.reserve(create_info.subpassCount); |
| 278 | for (uint32_t pass = 0; pass < create_info.subpassCount; pass++) { |
| 279 | subpass_contexts.emplace_back(pass, queue_flags, rp_state.subpass_dependencies, subpass_contexts, external_context); |
| 280 | } |
| 281 | } |
| 282 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 283 | // NOTE: Make sure the proxy doesn't outlive from, as the proxy is pointing directly to access contexts owned by from. |
| 284 | CommandBufferAccessContext::CommandBufferAccessContext(const CommandBufferAccessContext &from, AsProxyContext dummy) |
| 285 | : CommandBufferAccessContext(from.sync_state_) { |
| 286 | // Copy only the needed fields out of from for a temporary, proxy command buffer context |
| 287 | cb_state_ = from.cb_state_; |
| 288 | queue_flags_ = from.queue_flags_; |
| 289 | destroyed_ = from.destroyed_; |
| 290 | access_log_ = from.access_log_; // potentially large, but no choice given tagging lookup. |
| 291 | command_number_ = from.command_number_; |
| 292 | subcommand_number_ = from.subcommand_number_; |
| 293 | reset_count_ = from.reset_count_; |
| 294 | |
| 295 | const auto *from_context = from.GetCurrentAccessContext(); |
| 296 | assert(from_context); |
| 297 | |
| 298 | // Construct a fully resolved single access context out of from |
| 299 | const NoopBarrierAction noop_barrier; |
| 300 | for (AccessAddressType address_type : kAddressTypes) { |
| 301 | from_context->ResolveAccessRange(address_type, kFullRange, noop_barrier, |
| 302 | &cb_access_context_.GetAccessStateMap(address_type), nullptr); |
| 303 | } |
| 304 | // The proxy has flatten the current render pass context (if any), but the async contexts are needed for hazard detection |
| 305 | cb_access_context_.ImportAsyncContexts(*from_context); |
| 306 | |
| 307 | events_context_ = from.events_context_; |
| 308 | |
| 309 | // We don't want to copy the full render_pass_context_ history just for the proxy. |
| 310 | } |
| 311 | |
| 312 | std::string CommandBufferAccessContext::FormatUsage(const ResourceUsageTag tag) const { |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 313 | if (tag >= access_log_.size()) return std::string(); |
| 314 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 315 | std::stringstream out; |
| 316 | assert(tag < access_log_.size()); |
| 317 | const auto &record = access_log_[tag]; |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 318 | out << record; |
| 319 | if (cb_state_.get() != record.cb_state) { |
| 320 | out << SyncNodeFormatter(*sync_state_, record.cb_state); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 321 | } |
John Zulauf | d142c9a | 2022-04-12 14:22:44 -0600 | [diff] [blame] | 322 | out << ", reset_no: " << std::to_string(record.reset_count); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 323 | return out.str(); |
| 324 | } |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 325 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 326 | std::string CommandBufferAccessContext::FormatUsage(const ResourceFirstAccess &access) const { |
| 327 | std::stringstream out; |
| 328 | out << "(recorded_usage: " << string_UsageIndex(access.usage_index); |
| 329 | out << ", " << FormatUsage(access.tag) << ")"; |
| 330 | return out.str(); |
| 331 | } |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 332 | |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 333 | std::string CommandExecutionContext::FormatHazard(const HazardResult &hazard) const { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 334 | std::stringstream out; |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 335 | out << hazard; |
| 336 | out << ", " << FormatUsage(hazard.tag) << ")"; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 337 | return out.str(); |
| 338 | } |
| 339 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 340 | |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 341 | bool CommandExecutionContext::ValidForSyncOps() const { |
| 342 | bool valid = GetCurrentEventsContext() && GetCurrentAccessContext(); |
| 343 | assert(valid); |
| 344 | return valid; |
| 345 | } |
| 346 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 347 | // NOTE: the attachement read flag is put *only* in the access scope and not in the exect scope, since the ordering |
| 348 | // rules apply only to this specific access for this stage, and not the stage as a whole. The ordering detection |
| 349 | // also reflects this special case for read hazard detection (using access instead of exec scope) |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 350 | static constexpr VkPipelineStageFlags2KHR kColorAttachmentExecScope = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT_KHR; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 351 | static const SyncStageAccessFlags kColorAttachmentAccessScope = |
| 352 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_BIT | |
| 353 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT | |
| 354 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE_BIT | |
| 355 | SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT; // Note: this is intentionally not in the exec scope |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 356 | static constexpr VkPipelineStageFlags2KHR kDepthStencilAttachmentExecScope = |
| 357 | VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT_KHR | VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT_KHR; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 358 | static const SyncStageAccessFlags kDepthStencilAttachmentAccessScope = |
| 359 | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 360 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 361 | SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT; // Note: this is intentionally not in the exec scope |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 362 | static constexpr VkPipelineStageFlags2KHR kRasterAttachmentExecScope = kDepthStencilAttachmentExecScope | kColorAttachmentExecScope; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 363 | static const SyncStageAccessFlags kRasterAttachmentAccessScope = kDepthStencilAttachmentAccessScope | kColorAttachmentAccessScope; |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 364 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 365 | ResourceAccessState::OrderingBarriers ResourceAccessState::kOrderingRules = { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 366 | {{VK_PIPELINE_STAGE_2_NONE_KHR, SyncStageAccessFlags()}, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 367 | {kColorAttachmentExecScope, kColorAttachmentAccessScope}, |
| 368 | {kDepthStencilAttachmentExecScope, kDepthStencilAttachmentAccessScope}, |
| 369 | {kRasterAttachmentExecScope, kRasterAttachmentAccessScope}}}; |
| 370 | |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 371 | // Sometimes we have an internal access conflict, and we using the kInvalidTag to set and detect in temporary/proxy contexts |
| 372 | static const ResourceUsageTag kInvalidTag(ResourceUsageRecord::kMaxIndex); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 373 | |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 374 | static VkDeviceSize ResourceBaseAddress(const BINDABLE &bindable) { return bindable.GetFakeBaseAddress(); } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 375 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 376 | VkDeviceSize GetRealWholeSize(VkDeviceSize offset, VkDeviceSize size, VkDeviceSize whole_size) { |
locke-lunarg | 3c03800 | 2020-04-30 23:08:08 -0600 | [diff] [blame] | 377 | if (size == VK_WHOLE_SIZE) { |
| 378 | return (whole_size - offset); |
| 379 | } |
| 380 | return size; |
| 381 | } |
| 382 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 383 | static inline VkDeviceSize GetBufferWholeSize(const BUFFER_STATE &buf_state, VkDeviceSize offset, VkDeviceSize size) { |
| 384 | return GetRealWholeSize(offset, size, buf_state.createInfo.size); |
| 385 | } |
| 386 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 387 | template <typename T> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 388 | static ResourceAccessRange MakeRange(const T &has_offset_and_size) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 389 | return ResourceAccessRange(has_offset_and_size.offset, (has_offset_and_size.offset + has_offset_and_size.size)); |
| 390 | } |
| 391 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 392 | static ResourceAccessRange MakeRange(VkDeviceSize start, VkDeviceSize size) { return ResourceAccessRange(start, (start + size)); } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 393 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 394 | static inline ResourceAccessRange MakeRange(const BUFFER_STATE &buffer, VkDeviceSize offset, VkDeviceSize size) { |
| 395 | return MakeRange(offset, GetBufferWholeSize(buffer, offset, size)); |
| 396 | } |
| 397 | |
| 398 | static inline ResourceAccessRange MakeRange(const BUFFER_VIEW_STATE &buf_view_state) { |
| 399 | return MakeRange(*buf_view_state.buffer_state.get(), buf_view_state.create_info.offset, buf_view_state.create_info.range); |
| 400 | } |
| 401 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 402 | // Range generators for to allow event scope filtration to be limited to the top of the resource access traversal pipeline |
| 403 | // |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 404 | // Note: there is no "begin/end" or reset facility. These are each written as "one time through" generators. |
| 405 | // |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 406 | // Usage: |
| 407 | // Constructor() -- initializes the generator to point to the begin of the space declared. |
| 408 | // * -- the current range of the generator empty signfies end |
| 409 | // ++ -- advance to the next non-empty range (or end) |
| 410 | |
| 411 | // A wrapper for a single range with the same semantics as the actual generators below |
| 412 | template <typename KeyType> |
| 413 | class SingleRangeGenerator { |
| 414 | public: |
| 415 | SingleRangeGenerator(const KeyType &range) : current_(range) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 416 | const KeyType &operator*() const { return current_; } |
| 417 | const KeyType *operator->() const { return ¤t_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 418 | SingleRangeGenerator &operator++() { |
| 419 | current_ = KeyType(); // just one real range |
| 420 | return *this; |
| 421 | } |
| 422 | |
| 423 | bool operator==(const SingleRangeGenerator &other) const { return current_ == other.current_; } |
| 424 | |
| 425 | private: |
| 426 | SingleRangeGenerator() = default; |
| 427 | const KeyType range_; |
| 428 | KeyType current_; |
| 429 | }; |
| 430 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 431 | // Generate the ranges that are the intersection of range and the entries in the RangeMap |
| 432 | template <typename RangeMap, typename KeyType = typename RangeMap::key_type> |
| 433 | class MapRangesRangeGenerator { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 434 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 435 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 436 | MapRangesRangeGenerator() : range_(), map_(nullptr), map_pos_(), current_() { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 437 | // Default construction for KeyType *must* be empty range |
| 438 | assert(current_.empty()); |
| 439 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 440 | MapRangesRangeGenerator(const RangeMap &filter, const KeyType &range) : range_(range), map_(&filter), map_pos_(), current_() { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 441 | SeekBegin(); |
| 442 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 443 | MapRangesRangeGenerator(const MapRangesRangeGenerator &from) = default; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 444 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 445 | const KeyType &operator*() const { return current_; } |
| 446 | const KeyType *operator->() const { return ¤t_; } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 447 | MapRangesRangeGenerator &operator++() { |
| 448 | ++map_pos_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 449 | UpdateCurrent(); |
| 450 | return *this; |
| 451 | } |
| 452 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 453 | bool operator==(const MapRangesRangeGenerator &other) const { return current_ == other.current_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 454 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 455 | protected: |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 456 | void UpdateCurrent() { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 457 | if (map_pos_ != map_->cend()) { |
| 458 | current_ = range_ & map_pos_->first; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 459 | } else { |
| 460 | current_ = KeyType(); |
| 461 | } |
| 462 | } |
| 463 | void SeekBegin() { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 464 | map_pos_ = map_->lower_bound(range_); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 465 | UpdateCurrent(); |
| 466 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 467 | |
| 468 | // Adding this functionality here, to avoid gratuitous Base:: qualifiers in the derived class |
| 469 | // Note: Not exposed in this classes public interface to encourage using a consistent ++/empty generator semantic |
| 470 | template <typename Pred> |
| 471 | MapRangesRangeGenerator &PredicatedIncrement(Pred &pred) { |
| 472 | do { |
| 473 | ++map_pos_; |
| 474 | } while (map_pos_ != map_->cend() && map_pos_->first.intersects(range_) && !pred(map_pos_)); |
| 475 | UpdateCurrent(); |
| 476 | return *this; |
| 477 | } |
| 478 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 479 | const KeyType range_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 480 | const RangeMap *map_; |
| 481 | typename RangeMap::const_iterator map_pos_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 482 | KeyType current_; |
| 483 | }; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 484 | using SingleAccessRangeGenerator = SingleRangeGenerator<ResourceAccessRange>; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 485 | using EventSimpleRangeGenerator = MapRangesRangeGenerator<SyncEventState::ScopeMap>; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 486 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 487 | // Generate the ranges for entries meeting the predicate that are the intersection of range and the entries in the RangeMap |
| 488 | template <typename RangeMap, typename Predicate, typename KeyType = typename RangeMap::key_type> |
| 489 | class PredicatedMapRangesRangeGenerator : public MapRangesRangeGenerator<RangeMap, KeyType> { |
| 490 | public: |
| 491 | using Base = MapRangesRangeGenerator<RangeMap, KeyType>; |
| 492 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 493 | PredicatedMapRangesRangeGenerator() : Base(), pred_() {} |
| 494 | PredicatedMapRangesRangeGenerator(const RangeMap &filter, const KeyType &range, Predicate pred) |
| 495 | : Base(filter, range), pred_(pred) {} |
| 496 | PredicatedMapRangesRangeGenerator(const PredicatedMapRangesRangeGenerator &from) = default; |
| 497 | |
| 498 | PredicatedMapRangesRangeGenerator &operator++() { |
| 499 | Base::PredicatedIncrement(pred_); |
| 500 | return *this; |
| 501 | } |
| 502 | |
| 503 | protected: |
| 504 | Predicate pred_; |
| 505 | }; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 506 | |
| 507 | // Generate the ranges that are the intersection of the RangeGen ranges and the entries in the FilterMap |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 508 | // Templated to allow for different Range generators or map sources... |
| 509 | template <typename RangeMap, typename RangeGen, typename KeyType = typename RangeMap::key_type> |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 510 | class FilteredGeneratorGenerator { |
| 511 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 512 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 513 | FilteredGeneratorGenerator() : filter_(nullptr), gen_(), filter_pos_(), current_() { |
| 514 | // Default construction for KeyType *must* be empty range |
| 515 | assert(current_.empty()); |
| 516 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 517 | FilteredGeneratorGenerator(const RangeMap &filter, RangeGen &gen) : filter_(&filter), gen_(gen), filter_pos_(), current_() { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 518 | SeekBegin(); |
| 519 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 520 | FilteredGeneratorGenerator(const FilteredGeneratorGenerator &from) = default; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 521 | const KeyType &operator*() const { return current_; } |
| 522 | const KeyType *operator->() const { return ¤t_; } |
| 523 | FilteredGeneratorGenerator &operator++() { |
| 524 | KeyType gen_range = GenRange(); |
| 525 | KeyType filter_range = FilterRange(); |
| 526 | current_ = KeyType(); |
| 527 | while (gen_range.non_empty() && filter_range.non_empty() && current_.empty()) { |
| 528 | if (gen_range.end > filter_range.end) { |
| 529 | // if the generated range is beyond the filter_range, advance the filter range |
| 530 | filter_range = AdvanceFilter(); |
| 531 | } else { |
| 532 | gen_range = AdvanceGen(); |
| 533 | } |
| 534 | current_ = gen_range & filter_range; |
| 535 | } |
| 536 | return *this; |
| 537 | } |
| 538 | |
| 539 | bool operator==(const FilteredGeneratorGenerator &other) const { return current_ == other.current_; } |
| 540 | |
| 541 | private: |
| 542 | KeyType AdvanceFilter() { |
| 543 | ++filter_pos_; |
| 544 | auto filter_range = FilterRange(); |
| 545 | if (filter_range.valid()) { |
| 546 | FastForwardGen(filter_range); |
| 547 | } |
| 548 | return filter_range; |
| 549 | } |
| 550 | KeyType AdvanceGen() { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 551 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 552 | auto gen_range = GenRange(); |
| 553 | if (gen_range.valid()) { |
| 554 | FastForwardFilter(gen_range); |
| 555 | } |
| 556 | return gen_range; |
| 557 | } |
| 558 | |
| 559 | KeyType FilterRange() const { return (filter_pos_ != filter_->cend()) ? filter_pos_->first : KeyType(); } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 560 | KeyType GenRange() const { return *gen_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 561 | |
| 562 | KeyType FastForwardFilter(const KeyType &range) { |
| 563 | auto filter_range = FilterRange(); |
| 564 | int retry_count = 0; |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 565 | const static int kRetryLimit = 2; // TODO -- determine whether this limit is optimal |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 566 | while (!filter_range.empty() && (filter_range.end <= range.begin)) { |
| 567 | if (retry_count < kRetryLimit) { |
| 568 | ++filter_pos_; |
| 569 | filter_range = FilterRange(); |
| 570 | retry_count++; |
| 571 | } else { |
| 572 | // Okay we've tried walking, do a seek. |
| 573 | filter_pos_ = filter_->lower_bound(range); |
| 574 | break; |
| 575 | } |
| 576 | } |
| 577 | return FilterRange(); |
| 578 | } |
| 579 | |
| 580 | // TODO: Consider adding "seek" (or an absolute bound "get" to range generators to make this walk |
| 581 | // faster. |
| 582 | KeyType FastForwardGen(const KeyType &range) { |
| 583 | auto gen_range = GenRange(); |
| 584 | while (!gen_range.empty() && (gen_range.end <= range.begin)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 585 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 586 | gen_range = GenRange(); |
| 587 | } |
| 588 | return gen_range; |
| 589 | } |
| 590 | |
| 591 | void SeekBegin() { |
| 592 | auto gen_range = GenRange(); |
| 593 | if (gen_range.empty()) { |
| 594 | current_ = KeyType(); |
| 595 | filter_pos_ = filter_->cend(); |
| 596 | } else { |
| 597 | filter_pos_ = filter_->lower_bound(gen_range); |
| 598 | current_ = gen_range & FilterRange(); |
| 599 | } |
| 600 | } |
| 601 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 602 | const RangeMap *filter_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 603 | RangeGen gen_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 604 | typename RangeMap::const_iterator filter_pos_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 605 | KeyType current_; |
| 606 | }; |
| 607 | |
| 608 | using EventImageRangeGenerator = FilteredGeneratorGenerator<SyncEventState::ScopeMap, subresource_adapter::ImageRangeGenerator>; |
| 609 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 610 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 611 | ResourceAccessRange GetBufferRange(VkDeviceSize offset, VkDeviceSize buf_whole_size, uint32_t first_index, uint32_t count, |
| 612 | VkDeviceSize stride) { |
| 613 | VkDeviceSize range_start = offset + first_index * stride; |
| 614 | VkDeviceSize range_size = 0; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 615 | if (count == UINT32_MAX) { |
| 616 | range_size = buf_whole_size - range_start; |
| 617 | } else { |
| 618 | range_size = count * stride; |
| 619 | } |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 620 | return MakeRange(range_start, range_size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 621 | } |
| 622 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 623 | SyncStageAccessIndex GetSyncStageAccessIndexsByDescriptorSet(VkDescriptorType descriptor_type, const interface_var &descriptor_data, |
| 624 | VkShaderStageFlagBits stage_flag) { |
| 625 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 626 | assert(stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT); |
| 627 | return SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ; |
| 628 | } |
| 629 | auto stage_access = syncStageAccessMaskByShaderStage.find(stage_flag); |
| 630 | if (stage_access == syncStageAccessMaskByShaderStage.end()) { |
| 631 | assert(0); |
| 632 | } |
| 633 | if (descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) { |
| 634 | return stage_access->second.uniform_read; |
| 635 | } |
| 636 | |
| 637 | // If the desriptorSet is writable, we don't need to care SHADER_READ. SHADER_WRITE is enough. |
| 638 | // Because if write hazard happens, read hazard might or might not happen. |
| 639 | // But if write hazard doesn't happen, read hazard is impossible to happen. |
| 640 | if (descriptor_data.is_writable) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 641 | return stage_access->second.storage_write; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 642 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 643 | // TODO: sampled_read |
| 644 | return stage_access->second.storage_read; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 645 | } |
| 646 | |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 647 | bool IsImageLayoutDepthWritable(VkImageLayout image_layout) { |
| 648 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 649 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL || |
| 650 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) |
| 651 | ? true |
| 652 | : false; |
| 653 | } |
| 654 | |
| 655 | bool IsImageLayoutStencilWritable(VkImageLayout image_layout) { |
| 656 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 657 | image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL || |
| 658 | image_layout == VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL) |
| 659 | ? true |
| 660 | : false; |
| 661 | } |
| 662 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 663 | // Class AccessContext stores the state of accesses specific to a Command, Subpass, or Queue |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 664 | template <typename Action> |
| 665 | static void ApplyOverImageRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &subresource_range_arg, |
| 666 | Action &action) { |
| 667 | // At this point the "apply over range" logic only supports a single memory binding |
| 668 | if (!SimpleBinding(image_state)) return; |
| 669 | auto subresource_range = NormalizeSubresourceRange(image_state.createInfo, subresource_range_arg); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 670 | const auto base_address = ResourceBaseAddress(image_state); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 671 | subresource_adapter::ImageRangeGenerator range_gen(*image_state.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 672 | image_state.createInfo.extent, base_address, false); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 673 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 674 | action(*range_gen); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 678 | // Tranverse the attachment resolves for this a specific subpass, and do action() to them. |
| 679 | // Used by both validation and record operations |
| 680 | // |
| 681 | // The signature for Action() reflect the needs of both uses. |
| 682 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 683 | void ResolveOperation(Action &action, const RENDER_PASS_STATE &rp_state, const AttachmentViewGenVector &attachment_views, |
| 684 | uint32_t subpass) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 685 | const auto &rp_ci = rp_state.createInfo; |
| 686 | const auto *attachment_ci = rp_ci.pAttachments; |
| 687 | const auto &subpass_ci = rp_ci.pSubpasses[subpass]; |
| 688 | |
| 689 | // Color resolves -- require an inuse color attachment and a matching inuse resolve attachment |
| 690 | const auto *color_attachments = subpass_ci.pColorAttachments; |
| 691 | const auto *color_resolve = subpass_ci.pResolveAttachments; |
| 692 | if (color_resolve && color_attachments) { |
| 693 | for (uint32_t i = 0; i < subpass_ci.colorAttachmentCount; i++) { |
| 694 | const auto &color_attach = color_attachments[i].attachment; |
| 695 | const auto &resolve_attach = subpass_ci.pResolveAttachments[i].attachment; |
| 696 | if ((color_attach != VK_ATTACHMENT_UNUSED) && (resolve_attach != VK_ATTACHMENT_UNUSED)) { |
| 697 | action("color", "resolve read", color_attach, resolve_attach, attachment_views[color_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 698 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, |
| 699 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 700 | action("color", "resolve write", color_attach, resolve_attach, attachment_views[resolve_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 701 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 702 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | // Depth stencil resolve only if the extension is present |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 708 | const auto ds_resolve = LvlFindInChain<VkSubpassDescriptionDepthStencilResolve>(subpass_ci.pNext); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 709 | if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment && |
| 710 | (ds_resolve->pDepthStencilResolveAttachment->attachment != VK_ATTACHMENT_UNUSED) && subpass_ci.pDepthStencilAttachment && |
| 711 | (subpass_ci.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) { |
| 712 | const auto src_at = subpass_ci.pDepthStencilAttachment->attachment; |
| 713 | const auto src_ci = attachment_ci[src_at]; |
| 714 | // The formats are required to match so we can pick either |
| 715 | const bool resolve_depth = (ds_resolve->depthResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasDepth(src_ci.format); |
| 716 | const bool resolve_stencil = (ds_resolve->stencilResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasStencil(src_ci.format); |
| 717 | const auto dst_at = ds_resolve->pDepthStencilResolveAttachment->attachment; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 718 | |
| 719 | // Figure out which aspects are actually touched during resolve operations |
| 720 | const char *aspect_string = nullptr; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 721 | AttachmentViewGen::Gen gen_type = AttachmentViewGen::Gen::kRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 722 | if (resolve_depth && resolve_stencil) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 723 | aspect_string = "depth/stencil"; |
| 724 | } else if (resolve_depth) { |
| 725 | // Validate depth only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 726 | gen_type = AttachmentViewGen::Gen::kDepthOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 727 | aspect_string = "depth"; |
| 728 | } else if (resolve_stencil) { |
| 729 | // Validate all stencil only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 730 | gen_type = AttachmentViewGen::Gen::kStencilOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 731 | aspect_string = "stencil"; |
| 732 | } |
| 733 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 734 | if (aspect_string) { |
| 735 | action(aspect_string, "resolve read", src_at, dst_at, attachment_views[src_at], gen_type, |
| 736 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, SyncOrdering::kRaster); |
| 737 | action(aspect_string, "resolve write", src_at, dst_at, attachment_views[dst_at], gen_type, |
| 738 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | // Action for validating resolve operations |
| 744 | class ValidateResolveAction { |
| 745 | public: |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 746 | ValidateResolveAction(VkRenderPass render_pass, uint32_t subpass, const AccessContext &context, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 747 | const CommandExecutionContext &exec_context, CMD_TYPE cmd_type) |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 748 | : render_pass_(render_pass), |
| 749 | subpass_(subpass), |
| 750 | context_(context), |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 751 | exec_context_(exec_context), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 752 | cmd_type_(cmd_type), |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 753 | skip_(false) {} |
| 754 | void operator()(const char *aspect_name, const char *attachment_name, uint32_t src_at, uint32_t dst_at, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 755 | const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, |
| 756 | SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 757 | HazardResult hazard; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 758 | hazard = context_.DetectHazard(view_gen, gen_type, current_usage, ordering_rule); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 759 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 760 | skip_ |= exec_context_.GetSyncState().LogError( |
| 761 | render_pass_, string_SyncHazardVUID(hazard.hazard), |
| 762 | "%s: Hazard %s in subpass %" PRIu32 "during %s %s, from attachment %" PRIu32 " to resolve attachment %" PRIu32 |
| 763 | ". Access info %s.", |
| 764 | CommandTypeString(cmd_type_), string_SyncHazard(hazard.hazard), subpass_, aspect_name, attachment_name, src_at, |
| 765 | dst_at, exec_context_.FormatHazard(hazard).c_str()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | // Providing a mechanism for the constructing caller to get the result of the validation |
| 769 | bool GetSkip() const { return skip_; } |
| 770 | |
| 771 | private: |
| 772 | VkRenderPass render_pass_; |
| 773 | const uint32_t subpass_; |
| 774 | const AccessContext &context_; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 775 | const CommandExecutionContext &exec_context_; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 776 | CMD_TYPE cmd_type_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 777 | bool skip_; |
| 778 | }; |
| 779 | |
| 780 | // Update action for resolve operations |
| 781 | class UpdateStateResolveAction { |
| 782 | public: |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 783 | UpdateStateResolveAction(AccessContext &context, ResourceUsageTag tag) : context_(context), tag_(tag) {} |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 784 | void operator()(const char *, const char *, uint32_t, uint32_t, const AttachmentViewGen &view_gen, |
| 785 | AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 786 | // Ignores validation only arguments... |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 787 | context_.UpdateAccessState(view_gen, gen_type, current_usage, ordering_rule, tag_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | private: |
| 791 | AccessContext &context_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 792 | const ResourceUsageTag tag_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 793 | }; |
| 794 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 795 | void HazardResult::Set(const ResourceAccessState *access_state_, SyncStageAccessIndex usage_index_, SyncHazard hazard_, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 796 | const SyncStageAccessFlags &prior_, const ResourceUsageTag tag_) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 797 | access_state = layer_data::make_unique<const ResourceAccessState>(*access_state_); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 798 | usage_index = usage_index_; |
| 799 | hazard = hazard_; |
| 800 | prior_access = prior_; |
| 801 | tag = tag_; |
| 802 | } |
| 803 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 804 | void HazardResult::AddRecordedAccess(const ResourceFirstAccess &first_access) { |
| 805 | recorded_access = layer_data::make_unique<const ResourceFirstAccess>(first_access); |
| 806 | } |
| 807 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 808 | void AccessContext::DeleteAccess(const AddressRange &address) { GetAccessStateMap(address.type).erase_range(address.range); } |
| 809 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 810 | AccessContext::AccessContext(uint32_t subpass, VkQueueFlags queue_flags, |
| 811 | const std::vector<SubpassDependencyGraphNode> &dependencies, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 812 | const std::vector<AccessContext> &contexts, const AccessContext *external_context) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 813 | Reset(); |
| 814 | const auto &subpass_dep = dependencies[subpass]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 815 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 816 | prev_.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 817 | prev_by_subpass_.resize(subpass, nullptr); // Can't be more prevs than the subpass we're on |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 818 | for (const auto &prev_dep : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 819 | const auto prev_pass = prev_dep.first->pass; |
| 820 | const auto &prev_barriers = prev_dep.second; |
| 821 | assert(prev_dep.second.size()); |
| 822 | prev_.emplace_back(&contexts[prev_pass], queue_flags, prev_barriers); |
| 823 | prev_by_subpass_[prev_pass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 824 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 825 | |
| 826 | async_.reserve(subpass_dep.async.size()); |
| 827 | for (const auto async_subpass : subpass_dep.async) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 828 | async_.emplace_back(&contexts[async_subpass]); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 829 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 830 | if (has_barrier_from_external) { |
| 831 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 832 | prev_.emplace_back(external_context, queue_flags, subpass_dep.barrier_from_external); |
| 833 | src_external_ = &prev_.back(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 834 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 835 | if (subpass_dep.barrier_to_external.size()) { |
| 836 | dst_external_ = TrackBack(this, queue_flags, subpass_dep.barrier_to_external); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 837 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 838 | } |
| 839 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 840 | template <typename Detector> |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 841 | HazardResult AccessContext::DetectPreviousHazard(AccessAddressType type, Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 842 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 843 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 844 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 845 | |
| 846 | HazardResult hazard; |
| 847 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 848 | hazard = detector.Detect(prev); |
| 849 | } |
| 850 | return hazard; |
| 851 | } |
| 852 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 853 | template <typename Action> |
| 854 | void AccessContext::ForAll(Action &&action) { |
| 855 | for (const auto address_type : kAddressTypes) { |
| 856 | auto &accesses = GetAccessStateMap(address_type); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 857 | for (auto &access : accesses) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 858 | action(address_type, access); |
| 859 | } |
| 860 | } |
| 861 | } |
| 862 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 863 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 864 | // the DAG of the contexts (for example subpasses) |
| 865 | template <typename Detector> |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 866 | HazardResult AccessContext::DetectHazard(AccessAddressType type, Detector &detector, const ResourceAccessRange &range, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 867 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 868 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 869 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 870 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 871 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 872 | // so we'll check these first |
| 873 | for (const auto &async_context : async_) { |
| 874 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 875 | if (hazard.hazard) return hazard; |
| 876 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 877 | } |
| 878 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 879 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 880 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 881 | const auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 882 | const auto the_end = accesses.cend(); // End is not invalidated |
| 883 | auto pos = accesses.lower_bound(range); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 884 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 885 | |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 886 | while (pos != the_end && pos->first.begin < range.end) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 887 | // Cover any leading gap, or gap between entries |
| 888 | if (detect_prev) { |
| 889 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 890 | // Cover any leading gap, or gap between entries |
| 891 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 892 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 893 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 894 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 895 | if (hazard.hazard) return hazard; |
| 896 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 897 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 898 | gap.begin = pos->first.end; |
| 899 | } |
| 900 | |
| 901 | hazard = detector.Detect(pos); |
| 902 | if (hazard.hazard) return hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 903 | ++pos; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | if (detect_prev) { |
| 907 | // Detect in the trailing empty as needed |
| 908 | gap.end = range.end; |
| 909 | if (gap.non_empty()) { |
| 910 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 911 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | return hazard; |
| 915 | } |
| 916 | |
| 917 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 918 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 919 | HazardResult AccessContext::DetectAsyncHazard(AccessAddressType type, const Detector &detector, |
| 920 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 921 | auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 922 | auto pos = accesses.lower_bound(range); |
| 923 | const auto the_end = accesses.end(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 924 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 925 | HazardResult hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 926 | while (pos != the_end && pos->first.begin < range.end) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 927 | hazard = detector.DetectAsync(pos, start_tag_); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 928 | if (hazard.hazard) break; |
| 929 | ++pos; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 930 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 931 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 932 | return hazard; |
| 933 | } |
| 934 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 935 | struct ApplySubpassTransitionBarriersAction { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 936 | explicit ApplySubpassTransitionBarriersAction(const std::vector<SyncBarrier> &barriers_) : barriers(barriers_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 937 | void operator()(ResourceAccessState *access) const { |
| 938 | assert(access); |
| 939 | access->ApplyBarriers(barriers, true); |
| 940 | } |
| 941 | const std::vector<SyncBarrier> &barriers; |
| 942 | }; |
| 943 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 944 | struct QueueTagOffsetBarrierAction { |
| 945 | QueueTagOffsetBarrierAction(QueueId qid, ResourceUsageTag offset) : queue_id(qid), tag_offset(offset) {} |
| 946 | void operator()(ResourceAccessState *access) const { |
| 947 | access->OffsetTag(tag_offset); |
| 948 | access->SetQueueId(queue_id); |
| 949 | }; |
| 950 | QueueId queue_id; |
| 951 | ResourceUsageTag tag_offset; |
| 952 | }; |
| 953 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 954 | struct ApplyTrackbackStackAction { |
| 955 | explicit ApplyTrackbackStackAction(const std::vector<SyncBarrier> &barriers_, |
| 956 | const ResourceAccessStateFunction *previous_barrier_ = nullptr) |
| 957 | : barriers(barriers_), previous_barrier(previous_barrier_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 958 | void operator()(ResourceAccessState *access) const { |
| 959 | assert(access); |
| 960 | assert(!access->HasPendingState()); |
| 961 | access->ApplyBarriers(barriers, false); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 962 | // NOTE: We can use invalid tag, as these barriers do no include layout transitions (would assert in SetWrite) |
| 963 | access->ApplyPendingBarriers(kInvalidTag); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 964 | if (previous_barrier) { |
| 965 | assert(bool(*previous_barrier)); |
| 966 | (*previous_barrier)(access); |
| 967 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 968 | } |
| 969 | const std::vector<SyncBarrier> &barriers; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 970 | const ResourceAccessStateFunction *previous_barrier; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 971 | }; |
| 972 | |
| 973 | // Splits a single map entry into piece matching the entries in [first, last) the total range over [first, last) must be |
| 974 | // contained with entry. Entry must be an iterator pointing to dest, first and last must be iterators pointing to a |
| 975 | // *different* map from dest. |
| 976 | // Returns the position past the last resolved range -- the entry covering the remainder of entry->first not included in the |
| 977 | // range [first, last) |
| 978 | template <typename BarrierAction> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 979 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 980 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 981 | BarrierAction &barrier_action) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 982 | auto at = entry; |
| 983 | for (auto pos = first; pos != last; ++pos) { |
| 984 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 985 | assert(at->first.includes(pos->first)); |
| 986 | assert(at != dest->end()); |
| 987 | // Trim up at to the same size as the entry to resolve |
| 988 | at = sparse_container::split(at, *dest, pos->first); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 989 | auto access = pos->second; // intentional copy |
| 990 | barrier_action(&access); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 991 | at->second.Resolve(access); |
| 992 | ++at; // Go to the remaining unused section of entry |
| 993 | } |
| 994 | } |
| 995 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 996 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 997 | SyncBarrier merged = {}; |
| 998 | for (const auto &barrier : barriers) { |
| 999 | merged.Merge(barrier); |
| 1000 | } |
| 1001 | return merged; |
| 1002 | } |
| 1003 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1004 | template <typename BarrierAction> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1005 | void AccessContext::ResolveAccessRange(AccessAddressType type, const ResourceAccessRange &range, BarrierAction &barrier_action, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1006 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 1007 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 1008 | if (!range.non_empty()) return; |
| 1009 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1010 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 1011 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 1012 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1013 | if (current->pos_B->valid) { |
| 1014 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1015 | auto access = src_pos->second; // intentional copy |
| 1016 | barrier_action(&access); |
| 1017 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1018 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 1019 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 1020 | trimmed->second.Resolve(access); |
| 1021 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1022 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 1023 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current_range, access)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1024 | current.invalidate_A(inserted); // Update the parallel iterator to point at the insert segment |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1025 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1026 | } else { |
| 1027 | // we have to descend to fill this gap |
| 1028 | if (recur_to_infill) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1029 | ResourceAccessRange recurrence_range = current_range; |
| 1030 | // The current context is empty for the current range, so recur to fill the gap. |
| 1031 | // Since we will be recurring back up the DAG, expand the gap descent to cover the full range for which B |
| 1032 | // is not valid, to minimize that recurrence |
| 1033 | if (current->pos_B.at_end()) { |
| 1034 | // Do the remainder here.... |
| 1035 | recurrence_range.end = range.end; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1036 | } else { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1037 | // Recur only over the range until B becomes valid (within the limits of range). |
| 1038 | recurrence_range.end = std::min(range.end, current->pos_B->lower_bound->first.begin); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1039 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1040 | ResolvePreviousAccessStack(type, recurrence_range, resolve_map, infill_state, barrier_action); |
| 1041 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1042 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 1043 | // iterator of the outer while. |
| 1044 | |
| 1045 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 1046 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 1047 | // we stepped on the dest map |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1048 | const auto seek_to = recurrence_range.end - 1; // The subtraction is safe as range can't be empty (loop condition) |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1049 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1050 | current.seek(seek_to); |
| 1051 | } else if (!current->pos_A->valid && infill_state) { |
| 1052 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 1053 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 1054 | current.invalidate_A(inserted); // Update the parallel iterator to point at the correct segment after insert |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1055 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1056 | } |
ziga-lunarg | f0e27ad | 2022-03-28 00:44:12 +0200 | [diff] [blame] | 1057 | if (current->range.non_empty()) { |
| 1058 | ++current; |
| 1059 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1060 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1061 | |
| 1062 | // Infill if range goes passed both the current and resolve map prior contents |
| 1063 | if (recur_to_infill && (current->range.end < range.end)) { |
| 1064 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1065 | ResolvePreviousAccessStack<BarrierAction>(type, trailing_fill_range, resolve_map, infill_state, barrier_action); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1066 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1067 | } |
| 1068 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1069 | template <typename BarrierAction> |
| 1070 | void AccessContext::ResolvePreviousAccessStack(AccessAddressType type, const ResourceAccessRange &range, |
| 1071 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 1072 | const BarrierAction &previous_barrier) const { |
| 1073 | ResourceAccessStateFunction stacked_barrier(std::ref(previous_barrier)); |
| 1074 | ResolvePreviousAccess(type, range, descent_map, infill_state, &stacked_barrier); |
| 1075 | } |
| 1076 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1077 | void AccessContext::ResolvePreviousAccess(AccessAddressType type, const ResourceAccessRange &range, |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1078 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 1079 | const ResourceAccessStateFunction *previous_barrier) const { |
| 1080 | if (prev_.size() == 0) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1081 | if (range.non_empty() && infill_state) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1082 | // Fill the empty poritions of descent_map with the default_state with the barrier function applied (iff present) |
| 1083 | ResourceAccessState state_copy; |
| 1084 | if (previous_barrier) { |
| 1085 | assert(bool(*previous_barrier)); |
| 1086 | state_copy = *infill_state; |
| 1087 | (*previous_barrier)(&state_copy); |
| 1088 | infill_state = &state_copy; |
| 1089 | } |
| 1090 | sparse_container::update_range_value(*descent_map, range, *infill_state, |
| 1091 | sparse_container::value_precedence::prefer_dest); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1092 | } |
| 1093 | } else { |
| 1094 | // Look for something to fill the gap further along. |
| 1095 | for (const auto &prev_dep : prev_) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1096 | const ApplyTrackbackStackAction barrier_action(prev_dep.barriers, previous_barrier); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1097 | prev_dep.source_subpass->ResolveAccessRange(type, range, barrier_action, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1098 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1099 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1100 | } |
| 1101 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1102 | // Non-lazy import of all accesses, WaitEvents needs this. |
| 1103 | void AccessContext::ResolvePreviousAccesses() { |
| 1104 | ResourceAccessState default_state; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1105 | if (!prev_.size()) return; // If no previous contexts, nothing to do |
| 1106 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1107 | for (const auto address_type : kAddressTypes) { |
| 1108 | ResolvePreviousAccess(address_type, kFullRange, &GetAccessStateMap(address_type), &default_state); |
| 1109 | } |
| 1110 | } |
| 1111 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1112 | AccessAddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
| 1113 | return (image.fragment_encoder->IsLinearImage()) ? AccessAddressType::kLinear : AccessAddressType::kIdealized; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1114 | } |
| 1115 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1116 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1117 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_NONE_EXT) |
| 1118 | ? SYNC_ACCESS_INDEX_NONE |
| 1119 | : ((load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 1120 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1121 | return stage_access; |
| 1122 | } |
| 1123 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1124 | const auto stage_access = |
| 1125 | (load_op == VK_ATTACHMENT_LOAD_OP_NONE_EXT) |
| 1126 | ? SYNC_ACCESS_INDEX_NONE |
| 1127 | : ((load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 1128 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1129 | return stage_access; |
| 1130 | } |
| 1131 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1132 | // Caller must manage returned pointer |
| 1133 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1134 | uint32_t subpass, const AttachmentViewGenVector &attachment_views) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1135 | auto *proxy = new AccessContext(context); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1136 | proxy->UpdateAttachmentResolveAccess(rp_state, attachment_views, subpass, kInvalidTag); |
| 1137 | proxy->UpdateAttachmentStoreAccess(rp_state, attachment_views, subpass, kInvalidTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1138 | return proxy; |
| 1139 | } |
| 1140 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1141 | template <typename BarrierAction> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1142 | void AccessContext::ResolveAccessRange(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1143 | BarrierAction &barrier_action, ResourceAccessRangeMap *descent_map, |
| 1144 | const ResourceAccessState *infill_state) const { |
| 1145 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1146 | if (!attachment_gen) return; |
| 1147 | |
| 1148 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1149 | const AccessAddressType address_type = view_gen.GetAddressType(); |
| 1150 | for (; range_gen->non_empty(); ++range_gen) { |
| 1151 | ResolveAccessRange(address_type, *range_gen, barrier_action, descent_map, infill_state); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1152 | } |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 1153 | } |
| 1154 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 1155 | template <typename ResolveOp> |
| 1156 | void AccessContext::ResolveFromContext(ResolveOp &&resolve_op, const AccessContext &from_context, |
| 1157 | const ResourceAccessState *infill_state, bool recur_to_infill) { |
| 1158 | for (auto address_type : kAddressTypes) { |
| 1159 | from_context.ResolveAccessRange(address_type, kFullRange, resolve_op, &GetAccessStateMap(address_type), infill_state, |
| 1160 | recur_to_infill); |
| 1161 | } |
| 1162 | } |
| 1163 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1164 | // Layout transitions are handled as if the were occuring in the beginning of the next subpass |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1165 | bool AccessContext::ValidateLayoutTransitions(const CommandExecutionContext &exec_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1166 | const VkRect2D &render_area, uint32_t subpass, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1167 | const AttachmentViewGenVector &attachment_views, CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1168 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1169 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 1170 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 1171 | // those affects have not been recorded yet. |
| 1172 | // |
| 1173 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 1174 | // to apply and only copy then, if this proves a hot spot. |
| 1175 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 1176 | TrackBack proxy_track_back; |
| 1177 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1178 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 1179 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1180 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 1181 | |
| 1182 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1183 | assert(track_back); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1184 | if (prev_needs_proxy) { |
| 1185 | if (!proxy_for_prev) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1186 | proxy_for_prev.reset( |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1187 | CreateStoreResolveProxyContext(*track_back->source_subpass, rp_state, transition.prev_pass, attachment_views)); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1188 | proxy_track_back = *track_back; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1189 | proxy_track_back.source_subpass = proxy_for_prev.get(); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1190 | } |
| 1191 | track_back = &proxy_track_back; |
| 1192 | } |
| 1193 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1194 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1195 | const char *func_name = CommandTypeString(cmd_type); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1196 | if (hazard.tag == kInvalidTag) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1197 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1198 | rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1199 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1200 | " image layout transition (old_layout: %s, new_layout: %s) after store/resolve operation in subpass %" PRIu32, |
| 1201 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1202 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), transition.prev_pass); |
| 1203 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1204 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1205 | rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1206 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1207 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 1208 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1209 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1210 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1211 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | return skip; |
| 1215 | } |
| 1216 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1217 | bool AccessContext::ValidateLoadOperation(const CommandExecutionContext &exec_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1218 | const VkRect2D &render_area, uint32_t subpass, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1219 | const AttachmentViewGenVector &attachment_views, CMD_TYPE cmd_type) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1220 | bool skip = false; |
| 1221 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1222 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1223 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1224 | if (subpass == rp_state.attachment_first_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1225 | const auto &view_gen = attachment_views[i]; |
| 1226 | if (!view_gen.IsValid()) continue; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1227 | const auto &ci = attachment_ci[i]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1228 | |
| 1229 | // Need check in the following way |
| 1230 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 1231 | // vs. transition |
| 1232 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 1233 | // for each aspect loaded. |
| 1234 | |
| 1235 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1236 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1237 | const bool is_color = !(has_depth || has_stencil); |
| 1238 | |
| 1239 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1240 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1241 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1242 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1243 | const char *aspect = nullptr; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1244 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1245 | bool checked_stencil = false; |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1246 | if (is_color && (load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1247 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, load_index, SyncOrdering::kColorAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1248 | aspect = "color"; |
| 1249 | } else { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1250 | if (has_depth && (load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1251 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_index, |
| 1252 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1253 | aspect = "depth"; |
| 1254 | } |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1255 | if (!hazard.hazard && has_stencil && (stencil_load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1256 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, stencil_load_index, |
| 1257 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1258 | aspect = "stencil"; |
| 1259 | checked_stencil = true; |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1264 | const char *func_name = CommandTypeString(cmd_type); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1265 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1266 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1267 | if (hazard.tag == kInvalidTag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1268 | // Hazard vs. ILT |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1269 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1270 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1271 | " aspect %s during load with loadOp %s.", |
| 1272 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string); |
| 1273 | } else { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1274 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1275 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1276 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1277 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1278 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1279 | } |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | return skip; |
| 1284 | } |
| 1285 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1286 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 1287 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 1288 | // store is part of the same Next/End operation. |
| 1289 | // The latter is handled in layout transistion validation directly |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1290 | bool AccessContext::ValidateStoreOperation(const CommandExecutionContext &exec_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1291 | const VkRect2D &render_area, uint32_t subpass, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1292 | const AttachmentViewGenVector &attachment_views, CMD_TYPE cmd_type) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1293 | bool skip = false; |
| 1294 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1295 | |
| 1296 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1297 | if (subpass == rp_state.attachment_last_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1298 | const AttachmentViewGen &view_gen = attachment_views[i]; |
| 1299 | if (!view_gen.IsValid()) continue; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1300 | const auto &ci = attachment_ci[i]; |
| 1301 | |
| 1302 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1303 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 1304 | // sake, we treat DONT_CARE as writing. |
| 1305 | const bool has_depth = FormatHasDepth(ci.format); |
| 1306 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1307 | const bool is_color = !(has_depth || has_stencil); |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1308 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_EXT; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1309 | if (!has_stencil && !store_op_stores) continue; |
| 1310 | |
| 1311 | HazardResult hazard; |
| 1312 | const char *aspect = nullptr; |
| 1313 | bool checked_stencil = false; |
| 1314 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1315 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1316 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1317 | aspect = "color"; |
| 1318 | } else { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1319 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_EXT; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1320 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1321 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1322 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1323 | aspect = "depth"; |
| 1324 | } |
| 1325 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1326 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1327 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1328 | aspect = "stencil"; |
| 1329 | checked_stencil = true; |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | if (hazard.hazard) { |
| 1334 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 1335 | const char *const store_op_string = string_VkAttachmentStoreOp(checked_stencil ? ci.stencilStoreOp : ci.storeOp); |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1336 | skip |= exec_context.GetSyncState().LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1337 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1338 | " %s aspect during store with %s %s. Access info %s", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1339 | CommandTypeString(cmd_type), string_SyncHazard(hazard.hazard), subpass, |
| 1340 | i, aspect, op_type_string, store_op_string, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1341 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | return skip; |
| 1346 | } |
| 1347 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1348 | bool AccessContext::ValidateResolveOperations(const CommandExecutionContext &exec_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1349 | const VkRect2D &render_area, const AttachmentViewGenVector &attachment_views, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1350 | CMD_TYPE cmd_type, uint32_t subpass) const { |
| 1351 | ValidateResolveAction validate_action(rp_state.renderPass(), subpass, *this, exec_context, cmd_type); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1352 | ResolveOperation(validate_action, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1353 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1354 | } |
| 1355 | |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 1356 | void AccessContext::AddAsyncContext(const AccessContext *context) { async_.emplace_back(context); } |
| 1357 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1358 | class HazardDetector { |
| 1359 | SyncStageAccessIndex usage_index_; |
| 1360 | |
| 1361 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1362 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { return pos->second.DetectHazard(usage_index_); } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1363 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1364 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1365 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1366 | explicit HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1367 | }; |
| 1368 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1369 | class HazardDetectorWithOrdering { |
| 1370 | const SyncStageAccessIndex usage_index_; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1371 | const SyncOrdering ordering_rule_; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1372 | |
| 1373 | public: |
| 1374 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 1375 | return pos->second.DetectHazard(usage_index_, ordering_rule_, QueueSyncState::kQueueIdInvalid); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1376 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1377 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1378 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1379 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1380 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, SyncOrdering ordering) : usage_index_(usage), ordering_rule_(ordering) {} |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1381 | }; |
| 1382 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1383 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1384 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1385 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1386 | const auto base_address = ResourceBaseAddress(buffer); |
| 1387 | HazardDetector detector(usage_index); |
| 1388 | return DetectHazard(AccessAddressType::kLinear, detector, (range + base_address), DetectOptions::kDetectAll); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 1389 | } |
| 1390 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1391 | template <typename Detector> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1392 | HazardResult AccessContext::DetectHazard(Detector &detector, const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1393 | DetectOptions options) const { |
| 1394 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1395 | if (!attachment_gen) return HazardResult(); |
| 1396 | |
| 1397 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1398 | const auto address_type = view_gen.GetAddressType(); |
| 1399 | for (; range_gen->non_empty(); ++range_gen) { |
| 1400 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1401 | if (hazard.hazard) return hazard; |
| 1402 | } |
| 1403 | |
| 1404 | return HazardResult(); |
| 1405 | } |
| 1406 | |
| 1407 | template <typename Detector> |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1408 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1409 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1410 | const VkExtent3D &extent, bool is_depth_sliced, DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1411 | if (!SimpleBinding(image)) return HazardResult(); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1412 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1413 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1414 | base_address, is_depth_sliced); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1415 | const auto address_type = ImageAddressType(image); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1416 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1417 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1418 | if (hazard.hazard) return hazard; |
| 1419 | } |
| 1420 | return HazardResult(); |
| 1421 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1422 | template <typename Detector> |
| 1423 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1424 | const VkImageSubresourceRange &subresource_range, bool is_depth_sliced, |
| 1425 | DetectOptions options) const { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1426 | if (!SimpleBinding(image)) return HazardResult(); |
| 1427 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1428 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address, |
| 1429 | is_depth_sliced); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1430 | const auto address_type = ImageAddressType(image); |
| 1431 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1432 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1433 | if (hazard.hazard) return hazard; |
| 1434 | } |
| 1435 | return HazardResult(); |
| 1436 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1437 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1438 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1439 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1440 | const VkExtent3D &extent, bool is_depth_sliced) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1441 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1442 | subresource.layerCount}; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1443 | HazardDetector detector(current_usage); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1444 | return DetectHazard(detector, image, subresource_range, offset, extent, is_depth_sliced, DetectOptions::kDetectAll); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1448 | const VkImageSubresourceRange &subresource_range, bool is_depth_sliced) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1449 | HazardDetector detector(current_usage); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1450 | return DetectHazard(detector, image, subresource_range, is_depth_sliced, DetectOptions::kDetectAll); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1451 | } |
| 1452 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1453 | HazardResult AccessContext::DetectHazard(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1454 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) const { |
| 1455 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
| 1456 | return DetectHazard(detector, view_gen, gen_type, DetectOptions::kDetectAll); |
| 1457 | } |
| 1458 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1459 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1460 | const VkImageSubresourceRange &subresource_range, SyncOrdering ordering_rule, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1461 | const VkOffset3D &offset, const VkExtent3D &extent, bool is_depth_sliced) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1462 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1463 | return DetectHazard(detector, image, subresource_range, offset, extent, is_depth_sliced, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1464 | } |
| 1465 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1466 | class BarrierHazardDetector { |
| 1467 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1468 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1469 | SyncStageAccessFlags src_access_scope) |
| 1470 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1471 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1472 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 1473 | return pos->second.DetectBarrierHazard(usage_index_, QueueSyncState::kQueueIdInvalid, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1474 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1475 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1476 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1477 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | private: |
| 1481 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1482 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1483 | SyncStageAccessFlags src_access_scope_; |
| 1484 | }; |
| 1485 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1486 | class EventBarrierHazardDetector { |
| 1487 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1488 | EventBarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1489 | SyncStageAccessFlags src_access_scope, const SyncEventState::ScopeMap &event_scope, QueueId queue_id, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1490 | ResourceUsageTag scope_tag) |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1491 | : usage_index_(usage_index), |
| 1492 | src_exec_scope_(src_exec_scope), |
| 1493 | src_access_scope_(src_access_scope), |
| 1494 | event_scope_(event_scope), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1495 | scope_queue_id_(queue_id), |
| 1496 | scope_tag_(scope_tag), |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1497 | scope_pos_(event_scope.cbegin()), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1498 | scope_end_(event_scope.cend()) {} |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1499 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1500 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) { |
| 1501 | // Need to piece together coverage of pos->first range: |
| 1502 | // Copy the range as we'll be chopping it up as needed |
| 1503 | ResourceAccessRange range = pos->first; |
| 1504 | const ResourceAccessState &access = pos->second; |
| 1505 | HazardResult hazard; |
| 1506 | |
| 1507 | bool in_scope = AdvanceScope(range); |
| 1508 | bool unscoped_tested = false; |
| 1509 | while (in_scope && !hazard.IsHazard()) { |
| 1510 | if (range.begin < ScopeBegin()) { |
| 1511 | if (!unscoped_tested) { |
| 1512 | unscoped_tested = true; |
| 1513 | hazard = access.DetectHazard(usage_index_); |
| 1514 | } |
| 1515 | // Note: don't need to check for in_scope as AdvanceScope true means range and ScopeRange intersect. |
| 1516 | // Thus a [ ScopeBegin, range.end ) will be non-empty. |
| 1517 | range.begin = ScopeBegin(); |
| 1518 | } else { // in_scope implied that ScopeRange and range intersect |
| 1519 | hazard = access.DetectBarrierHazard(usage_index_, ScopeState(), src_exec_scope_, src_access_scope_, scope_queue_id_, |
| 1520 | scope_tag_); |
| 1521 | if (!hazard.IsHazard()) { |
| 1522 | range.begin = ScopeEnd(); |
| 1523 | in_scope = AdvanceScope(range); // contains a non_empty check |
| 1524 | } |
| 1525 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1526 | } |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1527 | if (range.non_empty() && !hazard.IsHazard() && !unscoped_tested) { |
| 1528 | hazard = access.DetectHazard(usage_index_); |
| 1529 | } |
| 1530 | return hazard; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1531 | } |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1532 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1533 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1534 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1535 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
| 1536 | } |
| 1537 | |
| 1538 | private: |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1539 | bool ScopeInvalid() const { return scope_pos_ == scope_end_; } |
| 1540 | bool ScopeValid() const { return !ScopeInvalid(); } |
| 1541 | void ScopeSeek(const ResourceAccessRange &range) { scope_pos_ = event_scope_.lower_bound(range); } |
| 1542 | |
| 1543 | // Hiding away the std::pair grunge... |
| 1544 | ResourceAddress ScopeBegin() const { return scope_pos_->first.begin; } |
| 1545 | ResourceAddress ScopeEnd() const { return scope_pos_->first.end; } |
| 1546 | const ResourceAccessRange &ScopeRange() const { return scope_pos_->first; } |
| 1547 | const ResourceAccessState &ScopeState() const { return scope_pos_->second; } |
| 1548 | |
| 1549 | bool AdvanceScope(const ResourceAccessRange &range) { |
| 1550 | // Note: non_empty is (valid && !empty), so don't change !non_empty to empty... |
| 1551 | if (!range.non_empty()) return false; |
| 1552 | if (ScopeInvalid()) return false; |
| 1553 | |
| 1554 | if (ScopeRange().strictly_less(range)) { |
| 1555 | ScopeSeek(range); |
| 1556 | } |
| 1557 | |
| 1558 | return ScopeValid() && ScopeRange().intersects(range); |
| 1559 | } |
| 1560 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1561 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1562 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1563 | SyncStageAccessFlags src_access_scope_; |
| 1564 | const SyncEventState::ScopeMap &event_scope_; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1565 | QueueId scope_queue_id_; |
| 1566 | const ResourceUsageTag scope_tag_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1567 | SyncEventState::ScopeMap::const_iterator scope_pos_; |
| 1568 | SyncEventState::ScopeMap::const_iterator scope_end_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1569 | }; |
| 1570 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1571 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range, |
| 1572 | VkPipelineStageFlags2KHR src_exec_scope, |
| 1573 | const SyncStageAccessFlags &src_access_scope, QueueId queue_id, |
| 1574 | const SyncEventState &sync_event, AccessContext::DetectOptions options) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1575 | // It's not particularly DRY to get the address type in this function as well as lower down, but we have to select the |
| 1576 | // first access scope map to use, and there's no easy way to plumb it in below. |
| 1577 | const auto address_type = ImageAddressType(image); |
| 1578 | const auto &event_scope = sync_event.FirstScope(address_type); |
| 1579 | |
| 1580 | EventBarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope, |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1581 | event_scope, queue_id, sync_event.first_scope_tag); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1582 | return DetectHazard(detector, image, subresource_range, false, options); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1585 | HazardResult AccessContext::DetectImageBarrierHazard(const AttachmentViewGen &view_gen, const SyncBarrier &barrier, |
| 1586 | DetectOptions options) const { |
| 1587 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, barrier.src_exec_scope.exec_scope, |
| 1588 | barrier.src_access_scope); |
| 1589 | return DetectHazard(detector, view_gen, AttachmentViewGen::Gen::kViewSubresource, options); |
| 1590 | } |
| 1591 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1592 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1593 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1594 | const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1595 | const DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1596 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1597 | return DetectHazard(detector, image, subresource_range, false, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1600 | HazardResult AccessContext::DetectImageBarrierHazard(const SyncImageMemoryBarrier &image_barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1601 | return DetectImageBarrierHazard(*image_barrier.image.get(), image_barrier.barrier.src_exec_scope.exec_scope, |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1602 | image_barrier.barrier.src_access_scope, image_barrier.range, kDetectAll); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1603 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1604 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1605 | template <typename Flags, typename Map> |
| 1606 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1607 | SyncStageAccessFlags scope = 0; |
| 1608 | for (const auto &bit_scope : map) { |
| 1609 | if (flag_mask < bit_scope.first) break; |
| 1610 | |
| 1611 | if (flag_mask & bit_scope.first) { |
| 1612 | scope |= bit_scope.second; |
| 1613 | } |
| 1614 | } |
| 1615 | return scope; |
| 1616 | } |
| 1617 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1618 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags2KHR stages) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1619 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1620 | } |
| 1621 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1622 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags2KHR accesses) { |
| 1623 | return AccessScopeImpl(sync_utils::ExpandAccessFlags(accesses), syncStageAccessMaskByAccessBit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1624 | } |
| 1625 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1626 | // Getting from stage mask and access mask to stage/access masks is something we need to be good at... |
| 1627 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags2KHR stages, VkAccessFlags2KHR accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1628 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1629 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1630 | // of the union of all stage/access types for all the stages and the same unions for the access mask... |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1631 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1632 | } |
| 1633 | |
| 1634 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1635 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1636 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1637 | // that do incrementalupdates |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1638 | assert(accesses); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1639 | auto pos = accesses->lower_bound(range); |
| 1640 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1641 | // The range is empty, fill it with a default value. |
| 1642 | pos = action.Infill(accesses, pos, range); |
| 1643 | } else if (range.begin < pos->first.begin) { |
| 1644 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1645 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1646 | } else if (pos->first.begin < range.begin) { |
| 1647 | // Trim the beginning if needed |
| 1648 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1649 | ++pos; |
| 1650 | } |
| 1651 | |
| 1652 | const auto the_end = accesses->end(); |
| 1653 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1654 | if (pos->first.end > range.end) { |
| 1655 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1656 | } |
| 1657 | |
| 1658 | pos = action(accesses, pos); |
| 1659 | if (pos == the_end) break; |
| 1660 | |
| 1661 | auto next = pos; |
| 1662 | ++next; |
| 1663 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1664 | // Need to infill if next is disjoint |
| 1665 | VkDeviceSize limit = (next == the_end) ? range.end : std::min(range.end, next->first.begin); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1666 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1667 | next = action.Infill(accesses, next, new_range); |
| 1668 | } |
| 1669 | pos = next; |
| 1670 | } |
| 1671 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1672 | |
| 1673 | // Give a comparable interface for range generators and ranges |
| 1674 | template <typename Action> |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 1675 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, ResourceAccessRange *range) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1676 | assert(range); |
| 1677 | UpdateMemoryAccessState(accesses, *range, action); |
| 1678 | } |
| 1679 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1680 | template <typename Action, typename RangeGen> |
| 1681 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, RangeGen *range_gen_arg) { |
| 1682 | assert(range_gen_arg); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1683 | RangeGen &range_gen = *range_gen_arg; // Non-const references must be * by style requirement but deref-ing * iterator is a pain |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1684 | for (; range_gen->non_empty(); ++range_gen) { |
| 1685 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1686 | } |
| 1687 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1688 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1689 | template <typename Action, typename RangeGen> |
| 1690 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, const RangeGen &range_gen_prebuilt) { |
| 1691 | RangeGen range_gen(range_gen_prebuilt); // RangeGenerators can be expensive to create from scratch... initialize from built |
| 1692 | for (; range_gen->non_empty(); ++range_gen) { |
| 1693 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1694 | } |
| 1695 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1696 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1697 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1698 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1699 | // this is only called on gaps, and never returns a gap. |
| 1700 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1701 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1702 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1703 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1704 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1705 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1706 | auto &access_state = pos->second; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1707 | access_state.Update(usage, ordering_rule, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1708 | return pos; |
| 1709 | } |
| 1710 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1711 | UpdateMemoryAccessStateFunctor(AccessAddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1712 | SyncOrdering ordering_rule_, ResourceUsageTag tag_) |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1713 | : type(type_), context(context_), usage(usage_), ordering_rule(ordering_rule_), tag(tag_) {} |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1714 | const AccessAddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1715 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1716 | const SyncStageAccessIndex usage; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1717 | const SyncOrdering ordering_rule; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1718 | const ResourceUsageTag tag; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1719 | }; |
| 1720 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1721 | // The barrier operation for pipeline and subpass dependencies` |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1722 | struct PipelineBarrierOp { |
| 1723 | SyncBarrier barrier; |
| 1724 | bool layout_transition; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1725 | ResourceAccessState::QueueScopeOps scope; |
| 1726 | PipelineBarrierOp(QueueId queue_id, const SyncBarrier &barrier_, bool layout_transition_) |
| 1727 | : barrier(barrier_), layout_transition(layout_transition_), scope(queue_id) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1728 | PipelineBarrierOp(const PipelineBarrierOp &) = default; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1729 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(scope, barrier, layout_transition); } |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1730 | }; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1731 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 1732 | // Batch barrier ops don't modify in place, and thus don't need to hold pending state, and also are *never* layout transitions. |
| 1733 | struct BatchBarrierOp : public PipelineBarrierOp { |
| 1734 | void operator()(ResourceAccessState *access_state) const { |
| 1735 | access_state->ApplyBarrier(scope, barrier, layout_transition); |
| 1736 | access_state->ApplyPendingBarriers(kInvalidTag); // There can't be any need for this tag |
| 1737 | } |
| 1738 | BatchBarrierOp(QueueId queue_id, const SyncBarrier &barrier_) : PipelineBarrierOp(queue_id, barrier_, false) {} |
| 1739 | }; |
| 1740 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1741 | // The barrier operation for wait events |
| 1742 | struct WaitEventBarrierOp { |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 1743 | ResourceAccessState::EventScopeOps scope_ops; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1744 | SyncBarrier barrier; |
| 1745 | bool layout_transition; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1746 | |
| 1747 | WaitEventBarrierOp(const QueueId scope_queue_, const ResourceUsageTag scope_tag_, const SyncBarrier &barrier_, |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1748 | bool layout_transition_) |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1749 | : scope_ops(scope_queue_, scope_tag_), barrier(barrier_), layout_transition(layout_transition_) {} |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 1750 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(scope_ops, barrier, layout_transition); } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1751 | }; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1752 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1753 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1754 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1755 | // of a collection is known/present. |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1756 | template <typename BarrierOp, typename OpVector = std::vector<BarrierOp>> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1757 | class ApplyBarrierOpsFunctor { |
| 1758 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1759 | using Iterator = ResourceAccessRangeMap::iterator; |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1760 | // Only called with a gap, and pos at the lower_bound(range) |
| 1761 | inline Iterator Infill(ResourceAccessRangeMap *accesses, const Iterator &pos, const ResourceAccessRange &range) const { |
| 1762 | if (!infill_default_) { |
| 1763 | return pos; |
| 1764 | } |
| 1765 | ResourceAccessState default_state; |
| 1766 | auto inserted = accesses->insert(pos, std::make_pair(range, default_state)); |
| 1767 | return inserted; |
| 1768 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1769 | |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1770 | Iterator operator()(ResourceAccessRangeMap *accesses, const Iterator &pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1771 | auto &access_state = pos->second; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1772 | for (const auto &op : barrier_ops_) { |
| 1773 | op(&access_state); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1774 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1775 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1776 | if (resolve_) { |
| 1777 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1778 | // another walk |
| 1779 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1780 | } |
| 1781 | return pos; |
| 1782 | } |
| 1783 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1784 | // A valid tag is required IFF layout_transition is true, as transitions are write ops |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1785 | ApplyBarrierOpsFunctor(bool resolve, typename OpVector::size_type size_hint, ResourceUsageTag tag) |
| 1786 | : resolve_(resolve), infill_default_(false), barrier_ops_(), tag_(tag) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1787 | barrier_ops_.reserve(size_hint); |
| 1788 | } |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1789 | void EmplaceBack(const BarrierOp &op) { |
| 1790 | barrier_ops_.emplace_back(op); |
| 1791 | infill_default_ |= op.layout_transition; |
| 1792 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1793 | |
| 1794 | private: |
| 1795 | bool resolve_; |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1796 | bool infill_default_; |
| 1797 | OpVector barrier_ops_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1798 | const ResourceUsageTag tag_; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1799 | }; |
| 1800 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1801 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1802 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1803 | template <typename BarrierOp> |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1804 | class ApplyBarrierFunctor : public ApplyBarrierOpsFunctor<BarrierOp, small_vector<BarrierOp, 1>> { |
| 1805 | using Base = ApplyBarrierOpsFunctor<BarrierOp, small_vector<BarrierOp, 1>>; |
| 1806 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1807 | public: |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1808 | ApplyBarrierFunctor(const BarrierOp &barrier_op) : Base(false, 1, kInvalidTag) { Base::EmplaceBack(barrier_op); } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1809 | }; |
| 1810 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1811 | // This functor resolves the pendinging state. |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1812 | class ResolvePendingBarrierFunctor : public ApplyBarrierOpsFunctor<NoopBarrierAction, small_vector<NoopBarrierAction, 1>> { |
| 1813 | using Base = ApplyBarrierOpsFunctor<NoopBarrierAction, small_vector<NoopBarrierAction, 1>>; |
| 1814 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1815 | public: |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1816 | ResolvePendingBarrierFunctor(ResourceUsageTag tag) : Base(true, 0, tag) {} |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1817 | }; |
| 1818 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1819 | void AccessContext::UpdateAccessState(AccessAddressType type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1820 | const ResourceAccessRange &range, const ResourceUsageTag tag) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1821 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1822 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1823 | } |
| 1824 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1825 | void AccessContext::UpdateAccessState(const BUFFER_STATE &buffer, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1826 | const ResourceAccessRange &range, const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1827 | if (!SimpleBinding(buffer)) return; |
| 1828 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1829 | UpdateAccessState(AccessAddressType::kLinear, current_usage, ordering_rule, range + base_address, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1830 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1831 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1832 | void AccessContext::UpdateAccessState(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1833 | const VkImageSubresourceRange &subresource_range, const ResourceUsageTag &tag) { |
| 1834 | if (!SimpleBinding(image)) return; |
| 1835 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1836 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address, false); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1837 | const auto address_type = ImageAddressType(image); |
| 1838 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1839 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
| 1840 | } |
| 1841 | void AccessContext::UpdateAccessState(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1842 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1843 | const VkExtent3D &extent, const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1844 | if (!SimpleBinding(image)) return; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1845 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1846 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1847 | base_address, false); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1848 | const auto address_type = ImageAddressType(image); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1849 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1850 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1851 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1852 | |
| 1853 | void AccessContext::UpdateAccessState(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1854 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, const ResourceUsageTag tag) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1855 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1856 | if (!gen) return; |
| 1857 | subresource_adapter::ImageRangeGenerator range_gen(*gen); |
| 1858 | const auto address_type = view_gen.GetAddressType(); |
| 1859 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1860 | ApplyUpdateAction(address_type, action, &range_gen); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1861 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1862 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1863 | void AccessContext::UpdateAccessState(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1864 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1865 | const VkExtent3D &extent, const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1866 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1867 | subresource.layerCount}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1868 | UpdateAccessState(image, current_usage, ordering_rule, subresource_range, offset, extent, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1869 | } |
| 1870 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1871 | template <typename Action, typename RangeGen> |
| 1872 | void AccessContext::ApplyUpdateAction(AccessAddressType address_type, const Action &action, RangeGen *range_gen_arg) { |
| 1873 | assert(range_gen_arg); // Old Google C++ styleguide require non-const object pass by * not &, but this isn't an optional arg. |
| 1874 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, range_gen_arg); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1878 | void AccessContext::ApplyUpdateAction(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, const Action &action) { |
| 1879 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1880 | if (!gen) return; |
| 1881 | UpdateMemoryAccessState(&GetAccessStateMap(view_gen.GetAddressType()), action, *gen); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1882 | } |
| 1883 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1884 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, |
| 1885 | const AttachmentViewGenVector &attachment_views, uint32_t subpass, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1886 | const ResourceUsageTag tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1887 | UpdateStateResolveAction update(*this, tag); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1888 | ResolveOperation(update, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1889 | } |
| 1890 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1891 | void AccessContext::UpdateAttachmentStoreAccess(const RENDER_PASS_STATE &rp_state, const AttachmentViewGenVector &attachment_views, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1892 | uint32_t subpass, const ResourceUsageTag tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1893 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1894 | |
| 1895 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1896 | if (rp_state.attachment_last_subpass[i] == subpass) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1897 | const auto &view_gen = attachment_views[i]; |
| 1898 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1899 | |
| 1900 | const auto &ci = attachment_ci[i]; |
| 1901 | const bool has_depth = FormatHasDepth(ci.format); |
| 1902 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1903 | const bool is_color = !(has_depth || has_stencil); |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1904 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_EXT; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1905 | |
| 1906 | if (is_color && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1907 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1908 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1909 | } else { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1910 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1911 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1912 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1913 | } |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1914 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_EXT; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1915 | if (has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1916 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1917 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | } |
| 1923 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1924 | template <typename Action> |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1925 | void AccessContext::ApplyToContext(const Action &barrier_action) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1926 | // Note: Barriers do *not* cross context boundaries, applying to accessess within.... (at least for renderpass subpasses) |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1927 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1928 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), kFullRange, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1933 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1934 | auto &context = contexts[subpass_index]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1935 | ApplyTrackbackStackAction barrier_action(context.GetDstExternalTrackBack().barriers); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1936 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1937 | context.ResolveAccessRange(address_type, kFullRange, barrier_action, &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1938 | } |
| 1939 | } |
| 1940 | } |
| 1941 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 1942 | // Caller must ensure that lifespan of this is less than from |
| 1943 | void AccessContext::ImportAsyncContexts(const AccessContext &from) { async_ = from.async_; } |
| 1944 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1945 | // Suitable only for *subpass* access contexts |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1946 | HazardResult AccessContext::DetectSubpassTransitionHazard(const TrackBack &track_back, const AttachmentViewGen &attach_view) const { |
| 1947 | if (!attach_view.IsValid()) return HazardResult(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1948 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1949 | // We should never ask for a transition from a context we don't have |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1950 | assert(track_back.source_subpass); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1951 | |
| 1952 | // Do the detection against the specific prior context independent of other contexts. (Synchronous only) |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1953 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1954 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1955 | HazardResult hazard = track_back.source_subpass->DetectImageBarrierHazard(attach_view, merged_barrier, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1956 | if (!hazard.hazard) { |
| 1957 | // The Async hazard check is against the current context's async set. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1958 | hazard = DetectImageBarrierHazard(attach_view, merged_barrier, kDetectAsync); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1959 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1960 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1961 | return hazard; |
| 1962 | } |
| 1963 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1964 | void AccessContext::RecordLayoutTransitions(const RENDER_PASS_STATE &rp_state, uint32_t subpass, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1965 | const AttachmentViewGenVector &attachment_views, const ResourceUsageTag tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1966 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1967 | const ResourceAccessState empty_infill; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1968 | for (const auto &transition : transitions) { |
| 1969 | const auto prev_pass = transition.prev_pass; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1970 | const auto &view_gen = attachment_views[transition.attachment]; |
| 1971 | if (!view_gen.IsValid()) continue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1972 | |
| 1973 | const auto *trackback = GetTrackBackFromSubpass(prev_pass); |
| 1974 | assert(trackback); |
| 1975 | |
| 1976 | // Import the attachments into the current context |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1977 | const auto *prev_context = trackback->source_subpass; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1978 | assert(prev_context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1979 | const auto address_type = view_gen.GetAddressType(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1980 | auto &target_map = GetAccessStateMap(address_type); |
| 1981 | ApplySubpassTransitionBarriersAction barrier_action(trackback->barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1982 | prev_context->ResolveAccessRange(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action, &target_map, |
| 1983 | &empty_infill); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1984 | } |
| 1985 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1986 | // If there were no transitions skip this global map walk |
| 1987 | if (transitions.size()) { |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1988 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1989 | ApplyToContext(apply_pending_action); |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1990 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1991 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1992 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1993 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, CMD_TYPE cmd_type) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1994 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1995 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1996 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 1997 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1998 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1999 | return skip; |
| 2000 | } |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2001 | const char *caller_name = CommandTypeString(cmd_type); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2002 | |
| 2003 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 2004 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 2005 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2006 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 2007 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2008 | for (const auto &stage_state : pipe->stage_state) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2009 | const auto raster_state = pipe->RasterizationState(); |
| 2010 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && raster_state && raster_state->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 2011 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2012 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2013 | for (const auto &set_binding : stage_state.descriptor_uses) { |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 2014 | const auto *descriptor_set = (*per_sets)[set_binding.first.set].bound_descriptor_set.get(); |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 2015 | auto binding = descriptor_set->GetBinding(set_binding.first.binding); |
| 2016 | const auto descriptor_type = binding->type; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2017 | SyncStageAccessIndex sync_index = |
| 2018 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 2019 | |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 2020 | for (uint32_t index = 0; index < binding->count; index++) { |
| 2021 | const auto *descriptor = binding->GetDescriptor(index); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2022 | switch (descriptor->GetClass()) { |
| 2023 | case DescriptorClass::ImageSampler: |
| 2024 | case DescriptorClass::Image: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2025 | if (descriptor->Invalid()) { |
| 2026 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2027 | } |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2028 | |
| 2029 | // NOTE: ImageSamplerDescriptor inherits from ImageDescriptor, so this cast works for both types. |
| 2030 | const auto *image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 2031 | const auto *img_view_state = image_descriptor->GetImageViewState(); |
| 2032 | VkImageLayout image_layout = image_descriptor->GetImageLayout(); |
| 2033 | |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2034 | HazardResult hazard; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 2035 | // NOTE: 2D ImageViews of VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT Images are not allowed in |
| 2036 | // Descriptors, so we do not have to worry about depth slicing here. |
| 2037 | // See: VUID 00343 |
| 2038 | assert(!img_view_state->IsDepthSliced()); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2039 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2040 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2041 | |
| 2042 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 2043 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 2044 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2045 | // Input attachments are subject to raster ordering rules |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 2046 | hazard = |
| 2047 | current_context_->DetectHazard(*img_state, sync_index, subresource_range, SyncOrdering::kRaster, |
| 2048 | offset, extent, img_view_state->IsDepthSliced()); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2049 | } else { |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 2050 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
| 2051 | img_view_state->IsDepthSliced()); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2052 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2053 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 2054 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2055 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2056 | img_view_state->image_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2057 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 2058 | ", index %" PRIu32 ". Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2059 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2060 | sync_state_->report_data->FormatHandle(img_view_state->image_view()).c_str(), |
| 2061 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 2062 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2063 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 2064 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2065 | set_binding.first.binding, index, FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2066 | } |
| 2067 | break; |
| 2068 | } |
| 2069 | case DescriptorClass::TexelBuffer: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2070 | const auto *texel_descriptor = static_cast<const TexelDescriptor *>(descriptor); |
| 2071 | if (texel_descriptor->Invalid()) { |
| 2072 | continue; |
| 2073 | } |
| 2074 | const auto *buf_view_state = texel_descriptor->GetBufferViewState(); |
| 2075 | const auto *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2076 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2077 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 2078 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2079 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2080 | buf_view_state->buffer_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2081 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2082 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2083 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view()).c_str(), |
| 2084 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 2085 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2086 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2087 | string_VkDescriptorType(descriptor_type), set_binding.first.binding, index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2088 | FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2089 | } |
| 2090 | break; |
| 2091 | } |
| 2092 | case DescriptorClass::GeneralBuffer: { |
| 2093 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2094 | if (buffer_descriptor->Invalid()) { |
| 2095 | continue; |
| 2096 | } |
| 2097 | const auto *buf_state = buffer_descriptor->GetBufferState(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2098 | const ResourceAccessRange range = |
| 2099 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2100 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 2101 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2102 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2103 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2104 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2105 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2106 | sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 2107 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 2108 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2109 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2110 | string_VkDescriptorType(descriptor_type), set_binding.first.binding, index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2111 | FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2112 | } |
| 2113 | break; |
| 2114 | } |
| 2115 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2116 | default: |
| 2117 | break; |
| 2118 | } |
| 2119 | } |
| 2120 | } |
| 2121 | } |
| 2122 | return skip; |
| 2123 | } |
| 2124 | |
| 2125 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2126 | const ResourceUsageTag tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2127 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2128 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2129 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2130 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2131 | return; |
| 2132 | } |
| 2133 | |
| 2134 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 2135 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 2136 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2137 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 2138 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2139 | for (const auto &stage_state : pipe->stage_state) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2140 | const auto raster_state = pipe->RasterizationState(); |
| 2141 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && raster_state && raster_state->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 2142 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2143 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2144 | for (const auto &set_binding : stage_state.descriptor_uses) { |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 2145 | const auto *descriptor_set = (*per_sets)[set_binding.first.set].bound_descriptor_set.get(); |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 2146 | auto binding = descriptor_set->GetBinding(set_binding.first.binding); |
| 2147 | const auto descriptor_type = binding->type; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2148 | SyncStageAccessIndex sync_index = |
| 2149 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 2150 | |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 2151 | for (uint32_t i = 0; i < binding->count; i++) { |
| 2152 | const auto *descriptor = binding->GetDescriptor(i); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2153 | switch (descriptor->GetClass()) { |
| 2154 | case DescriptorClass::ImageSampler: |
| 2155 | case DescriptorClass::Image: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2156 | // NOTE: ImageSamplerDescriptor inherits from ImageDescriptor, so this cast works for both types. |
| 2157 | const auto *image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 2158 | if (image_descriptor->Invalid()) { |
| 2159 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2160 | } |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2161 | const auto *img_view_state = image_descriptor->GetImageViewState(); |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 2162 | // NOTE: 2D ImageViews of VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT Images are not allowed in |
| 2163 | // Descriptors, so we do not have to worry about depth slicing here. |
| 2164 | // See: VUID 00343 |
| 2165 | assert(!img_view_state->IsDepthSliced()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2166 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2167 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2168 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 2169 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 2170 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kRaster, |
| 2171 | img_view_state->normalized_subresource_range, offset, extent, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2172 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2173 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kNonAttachment, |
| 2174 | img_view_state->normalized_subresource_range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2175 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2176 | break; |
| 2177 | } |
| 2178 | case DescriptorClass::TexelBuffer: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2179 | const auto *texel_descriptor = static_cast<const TexelDescriptor *>(descriptor); |
| 2180 | if (texel_descriptor->Invalid()) { |
| 2181 | continue; |
| 2182 | } |
| 2183 | const auto *buf_view_state = texel_descriptor->GetBufferViewState(); |
| 2184 | const auto *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2185 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2186 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2187 | break; |
| 2188 | } |
| 2189 | case DescriptorClass::GeneralBuffer: { |
| 2190 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2191 | if (buffer_descriptor->Invalid()) { |
| 2192 | continue; |
| 2193 | } |
| 2194 | const auto *buf_state = buffer_descriptor->GetBufferState(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2195 | const ResourceAccessRange range = |
| 2196 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2197 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2198 | break; |
| 2199 | } |
| 2200 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2201 | default: |
| 2202 | break; |
| 2203 | } |
| 2204 | } |
| 2205 | } |
| 2206 | } |
| 2207 | } |
| 2208 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2209 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, CMD_TYPE cmd_type) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2210 | bool skip = false; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2211 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2212 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2213 | return skip; |
| 2214 | } |
| 2215 | |
| 2216 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2217 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2218 | const auto &binding_descriptions_size = pipe->vertex_input_state->binding_descriptions.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2219 | |
| 2220 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2221 | const auto &binding_description = pipe->vertex_input_state->binding_descriptions[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2222 | if (binding_description.binding < binding_buffers_size) { |
| 2223 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2224 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2225 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2226 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2227 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2228 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2229 | auto hazard = current_context_->DetectHazard(*buf_state, SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ, range); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2230 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2231 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2232 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for vertex %s in %s. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2233 | CommandTypeString(cmd_type), string_SyncHazard(hazard.hazard), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2234 | sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 2235 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | return skip; |
| 2240 | } |
| 2241 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2242 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag tag) { |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2243 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2244 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2245 | return; |
| 2246 | } |
| 2247 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2248 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2249 | const auto &binding_descriptions_size = pipe->vertex_input_state->binding_descriptions.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2250 | |
| 2251 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2252 | const auto &binding_description = pipe->vertex_input_state->binding_descriptions[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2253 | if (binding_description.binding < binding_buffers_size) { |
| 2254 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2255 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2256 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2257 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2258 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2259 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2260 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ, |
| 2261 | SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2262 | } |
| 2263 | } |
| 2264 | } |
| 2265 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2266 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, CMD_TYPE cmd_type) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2267 | bool skip = false; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2268 | if (cb_state_->index_buffer_binding.buffer_state == nullptr || cb_state_->index_buffer_binding.buffer_state->Destroyed()) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2269 | return skip; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2270 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2271 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2272 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2273 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2274 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2275 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2276 | auto hazard = current_context_->DetectHazard(*index_buf_state, SYNC_INDEX_INPUT_INDEX_READ, range); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2277 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2278 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2279 | index_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for index %s in %s. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2280 | CommandTypeString(cmd_type), string_SyncHazard(hazard.hazard), |
| 2281 | sync_state_->report_data->FormatHandle(index_buf_state->buffer()).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2282 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2286 | // We will detect more accurate range in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2287 | skip |= ValidateDrawVertex(UINT32_MAX, 0, cmd_type); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2288 | return skip; |
| 2289 | } |
| 2290 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2291 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag tag) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2292 | if (cb_state_->index_buffer_binding.buffer_state == nullptr || cb_state_->index_buffer_binding.buffer_state->Destroyed()) return; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2293 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2294 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2295 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2296 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2297 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2298 | current_context_->UpdateAccessState(*index_buf_state, SYNC_INDEX_INPUT_INDEX_READ, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2299 | |
| 2300 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2301 | // We will detect more accurate range in the future. |
| 2302 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 2303 | } |
| 2304 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2305 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(CMD_TYPE cmd_type) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2306 | bool skip = false; |
| 2307 | if (!current_renderpass_context_) return skip; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2308 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(GetExecutionContext(), *cb_state_.get(), cmd_type); |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2309 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2310 | } |
| 2311 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2312 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2313 | if (current_renderpass_context_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2314 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), tag); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2315 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2316 | } |
| 2317 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2318 | QueueId CommandBufferAccessContext::GetQueueId() const { return QueueSyncState::kQueueIdInvalid; } |
| 2319 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2320 | ResourceUsageTag CommandBufferAccessContext::RecordBeginRenderPass(CMD_TYPE cmd_type, const RENDER_PASS_STATE &rp_state, |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2321 | const VkRect2D &render_area, |
| 2322 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2323 | // Create an access context the current renderpass. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2324 | const auto barrier_tag = NextCommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
| 2325 | const auto load_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kLoadOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2326 | render_pass_contexts_.emplace_back(rp_state, render_area, GetQueueFlags(), attachment_views, &cb_access_context_); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2327 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2328 | current_renderpass_context_->RecordBeginRenderPass(barrier_tag, load_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2329 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2330 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2331 | } |
| 2332 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2333 | ResourceUsageTag CommandBufferAccessContext::RecordNextSubpass(const CMD_TYPE cmd_type) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2334 | assert(current_renderpass_context_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2335 | if (!current_renderpass_context_) return NextCommandTag(cmd_type); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2336 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2337 | auto store_tag = NextCommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kStoreOp); |
| 2338 | auto barrier_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
| 2339 | auto load_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kLoadOp); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2340 | |
| 2341 | current_renderpass_context_->RecordNextSubpass(store_tag, barrier_tag, load_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2342 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2343 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2344 | } |
| 2345 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2346 | ResourceUsageTag CommandBufferAccessContext::RecordEndRenderPass(const CMD_TYPE cmd_type) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2347 | assert(current_renderpass_context_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2348 | if (!current_renderpass_context_) return NextCommandTag(cmd_type); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2349 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2350 | auto store_tag = NextCommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kStoreOp); |
| 2351 | auto barrier_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2352 | |
| 2353 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, store_tag, barrier_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2354 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2355 | current_renderpass_context_ = nullptr; |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2356 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2357 | } |
| 2358 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2359 | void CommandBufferAccessContext::RecordDestroyEvent(VkEvent event) { |
| 2360 | // Erase is okay with the key not being |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 2361 | auto event_state = sync_state_->Get<EVENT_STATE>(event); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2362 | if (event_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 2363 | GetCurrentEventsContext()->Destroy(event_state.get()); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2364 | } |
| 2365 | } |
| 2366 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2367 | // The is the recorded cb context |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2368 | bool CommandBufferAccessContext::ValidateFirstUse(CommandExecutionContext &exec_context, const char *func_name, |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2369 | uint32_t index) const { |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2370 | if (!exec_context.ValidForSyncOps()) return false; |
| 2371 | |
| 2372 | const QueueId queue_id = exec_context.GetQueueId(); |
| 2373 | const ResourceUsageTag base_tag = exec_context.GetTagLimit(); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2374 | bool skip = false; |
| 2375 | ResourceUsageRange tag_range = {0, 0}; |
| 2376 | const AccessContext *recorded_context = GetCurrentAccessContext(); |
| 2377 | assert(recorded_context); |
| 2378 | HazardResult hazard; |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 2379 | ReplayGuard replay_guard(exec_context, *this); |
| 2380 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2381 | auto log_msg = [this](const HazardResult &hazard, const CommandExecutionContext &exec_context, const char *func_name, |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2382 | uint32_t index) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2383 | const auto handle = exec_context.Handle(); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2384 | const auto recorded_handle = cb_state_->commandBuffer(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2385 | const auto *report_data = sync_state_->report_data; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2386 | return sync_state_->LogError(handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2387 | "%s: Hazard %s for entry %" PRIu32 ", %s, Recorded access info %s. Access info %s.", func_name, |
| 2388 | string_SyncHazard(hazard.hazard), index, report_data->FormatHandle(recorded_handle).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2389 | FormatUsage(*hazard.recorded_access).c_str(), exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2390 | }; |
| 2391 | for (const auto &sync_op : sync_ops_) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2392 | // we update the range to any include layout transition first use writes, |
| 2393 | // as they are stored along with the source scope (as effective barrier) when recorded |
| 2394 | tag_range.end = sync_op.tag + 1; |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2395 | skip |= sync_op.sync_op->ReplayValidate(sync_op.tag, *this, base_tag, exec_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2396 | |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2397 | // We're allowing for the ReplayRecord to modify the exec_context (e.g. for Renderpass operations), so |
| 2398 | // we need to fetch the current access context each time |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 2399 | hazard = exec_context.DetectFirstUseHazard(tag_range); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2400 | if (hazard.hazard) { |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2401 | skip |= log_msg(hazard, exec_context, func_name, index); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2402 | } |
| 2403 | // NOTE: Add call to replay validate here when we add support for syncop with non-trivial replay |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2404 | // Record the barrier into the proxy context. |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2405 | sync_op.sync_op->ReplayRecord(exec_context, base_tag + sync_op.tag); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2406 | tag_range.begin = tag_range.end; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | // and anything after the last syncop |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2410 | tag_range.end = ResourceUsageRecord::kMaxIndex; |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2411 | hazard = recorded_context->DetectFirstUseHazard(queue_id, tag_range, *exec_context.GetCurrentAccessContext()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2412 | if (hazard.hazard) { |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2413 | skip |= log_msg(hazard, exec_context, func_name, index); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | return skip; |
| 2417 | } |
| 2418 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2419 | void CommandBufferAccessContext::RecordExecutedCommandBuffer(const CommandBufferAccessContext &recorded_cb_context) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2420 | const AccessContext *recorded_context = recorded_cb_context.GetCurrentAccessContext(); |
| 2421 | assert(recorded_context); |
| 2422 | |
| 2423 | // Just run through the barriers ignoring the usage from the recorded context, as Resolve will overwrite outdated state |
| 2424 | const ResourceUsageTag base_tag = GetTagLimit(); |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2425 | for (const auto &sync_op : recorded_cb_context.GetSyncOps()) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2426 | // we update the range to any include layout transition first use writes, |
| 2427 | // as they are stored along with the source scope (as effective barrier) when recorded |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2428 | sync_op.sync_op->ReplayRecord(*this, base_tag + sync_op.tag); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | ResourceUsageRange tag_range = ImportRecordedAccessLog(recorded_cb_context); |
| 2432 | assert(base_tag == tag_range.begin); // to ensure the to offset calculation agree |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 2433 | ResolveExecutedCommandBuffer(*recorded_context, tag_range.begin); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2434 | } |
| 2435 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 2436 | void CommandBufferAccessContext::ResolveExecutedCommandBuffer(const AccessContext &recorded_context, ResourceUsageTag offset) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2437 | auto tag_offset = [offset](ResourceAccessState *access) { access->OffsetTag(offset); }; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 2438 | GetCurrentAccessContext()->ResolveFromContext(tag_offset, recorded_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2439 | } |
| 2440 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 2441 | HazardResult CommandBufferAccessContext::DetectFirstUseHazard(const ResourceUsageRange &tag_range) { |
| 2442 | return current_replay_->GetCurrentAccessContext()->DetectFirstUseHazard(GetQueueId(), tag_range, *GetCurrentAccessContext()); |
| 2443 | } |
| 2444 | |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2445 | ResourceUsageRange CommandExecutionContext::ImportRecordedAccessLog(const CommandBufferAccessContext &recorded_context) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2446 | // The execution references ensure lifespan for the referenced child CB's... |
| 2447 | ResourceUsageRange tag_range(GetTagLimit(), 0); |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2448 | InsertRecordedAccessLogEntries(recorded_context); |
| 2449 | tag_range.end = GetTagLimit(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2450 | return tag_range; |
| 2451 | } |
| 2452 | |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2453 | void CommandBufferAccessContext::InsertRecordedAccessLogEntries(const CommandBufferAccessContext &recorded_context) { |
| 2454 | cbs_referenced_.emplace(recorded_context.GetCBStateShared()); |
| 2455 | access_log_.insert(access_log_.end(), recorded_context.access_log_.cbegin(), recorded_context.access_log_.end()); |
| 2456 | } |
| 2457 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2458 | ResourceUsageTag CommandBufferAccessContext::NextSubcommandTag(CMD_TYPE command, ResourceUsageRecord::SubcommandType subcommand) { |
| 2459 | ResourceUsageTag next = access_log_.size(); |
| 2460 | access_log_.emplace_back(command, command_number_, subcommand, ++subcommand_number_, cb_state_.get(), reset_count_); |
| 2461 | return next; |
| 2462 | } |
| 2463 | |
| 2464 | ResourceUsageTag CommandBufferAccessContext::NextCommandTag(CMD_TYPE command, ResourceUsageRecord::SubcommandType subcommand) { |
| 2465 | command_number_++; |
| 2466 | subcommand_number_ = 0; |
| 2467 | ResourceUsageTag next = access_log_.size(); |
| 2468 | access_log_.emplace_back(command, command_number_, subcommand, subcommand_number_, cb_state_.get(), reset_count_); |
| 2469 | return next; |
| 2470 | } |
| 2471 | |
| 2472 | ResourceUsageTag CommandBufferAccessContext::NextIndexedCommandTag(CMD_TYPE command, uint32_t index) { |
| 2473 | if (index == 0) { |
| 2474 | return NextCommandTag(command, ResourceUsageRecord::SubcommandType::kIndex); |
| 2475 | } |
| 2476 | return NextSubcommandTag(command, ResourceUsageRecord::SubcommandType::kIndex); |
| 2477 | } |
| 2478 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2479 | void CommandBufferAccessContext::RecordSyncOp(SyncOpPointer &&sync_op) { |
| 2480 | auto tag = sync_op->Record(this); |
| 2481 | // As renderpass operations can have side effects on the command buffer access context, |
| 2482 | // update the sync operation to record these if any. |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2483 | sync_ops_.emplace_back(tag, std::move(sync_op)); |
| 2484 | } |
| 2485 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2486 | class HazardDetectFirstUse { |
| 2487 | public: |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2488 | HazardDetectFirstUse(const ResourceAccessState &recorded_use, QueueId queue_id, const ResourceUsageRange &tag_range) |
| 2489 | : recorded_use_(recorded_use), queue_id_(queue_id), tag_range_(tag_range) {} |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2490 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2491 | return pos->second.DetectHazard(recorded_use_, queue_id_, tag_range_); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2492 | } |
| 2493 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
| 2494 | return pos->second.DetectAsyncHazard(recorded_use_, tag_range_, start_tag); |
| 2495 | } |
| 2496 | |
| 2497 | private: |
| 2498 | const ResourceAccessState &recorded_use_; |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2499 | const QueueId queue_id_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2500 | const ResourceUsageRange &tag_range_; |
| 2501 | }; |
| 2502 | |
| 2503 | // This is called with the *recorded* command buffers access context, with the *active* access context pass in, againsts which |
| 2504 | // hazards will be detected |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2505 | HazardResult AccessContext::DetectFirstUseHazard(QueueId queue_id, const ResourceUsageRange &tag_range, |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2506 | const AccessContext &access_context) const { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2507 | HazardResult hazard; |
| 2508 | for (const auto address_type : kAddressTypes) { |
| 2509 | const auto &recorded_access_map = GetAccessStateMap(address_type); |
| 2510 | for (const auto &recorded_access : recorded_access_map) { |
| 2511 | // Cull any entries not in the current tag range |
| 2512 | if (!recorded_access.second.FirstAccessInTagRange(tag_range)) continue; |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 2513 | HazardDetectFirstUse detector(recorded_access.second, queue_id, tag_range); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2514 | hazard = access_context.DetectHazard(address_type, detector, recorded_access.first, DetectOptions::kDetectAll); |
| 2515 | if (hazard.hazard) break; |
| 2516 | } |
| 2517 | } |
| 2518 | |
| 2519 | return hazard; |
| 2520 | } |
| 2521 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2522 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const CommandExecutionContext &exec_context, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2523 | const CMD_BUFFER_STATE &cmd_buffer, CMD_TYPE cmd_type) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2524 | bool skip = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2525 | const auto &sync_state = exec_context.GetSyncState(); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2526 | const auto *pipe = cmd_buffer.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2527 | if (!pipe) { |
| 2528 | return skip; |
| 2529 | } |
| 2530 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2531 | const auto raster_state = pipe->RasterizationState(); |
| 2532 | if (raster_state && raster_state->rasterizerDiscardEnable) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2533 | return skip; |
| 2534 | } |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2535 | const char *caller_name = CommandTypeString(cmd_type); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2536 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2537 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2538 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2539 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2540 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2541 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2542 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2543 | if (location >= subpass.colorAttachmentCount || |
| 2544 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2545 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2546 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2547 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2548 | if (!view_gen.IsValid()) continue; |
| 2549 | HazardResult hazard = |
| 2550 | current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2551 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2552 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2553 | const VkImageView view_handle = view_gen.GetViewState()->image_view(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2554 | skip |= sync_state.LogError(view_handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2555 | "%s: Hazard %s for %s in %s, Subpass #%d, and pColorAttachments #%d. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2556 | caller_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2557 | sync_state.report_data->FormatHandle(view_handle).c_str(), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2558 | sync_state.report_data->FormatHandle(cmd_buffer.commandBuffer()).c_str(), |
| 2559 | cmd_buffer.activeSubpass, location, exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2563 | |
| 2564 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2565 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2566 | const auto ds_state = pipe->DepthStencilState(); |
| 2567 | const uint32_t depth_stencil_attachment = GetSubpassDepthStencilAttachmentIndex(ds_state, subpass.pDepthStencilAttachment); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2568 | |
| 2569 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2570 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2571 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2572 | bool depth_write = false, stencil_write = false; |
| 2573 | |
| 2574 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2575 | if (!FormatIsStencilOnly(view_state.create_info.format) && ds_state->depthTestEnable && ds_state->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2576 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2577 | depth_write = true; |
| 2578 | } |
| 2579 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2580 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2581 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2582 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2583 | if (!FormatIsDepthOnly(view_state.create_info.format) && ds_state->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2584 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2585 | stencil_write = true; |
| 2586 | } |
| 2587 | |
| 2588 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2589 | if (depth_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2590 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2591 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2592 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2593 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2594 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2595 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2596 | "%s: Hazard %s for %s in %s, Subpass #%d, and depth part of pDepthStencilAttachment. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2597 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2598 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2599 | sync_state.report_data->FormatHandle(cmd_buffer.commandBuffer()).c_str(), cmd_buffer.activeSubpass, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2600 | exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2601 | } |
| 2602 | } |
| 2603 | if (stencil_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2604 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2605 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2606 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2607 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2608 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2609 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2610 | "%s: Hazard %s for %s in %s, Subpass #%d, and stencil part of pDepthStencilAttachment. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2611 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2612 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2613 | sync_state.report_data->FormatHandle(cmd_buffer.commandBuffer()).c_str(), cmd_buffer.activeSubpass, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2614 | exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2615 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2616 | } |
| 2617 | } |
| 2618 | return skip; |
| 2619 | } |
| 2620 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2621 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd_buffer, const ResourceUsageTag tag) { |
| 2622 | const auto *pipe = cmd_buffer.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2623 | if (!pipe) { |
| 2624 | return; |
| 2625 | } |
| 2626 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2627 | const auto *raster_state = pipe->RasterizationState(); |
| 2628 | if (raster_state && raster_state->rasterizerDiscardEnable) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2629 | return; |
| 2630 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2631 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2632 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2633 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2634 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2635 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2636 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2637 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2638 | if (location >= subpass.colorAttachmentCount || |
| 2639 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2640 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2641 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2642 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2643 | current_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2644 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment, |
| 2645 | tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2646 | } |
| 2647 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2648 | |
| 2649 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2650 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2651 | const auto *ds_state = pipe->DepthStencilState(); |
| 2652 | const uint32_t depth_stencil_attachment = GetSubpassDepthStencilAttachmentIndex(ds_state, subpass.pDepthStencilAttachment); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2653 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2654 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2655 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2656 | bool depth_write = false, stencil_write = false; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2657 | const bool has_depth = 0 != (view_state.normalized_subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 2658 | const bool has_stencil = 0 != (view_state.normalized_subresource_range.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2659 | |
| 2660 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2661 | if (has_depth && !FormatIsStencilOnly(view_state.create_info.format) && ds_state->depthTestEnable && |
| 2662 | ds_state->depthWriteEnable && IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2663 | depth_write = true; |
| 2664 | } |
| 2665 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2666 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2667 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2668 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2669 | if (has_stencil && !FormatIsDepthOnly(view_state.create_info.format) && ds_state->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2670 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2671 | stencil_write = true; |
| 2672 | } |
| 2673 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2674 | if (depth_write || stencil_write) { |
| 2675 | const auto ds_gentype = view_gen.GetDepthStencilRenderAreaGenType(depth_write, stencil_write); |
| 2676 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2677 | current_context.UpdateAccessState(view_gen, ds_gentype, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2678 | SyncOrdering::kDepthStencilAttachment, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2679 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2680 | } |
| 2681 | } |
| 2682 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2683 | bool RenderPassAccessContext::ValidateNextSubpass(const CommandExecutionContext &exec_context, CMD_TYPE cmd_type) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2684 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2685 | bool skip = false; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2686 | skip |= CurrentContext().ValidateResolveOperations(exec_context, *rp_state_, render_area_, attachment_views_, cmd_type, |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2687 | current_subpass_); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2688 | skip |= CurrentContext().ValidateStoreOperation(exec_context, *rp_state_, render_area_, current_subpass_, attachment_views_, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2689 | cmd_type); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2690 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2691 | const auto next_subpass = current_subpass_ + 1; |
ziga-lunarg | 31a3e77 | 2022-03-22 11:48:46 +0100 | [diff] [blame] | 2692 | if (next_subpass >= subpass_contexts_.size()) { |
| 2693 | return skip; |
| 2694 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2695 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2696 | skip |= |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2697 | next_context.ValidateLayoutTransitions(exec_context, *rp_state_, render_area_, next_subpass, attachment_views_, cmd_type); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2698 | if (!skip) { |
| 2699 | // To avoid complex (and buggy) duplication of the affect of layout transitions on load operations, we'll record them |
| 2700 | // on a copy of the (empty) next context. |
| 2701 | // Note: The resource access map should be empty so hopefully this copy isn't too horrible from a perf POV. |
| 2702 | AccessContext temp_context(next_context); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2703 | temp_context.RecordLayoutTransitions(*rp_state_, next_subpass, attachment_views_, kInvalidTag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2704 | skip |= |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2705 | temp_context.ValidateLoadOperation(exec_context, *rp_state_, render_area_, next_subpass, attachment_views_, cmd_type); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2706 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2707 | return skip; |
| 2708 | } |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2709 | bool RenderPassAccessContext::ValidateEndRenderPass(const CommandExecutionContext &exec_context, CMD_TYPE cmd_type) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2710 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2711 | bool skip = false; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2712 | skip |= CurrentContext().ValidateResolveOperations(exec_context, *rp_state_, render_area_, attachment_views_, cmd_type, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2713 | current_subpass_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2714 | skip |= CurrentContext().ValidateStoreOperation(exec_context, *rp_state_, render_area_, current_subpass_, attachment_views_, |
| 2715 | cmd_type); |
| 2716 | skip |= ValidateFinalSubpassLayoutTransitions(exec_context, cmd_type); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2717 | return skip; |
| 2718 | } |
| 2719 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2720 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy() const { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2721 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, attachment_views_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2722 | } |
| 2723 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2724 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const CommandExecutionContext &exec_context, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2725 | CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2726 | bool skip = false; |
| 2727 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2728 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2729 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2730 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2731 | // to apply and only copy then, if this proves a hot spot. |
| 2732 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2733 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2734 | // Validate the "finalLayout" transitions to external |
| 2735 | // Get them from where there we're hidding in the extra entry. |
| 2736 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2737 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2738 | const auto &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2739 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2740 | assert(trackback.source_subpass); // Transitions are given implicit transitions if the StateTracker is working correctly |
| 2741 | auto *context = trackback.source_subpass; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2742 | |
| 2743 | if (transition.prev_pass == current_subpass_) { |
| 2744 | if (!proxy_for_current) { |
| 2745 | // We haven't recorded resolve ofor the current_subpass, so we need to copy current and update it *as if* |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2746 | proxy_for_current.reset(CreateStoreResolveProxy()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2747 | } |
| 2748 | context = proxy_for_current.get(); |
| 2749 | } |
| 2750 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2751 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2752 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2753 | auto hazard = context->DetectImageBarrierHazard(view_gen, merged_barrier, AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2754 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2755 | const char *func_name = CommandTypeString(cmd_type); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2756 | if (hazard.tag == kInvalidTag) { |
| 2757 | // Hazard vs. ILT |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2758 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2759 | rp_state_->renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 2760 | "%s: Hazard %s vs. store/resolve operations in subpass %" PRIu32 " for attachment %" PRIu32 |
| 2761 | " final image layout transition (old_layout: %s, new_layout: %s).", |
| 2762 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2763 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout)); |
| 2764 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2765 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2766 | rp_state_->renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 2767 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
| 2768 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 2769 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2770 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2771 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2772 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2773 | } |
| 2774 | } |
| 2775 | return skip; |
| 2776 | } |
| 2777 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2778 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2779 | // Add layout transitions... |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2780 | subpass_contexts_[current_subpass_].RecordLayoutTransitions(*rp_state_, current_subpass_, attachment_views_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2781 | } |
| 2782 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2783 | void RenderPassAccessContext::RecordLoadOperations(const ResourceUsageTag tag) { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2784 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2785 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2786 | |
| 2787 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2788 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2789 | const AttachmentViewGen &view_gen = attachment_views_[i]; |
| 2790 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2791 | |
| 2792 | const auto &ci = attachment_ci[i]; |
| 2793 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2794 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2795 | const bool is_color = !(has_depth || has_stencil); |
| 2796 | |
| 2797 | if (is_color) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2798 | const SyncStageAccessIndex load_op = ColorLoadUsage(ci.loadOp); |
| 2799 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2800 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, load_op, |
| 2801 | SyncOrdering::kColorAttachment, tag); |
| 2802 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2803 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2804 | if (has_depth) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2805 | const SyncStageAccessIndex load_op = DepthStencilLoadUsage(ci.loadOp); |
| 2806 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2807 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_op, |
| 2808 | SyncOrdering::kDepthStencilAttachment, tag); |
| 2809 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2810 | } |
| 2811 | if (has_stencil) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2812 | const SyncStageAccessIndex load_op = DepthStencilLoadUsage(ci.stencilLoadOp); |
| 2813 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2814 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, load_op, |
| 2815 | SyncOrdering::kDepthStencilAttachment, tag); |
| 2816 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2817 | } |
| 2818 | } |
| 2819 | } |
| 2820 | } |
| 2821 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2822 | AttachmentViewGenVector RenderPassAccessContext::CreateAttachmentViewGen( |
| 2823 | const VkRect2D &render_area, const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
| 2824 | AttachmentViewGenVector view_gens; |
| 2825 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2826 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2827 | view_gens.reserve(attachment_views.size()); |
| 2828 | for (const auto *view : attachment_views) { |
| 2829 | view_gens.emplace_back(view, offset, extent); |
| 2830 | } |
| 2831 | return view_gens; |
| 2832 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2833 | RenderPassAccessContext::RenderPassAccessContext(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2834 | VkQueueFlags queue_flags, |
| 2835 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2836 | const AccessContext *external_context) |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2837 | : rp_state_(&rp_state), render_area_(render_area), current_subpass_(0U), attachment_views_() { |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 2838 | // Add this for all subpasses here so that they exist during next subpass validation |
| 2839 | InitSubpassContexts(queue_flags, rp_state, external_context, subpass_contexts_); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2840 | attachment_views_ = CreateAttachmentViewGen(render_area, attachment_views); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2841 | } |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2842 | void RenderPassAccessContext::RecordBeginRenderPass(const ResourceUsageTag barrier_tag, const ResourceUsageTag load_tag) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2843 | assert(0 == current_subpass_); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2844 | subpass_contexts_[current_subpass_].SetStartTag(barrier_tag); |
| 2845 | RecordLayoutTransitions(barrier_tag); |
| 2846 | RecordLoadOperations(load_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2847 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2848 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2849 | void RenderPassAccessContext::RecordNextSubpass(const ResourceUsageTag store_tag, const ResourceUsageTag barrier_tag, |
| 2850 | const ResourceUsageTag load_tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2851 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2852 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
| 2853 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2854 | |
ziga-lunarg | 31a3e77 | 2022-03-22 11:48:46 +0100 | [diff] [blame] | 2855 | if (current_subpass_ + 1 >= subpass_contexts_.size()) { |
| 2856 | return; |
| 2857 | } |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 2858 | // Move to the next sub-command for the new subpass. The resolve and store are logically part of the previous |
| 2859 | // subpass, so their tag needs to be different from the layout and load operations below. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2860 | current_subpass_++; |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2861 | subpass_contexts_[current_subpass_].SetStartTag(barrier_tag); |
| 2862 | RecordLayoutTransitions(barrier_tag); |
| 2863 | RecordLoadOperations(load_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2864 | } |
| 2865 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2866 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const ResourceUsageTag store_tag, |
| 2867 | const ResourceUsageTag barrier_tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2868 | // Add the resolve and store accesses |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2869 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
| 2870 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2871 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2872 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2873 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2874 | |
| 2875 | // Add the "finalLayout" transitions to external |
| 2876 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2877 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2878 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2879 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2880 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2881 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2882 | const AttachmentViewGen &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2883 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2884 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.source_subpass); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2885 | ApplyBarrierOpsFunctor<PipelineBarrierOp> barrier_action(true /* resolve */, last_trackback.barriers.size(), barrier_tag); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2886 | for (const auto &barrier : last_trackback.barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2887 | barrier_action.EmplaceBack(PipelineBarrierOp(QueueSyncState::kQueueIdInvalid, barrier, true)); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2888 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2889 | external_context->ApplyUpdateAction(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2890 | } |
| 2891 | } |
| 2892 | |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2893 | SyncExecScope SyncExecScope::MakeSrc(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param, |
| 2894 | const VkPipelineStageFlags2KHR disabled_feature_mask) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2895 | SyncExecScope result; |
| 2896 | result.mask_param = mask_param; |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2897 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags, disabled_feature_mask); |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2898 | result.exec_scope = sync_utils::WithEarlierPipelineStages(result.expanded_mask); |
Jeremy Gebben | 87fd042 | 2022-06-08 15:43:47 -0600 | [diff] [blame] | 2899 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2900 | return result; |
| 2901 | } |
| 2902 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2903 | SyncExecScope SyncExecScope::MakeDst(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2904 | SyncExecScope result; |
| 2905 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2906 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2907 | result.exec_scope = sync_utils::WithLaterPipelineStages(result.expanded_mask); |
Jeremy Gebben | 87fd042 | 2022-06-08 15:43:47 -0600 | [diff] [blame] | 2908 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2909 | return result; |
| 2910 | } |
| 2911 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 2912 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst) |
| 2913 | : src_exec_scope(src), src_access_scope(0), dst_exec_scope(dst), dst_access_scope(0) {} |
| 2914 | |
| 2915 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst, const SyncBarrier::AllAccess &) |
| 2916 | : src_exec_scope(src), src_access_scope(src.valid_accesses), dst_exec_scope(dst), dst_access_scope(src.valid_accesses) {} |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2917 | |
| 2918 | template <typename Barrier> |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 2919 | SyncBarrier::SyncBarrier(const Barrier &barrier, const SyncExecScope &src, const SyncExecScope &dst) |
| 2920 | : src_exec_scope(src), |
| 2921 | src_access_scope(SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask)), |
| 2922 | dst_exec_scope(dst), |
| 2923 | dst_access_scope(SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask)) {} |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2924 | |
| 2925 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &subpass) { |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2926 | const auto barrier = lvl_find_in_chain<VkMemoryBarrier2KHR>(subpass.pNext); |
| 2927 | if (barrier) { |
| 2928 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier->srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2929 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2930 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier->srcAccessMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2931 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2932 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier->dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2933 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2934 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier->dstAccessMask); |
| 2935 | |
| 2936 | } else { |
| 2937 | auto src = SyncExecScope::MakeSrc(queue_flags, subpass.srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2938 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2939 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, subpass.srcAccessMask); |
| 2940 | |
| 2941 | auto dst = SyncExecScope::MakeDst(queue_flags, subpass.dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2942 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2943 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, subpass.dstAccessMask); |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | template <typename Barrier> |
| 2948 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const Barrier &barrier) { |
| 2949 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 2950 | src_exec_scope = src.exec_scope; |
| 2951 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
| 2952 | |
| 2953 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2954 | dst_exec_scope = dst.exec_scope; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2955 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2956 | } |
| 2957 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2958 | // Apply a list of barriers, without resolving pending state, useful for subpass layout transitions |
| 2959 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2960 | const UntaggedScopeOps scope; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2961 | for (const auto &barrier : barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2962 | ApplyBarrier(scope, barrier, layout_transition); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2963 | } |
| 2964 | } |
| 2965 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2966 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2967 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2968 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2969 | void ResourceAccessState::ApplyBarriersImmediate(const std::vector<SyncBarrier> &barriers) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2970 | assert(!pending_layout_transition); // This should never be call in the middle of another barrier application |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2971 | assert(pending_write_barriers.none()); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2972 | assert(!pending_write_dep_chain); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2973 | const UntaggedScopeOps scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2974 | for (const auto &barrier : barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2975 | ApplyBarrier(scope, barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2976 | } |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2977 | ApplyPendingBarriers(kInvalidTag); // There can't be any need for this tag |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2978 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2979 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2980 | HazardResult hazard; |
| 2981 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2982 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2983 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2984 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2985 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2986 | } |
| 2987 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2988 | // Write operation: |
| 2989 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2990 | // If reads exists -- test only against them because either: |
| 2991 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2992 | // * the read weren't hazards, and thus if the write is safe w.r.t. the reads, no hazard vs. last_write is possible if |
| 2993 | // the current write happens after the reads, so just test the write against the reades |
| 2994 | // Otherwise test against last_write |
| 2995 | // |
| 2996 | // Look for casus belli for WAR |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2997 | if (last_reads.size()) { |
| 2998 | for (const auto &read_access : last_reads) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2999 | if (IsReadHazard(usage_stage, read_access)) { |
| 3000 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3001 | break; |
| 3002 | } |
| 3003 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3004 | } else if (last_write.any() && IsWriteHazard(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3005 | // Write-After-Write check -- if we have a previous write to test against |
| 3006 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3007 | } |
| 3008 | } |
| 3009 | return hazard; |
| 3010 | } |
| 3011 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3012 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrdering ordering_rule, |
| 3013 | QueueId queue_id) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3014 | const auto &ordering = GetOrderingRules(ordering_rule); |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3015 | return DetectHazard(usage_index, ordering, queue_id); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3016 | } |
| 3017 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3018 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const OrderingBarrier &ordering, |
| 3019 | QueueId queue_id) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 3020 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 3021 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3022 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3023 | const auto usage_stage = PipelineStageBit(usage_index); |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3024 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3025 | const bool last_write_is_ordered = (last_write & ordering.access_scope).any() && (write_queue == queue_id); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3026 | if (IsRead(usage_bit)) { |
| 3027 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 3028 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 3029 | if (is_raw_hazard) { |
| 3030 | // NOTE: we know last_write is non-zero |
| 3031 | // See if the ordering rules save us from the simple RAW check above |
| 3032 | // First check to see if the current usage is covered by the ordering rules |
| 3033 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 3034 | const bool usage_is_ordered = |
| 3035 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 3036 | if (usage_is_ordered) { |
| 3037 | // Now see of the most recent write (or a subsequent read) are ordered |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3038 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(queue_id, ordering)); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3039 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3040 | } |
| 3041 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3042 | if (is_raw_hazard) { |
| 3043 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 3044 | } |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 3045 | } else if (usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION) { |
| 3046 | // For Image layout transitions, the barrier represents the first synchronization/access scope of the layout transition |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3047 | return DetectBarrierHazard(usage_index, queue_id, ordering.exec_scope, ordering.access_scope); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3048 | } else { |
| 3049 | // Only check for WAW if there are no reads since last_write |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3050 | bool usage_write_is_ordered = (usage_bit & ordering.access_scope).any(); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3051 | if (last_reads.size()) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3052 | // Look for any WAR hazards outside the ordered set of stages |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3053 | VkPipelineStageFlags2KHR ordered_stages = 0; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3054 | if (usage_write_is_ordered) { |
| 3055 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3056 | ordered_stages = GetOrderedStages(queue_id, ordering); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3057 | } |
| 3058 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 3059 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3060 | for (const auto &read_access : last_reads) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3061 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 3062 | if (IsReadHazard(usage_stage, read_access)) { |
| 3063 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3064 | break; |
| 3065 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3066 | } |
| 3067 | } |
John Zulauf | 2a344ca | 2021-09-09 17:07:19 -0600 | [diff] [blame] | 3068 | } else if (last_write.any() && !(last_write_is_ordered && usage_write_is_ordered)) { |
| 3069 | bool ilt_ilt_hazard = false; |
| 3070 | if ((usage_index == SYNC_IMAGE_LAYOUT_TRANSITION) && (usage_bit == last_write)) { |
| 3071 | // ILT after ILT is a special case where we check the 2nd access scope of the first ILT against the first access |
| 3072 | // scope of the second ILT, which has been passed (smuggled?) in the ordering barrier |
| 3073 | ilt_ilt_hazard = !(write_barriers & ordering.access_scope).any(); |
| 3074 | } |
| 3075 | if (ilt_ilt_hazard || IsWriteHazard(usage_bit)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3076 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3077 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 3078 | } |
| 3079 | } |
| 3080 | return hazard; |
| 3081 | } |
| 3082 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3083 | HazardResult ResourceAccessState::DetectHazard(const ResourceAccessState &recorded_use, QueueId queue_id, |
| 3084 | const ResourceUsageRange &tag_range) const { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3085 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3086 | using Size = FirstAccesses::size_type; |
| 3087 | const auto &recorded_accesses = recorded_use.first_accesses_; |
| 3088 | Size count = recorded_accesses.size(); |
| 3089 | if (count) { |
| 3090 | const auto &last_access = recorded_accesses.back(); |
| 3091 | bool do_write_last = IsWrite(last_access.usage_index); |
| 3092 | if (do_write_last) --count; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3093 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3094 | for (Size i = 0; i < count; ++count) { |
| 3095 | const auto &first = recorded_accesses[i]; |
| 3096 | // Skip and quit logic |
| 3097 | if (first.tag < tag_range.begin) continue; |
| 3098 | if (first.tag >= tag_range.end) { |
| 3099 | do_write_last = false; // ignore last since we know it can't be in tag_range |
| 3100 | break; |
| 3101 | } |
| 3102 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3103 | hazard = DetectHazard(first.usage_index, first.ordering_rule, queue_id); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3104 | if (hazard.hazard) { |
| 3105 | hazard.AddRecordedAccess(first); |
| 3106 | break; |
| 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | if (do_write_last && tag_range.includes(last_access.tag)) { |
| 3111 | // Writes are a bit special... both for the "most recent" access logic, and layout transition specific logic |
| 3112 | OrderingBarrier barrier = GetOrderingRules(last_access.ordering_rule); |
| 3113 | if (last_access.usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION) { |
| 3114 | // Or in the layout first access scope as a barrier... IFF the usage is an ILT |
| 3115 | // this was saved off in the "apply barriers" logic to simplify ILT access checks as they straddle |
| 3116 | // the barrier that applies them |
| 3117 | barrier |= recorded_use.first_write_layout_ordering_; |
| 3118 | } |
| 3119 | // Any read stages present in the recorded context (this) are most recent to the write, and thus mask those stages in |
| 3120 | // the active context |
| 3121 | if (recorded_use.first_read_stages_) { |
| 3122 | // we need to ignore the first use read stage in the active context (so we add them to the ordering rule), |
| 3123 | // reads in the active context are not "most recent" as all recorded context operations are *after* them |
| 3124 | // This supresses only RAW checks for stages present in the recorded context, but not those only present in the |
| 3125 | // active context. |
| 3126 | barrier.exec_scope |= recorded_use.first_read_stages_; |
| 3127 | // if there are any first use reads, we suppress WAW by injecting the active context write in the ordering rule |
| 3128 | barrier.access_scope |= FlagBit(last_access.usage_index); |
| 3129 | } |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3130 | hazard = DetectHazard(last_access.usage_index, barrier, queue_id); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3131 | if (hazard.hazard) { |
| 3132 | hazard.AddRecordedAccess(last_access); |
| 3133 | } |
| 3134 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3135 | } |
| 3136 | return hazard; |
| 3137 | } |
| 3138 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3139 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3140 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index, const ResourceUsageTag start_tag) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3141 | HazardResult hazard; |
| 3142 | auto usage = FlagBit(usage_index); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 3143 | // Async checks need to not go back further than the start of the subpass, as we only want to find hazards between the async |
| 3144 | // subpasses. Anything older than that should have been checked at the start of each subpass, taking into account all of |
| 3145 | // the raster ordering rules. |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3146 | if (IsRead(usage)) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3147 | if (last_write.any() && (write_tag >= start_tag)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3148 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3149 | } |
| 3150 | } else { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3151 | if (last_write.any() && (write_tag >= start_tag)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3152 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3153 | } else if (last_reads.size() > 0) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 3154 | // Any reads during the other subpass will conflict with this write, so we need to check them all. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3155 | for (const auto &read_access : last_reads) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3156 | if (read_access.tag >= start_tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3157 | hazard.Set(this, usage_index, WRITE_RACING_READ, read_access.access, read_access.tag); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 3158 | break; |
| 3159 | } |
| 3160 | } |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3161 | } |
| 3162 | } |
| 3163 | return hazard; |
| 3164 | } |
| 3165 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3166 | HazardResult ResourceAccessState::DetectAsyncHazard(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range, |
| 3167 | ResourceUsageTag start_tag) const { |
| 3168 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3169 | for (const auto &first : recorded_use.first_accesses_) { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3170 | // Skip and quit logic |
| 3171 | if (first.tag < tag_range.begin) continue; |
| 3172 | if (first.tag >= tag_range.end) break; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3173 | |
| 3174 | hazard = DetectAsyncHazard(first.usage_index, start_tag); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3175 | if (hazard.hazard) { |
| 3176 | hazard.AddRecordedAccess(first); |
| 3177 | break; |
| 3178 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3179 | } |
| 3180 | return hazard; |
| 3181 | } |
| 3182 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3183 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, QueueId queue_id, |
| 3184 | VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3185 | const SyncStageAccessFlags &src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3186 | // Only supporting image layout transitions for now |
| 3187 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 3188 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3189 | // only test for WAW if there no intervening read operations. |
| 3190 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3191 | if (last_reads.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3192 | // Look at the reads if any |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3193 | for (const auto &read_access : last_reads) { |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3194 | if (read_access.IsReadBarrierHazard(queue_id, src_exec_scope)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3195 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3196 | break; |
| 3197 | } |
| 3198 | } |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3199 | } else if (last_write.any() && IsWriteBarrierHazard(queue_id, src_exec_scope, src_access_scope)) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3200 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3201 | } |
| 3202 | |
| 3203 | return hazard; |
| 3204 | } |
| 3205 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3206 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, const ResourceAccessState &scope_state, |
| 3207 | VkPipelineStageFlags2KHR src_exec_scope, |
| 3208 | const SyncStageAccessFlags &src_access_scope, QueueId event_queue, |
| 3209 | ResourceUsageTag event_tag) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3210 | // Only supporting image layout transitions for now |
| 3211 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 3212 | HazardResult hazard; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3213 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3214 | if ((write_tag >= event_tag) && last_write.any()) { |
| 3215 | // Any write after the event precludes the possibility of being in the first access scope for the layout transition |
| 3216 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3217 | } else { |
| 3218 | // only test for WAW if there no intervening read operations. |
| 3219 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 3220 | if (last_reads.size()) { |
| 3221 | // Look at the reads if any... if reads exist, they are either the reason the access is in the event |
| 3222 | // first scope, or they are a hazard. |
| 3223 | const ReadStates &scope_reads = scope_state.last_reads; |
| 3224 | const ReadStates::size_type scope_read_count = scope_reads.size(); |
| 3225 | // Since the hasn't been a write: |
| 3226 | // * The current read state is a superset of the scoped one |
| 3227 | // * The stage order is the same. |
| 3228 | assert(last_reads.size() >= scope_read_count); |
| 3229 | for (ReadStates::size_type read_idx = 0; read_idx < scope_read_count; ++read_idx) { |
| 3230 | const ReadState &scope_read = scope_reads[read_idx]; |
| 3231 | const ReadState ¤t_read = last_reads[read_idx]; |
| 3232 | assert(scope_read.stage == current_read.stage); |
| 3233 | if (current_read.tag > event_tag) { |
| 3234 | // The read is more recent than the set event scope, thus no barrier from the wait/ILT. |
| 3235 | hazard.Set(this, usage_index, WRITE_AFTER_READ, current_read.access, current_read.tag); |
| 3236 | } else { |
| 3237 | // The read is in the events first synchronization scope, so we use a barrier hazard check |
| 3238 | // If the read stage is not in the src sync scope |
| 3239 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 3240 | // then the barrier access is unsafe (R/W after R) |
| 3241 | if (scope_read.IsReadBarrierHazard(event_queue, src_exec_scope)) { |
| 3242 | hazard.Set(this, usage_index, WRITE_AFTER_READ, scope_read.access, scope_read.tag); |
| 3243 | break; |
| 3244 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3245 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3246 | } |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3247 | if (!hazard.IsHazard() && (last_reads.size() > scope_read_count)) { |
| 3248 | const ReadState ¤t_read = last_reads[scope_read_count]; |
| 3249 | hazard.Set(this, usage_index, WRITE_AFTER_READ, current_read.access, current_read.tag); |
| 3250 | } |
| 3251 | } else if (last_write.any()) { |
| 3252 | // if there are no reads, the write is either the reason the access is in the event scope... they are a hazard |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3253 | // The write is in the first sync scope of the event (sync their aren't any reads to be the reason) |
| 3254 | // So do a normal barrier hazard check |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3255 | if (scope_state.IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 3256 | hazard.Set(&scope_state, usage_index, WRITE_AFTER_WRITE, scope_state.last_write, scope_state.write_tag); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3257 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3258 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3259 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3260 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3261 | return hazard; |
| 3262 | } |
| 3263 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3264 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 3265 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 3266 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 3267 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3268 | if (write_tag < other.write_tag) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3269 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 3270 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3271 | *this = other; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3272 | } else if (other.write_tag == write_tag) { |
| 3273 | // In the *equals* case for write operations, we merged the write barriers and the read state (but without the |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3274 | // dependency chaining logic or any stage expansion) |
| 3275 | write_barriers |= other.write_barriers; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3276 | pending_write_barriers |= other.pending_write_barriers; |
| 3277 | pending_layout_transition |= other.pending_layout_transition; |
| 3278 | pending_write_dep_chain |= other.pending_write_dep_chain; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3279 | pending_layout_ordering_ |= other.pending_layout_ordering_; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3280 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3281 | // Merge the read states |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3282 | const auto pre_merge_count = last_reads.size(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3283 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3284 | for (uint32_t other_read_index = 0; other_read_index < other.last_reads.size(); other_read_index++) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3285 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3286 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3287 | // Merge in the barriers for read stages that exist in *both* this and other |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3288 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 3289 | // but we should wait on profiling data for that. |
| 3290 | for (uint32_t my_read_index = 0; my_read_index < pre_merge_count; my_read_index++) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3291 | auto &my_read = last_reads[my_read_index]; |
| 3292 | if (other_read.stage == my_read.stage) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3293 | if (my_read.tag < other_read.tag) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3294 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3295 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3296 | my_read.tag = other_read.tag; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3297 | my_read.queue = other_read.queue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3298 | my_read.pending_dep_chain = other_read.pending_dep_chain; |
| 3299 | // TODO: Phase 2 -- review the state merge logic to avoid false positive from overwriting the barriers |
| 3300 | // May require tracking more than one access per stage. |
| 3301 | my_read.barriers = other_read.barriers; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3302 | my_read.sync_stages = other_read.sync_stages; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3303 | if (my_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3304 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 3305 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3306 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3307 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3308 | } else if (other_read.tag == my_read.tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3309 | // The read tags match so merge the barriers |
| 3310 | my_read.barriers |= other_read.barriers; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3311 | my_read.sync_stages |= other_read.sync_stages; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3312 | my_read.pending_dep_chain |= other_read.pending_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3313 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3314 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3315 | break; |
| 3316 | } |
| 3317 | } |
| 3318 | } else { |
| 3319 | // The other read stage doesn't exist in this, so add it. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3320 | last_reads.emplace_back(other_read); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3321 | last_read_stages |= other_read.stage; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3322 | if (other_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3323 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3324 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3325 | } |
| 3326 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3327 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3328 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 3329 | // ignore it. |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3330 | |
| 3331 | // Merge first access information by making a copy of this first_access and reconstructing with a shuffle |
| 3332 | // of the copy and other into this using the update first logic. |
| 3333 | // NOTE: All sorts of additional cleverness could be put into short circuts. (for example back is write and is before front |
| 3334 | // of the other first_accesses... ) |
| 3335 | if (!(first_accesses_ == other.first_accesses_) && !other.first_accesses_.empty()) { |
| 3336 | FirstAccesses firsts(std::move(first_accesses_)); |
| 3337 | first_accesses_.clear(); |
| 3338 | first_read_stages_ = 0U; |
| 3339 | auto a = firsts.begin(); |
| 3340 | auto a_end = firsts.end(); |
| 3341 | for (auto &b : other.first_accesses_) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3342 | // TODO: Determine whether some tag offset will be needed for PHASE II |
| 3343 | while ((a != a_end) && (a->tag < b.tag)) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3344 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3345 | ++a; |
| 3346 | } |
| 3347 | UpdateFirst(b.tag, b.usage_index, b.ordering_rule); |
| 3348 | } |
| 3349 | for (; a != a_end; ++a) { |
| 3350 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3351 | } |
| 3352 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3353 | } |
| 3354 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3355 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, SyncOrdering ordering_rule, const ResourceUsageTag tag) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3356 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 3357 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3358 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3359 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 3360 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 3361 | const auto usage_stage = PipelineStageBit(usage_index); |
| 3362 | if (usage_stage & last_read_stages) { |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3363 | const auto not_usage_stage = ~usage_stage; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3364 | for (auto &read_access : last_reads) { |
| 3365 | if (read_access.stage == usage_stage) { |
| 3366 | read_access.Set(usage_stage, usage_bit, 0, tag); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3367 | } else if (read_access.barriers & usage_stage) { |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3368 | // If the current access is barriered to this stage, mark it as "known to happen after" |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3369 | read_access.sync_stages |= usage_stage; |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3370 | } else { |
| 3371 | // If the current access is *NOT* barriered to this stage it needs to be cleared. |
| 3372 | // Note: this is possible because semaphores can *clear* effective barriers, so the assumption |
| 3373 | // that sync_stages is a subset of barriers may not apply. |
| 3374 | read_access.sync_stages &= not_usage_stage; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3375 | } |
| 3376 | } |
| 3377 | } else { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3378 | for (auto &read_access : last_reads) { |
| 3379 | if (read_access.barriers & usage_stage) { |
| 3380 | read_access.sync_stages |= usage_stage; |
| 3381 | } |
| 3382 | } |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3383 | last_reads.emplace_back(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3384 | last_read_stages |= usage_stage; |
| 3385 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3386 | |
| 3387 | // Fragment shader reads come in two flavors, and we need to track if the one we're tracking is the special one. |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3388 | if (usage_stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3389 | // TODO Revisit re: multiple reads for a given stage |
| 3390 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3391 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3392 | } else { |
| 3393 | // Assume write |
| 3394 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3395 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3396 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3397 | UpdateFirst(tag, usage_index, ordering_rule); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3398 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3399 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3400 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 3401 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 3402 | // We can overwrite them as *this* write is now after them. |
| 3403 | // |
| 3404 | // Note: intentionally ignore pending barriers and chains (i.e. don't apply or clear them), let ApplyPendingBarriers handle them. |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3405 | void ResourceAccessState::SetWrite(const SyncStageAccessFlags &usage_bit, const ResourceUsageTag tag) { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3406 | ClearRead(); |
| 3407 | ClearWrite(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3408 | write_tag = tag; |
| 3409 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3410 | } |
| 3411 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3412 | void ResourceAccessState::ClearWrite() { |
| 3413 | read_execution_barriers = VK_PIPELINE_STAGE_2_NONE; |
| 3414 | input_attachment_read = false; // Denotes no outstanding input attachment read after the last write. |
| 3415 | write_barriers.reset(); |
| 3416 | write_dependency_chain = VK_PIPELINE_STAGE_2_NONE; |
| 3417 | last_write.reset(); |
| 3418 | |
| 3419 | write_tag = 0; |
| 3420 | write_queue = QueueSyncState::kQueueIdInvalid; |
| 3421 | } |
| 3422 | |
| 3423 | void ResourceAccessState::ClearRead() { |
| 3424 | last_reads.clear(); |
| 3425 | last_read_stages = VK_PIPELINE_STAGE_2_NONE; |
| 3426 | } |
| 3427 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3428 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 3429 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 3430 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 3431 | // replace the current write barriers or add to them, so accumulate to pending as well. |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3432 | template <typename ScopeOps> |
| 3433 | void ResourceAccessState::ApplyBarrier(ScopeOps &&scope, const SyncBarrier &barrier, bool layout_transition) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3434 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 3435 | // applying the memory barriers |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 3436 | // NOTE: We update the write barrier if the write is in the first access scope or if there is a layout |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3437 | // transistion, under the theory of "most recent access". If the resource acces *isn't* safe |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 3438 | // vs. this layout transition DetectBarrierHazard should report it. We treat the layout |
| 3439 | // transistion *as* a write and in scope with the barrier (it's before visibility). |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3440 | if (layout_transition || scope.WriteInScope(barrier, *this)) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3441 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3442 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3443 | if (layout_transition) { |
| 3444 | pending_layout_ordering_ |= OrderingBarrier(barrier.src_exec_scope.exec_scope, barrier.src_access_scope); |
| 3445 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3446 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3447 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 3448 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3449 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3450 | if (!pending_layout_transition) { |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3451 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/chains |
| 3452 | // don't need to be tracked as we're just going to clear them. |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3453 | VkPipelineStageFlags2 stages_in_scope = VK_PIPELINE_STAGE_2_NONE; |
| 3454 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3455 | for (auto &read_access : last_reads) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3456 | // The | implements the "dependency chain" logic for this access, as the barriers field stores the second sync scope |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3457 | if (scope.ReadInScope(barrier, read_access)) { |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3458 | // We'll apply the barrier in the next loop, because it's DRY'r to do it one place. |
| 3459 | stages_in_scope |= read_access.stage; |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | for (auto &read_access : last_reads) { |
| 3464 | if (0 != ((read_access.stage | read_access.sync_stages) & stages_in_scope)) { |
| 3465 | // If this stage, or any stage known to be synchronized after it are in scope, apply the barrier to this read |
| 3466 | // NOTE: Forwarding barriers to known prior stages changes the sync_stages from shallow to deep, because the |
| 3467 | // barriers used to determine sync_stages have been propagated to all known earlier stages |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3468 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3469 | } |
| 3470 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3471 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3472 | } |
| 3473 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3474 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag tag) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3475 | if (pending_layout_transition) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3476 | // SetWrite clobbers the last_reads array, and thus we don't have to clear the read_state out. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3477 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3478 | UpdateFirst(tag, SYNC_IMAGE_LAYOUT_TRANSITION, SyncOrdering::kNonAttachment); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3479 | TouchupFirstForLayoutTransition(tag, pending_layout_ordering_); |
| 3480 | pending_layout_ordering_ = OrderingBarrier(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3481 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3482 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3483 | |
| 3484 | // Apply the accumulate execution barriers (and thus update chaining information) |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3485 | // for layout transition, last_reads is reset by SetWrite, so this will be skipped. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3486 | for (auto &read_access : last_reads) { |
| 3487 | read_access.barriers |= read_access.pending_dep_chain; |
| 3488 | read_execution_barriers |= read_access.barriers; |
| 3489 | read_access.pending_dep_chain = 0; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 3493 | write_dependency_chain |= pending_write_dep_chain; |
| 3494 | write_barriers |= pending_write_barriers; |
| 3495 | pending_write_dep_chain = 0; |
| 3496 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3497 | } |
| 3498 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3499 | // Assumes signal queue != wait queue |
| 3500 | void ResourceAccessState::ApplySemaphore(const SemaphoreScope &signal, const SemaphoreScope wait) { |
| 3501 | // Semaphores only guarantee the first scope of the signal is before the second scope of the wait. |
| 3502 | // If any access isn't in the first scope, there are no guarantees, thus those barriers are cleared |
| 3503 | assert(signal.queue != wait.queue); |
| 3504 | for (auto &read_access : last_reads) { |
| 3505 | if (read_access.ReadInQueueScopeOrChain(signal.queue, signal.exec_scope)) { |
| 3506 | // Deflects WAR on wait queue |
| 3507 | read_access.barriers = wait.exec_scope; |
| 3508 | } else { |
| 3509 | // Leave sync stages alone. Update method will clear unsynchronized stages on subsequent reads as needed. |
| 3510 | read_access.barriers = VK_PIPELINE_STAGE_2_NONE; |
| 3511 | } |
| 3512 | } |
| 3513 | if (WriteInQueueSourceScopeOrChain(signal.queue, signal.exec_scope, signal.valid_accesses)) { |
| 3514 | // Will deflect RAW wait queue, WAW needs a chained barrier on wait queue |
| 3515 | read_execution_barriers = wait.exec_scope; |
| 3516 | write_barriers = wait.valid_accesses; |
| 3517 | } else { |
| 3518 | read_execution_barriers = VK_PIPELINE_STAGE_2_NONE; |
| 3519 | write_barriers.reset(); |
| 3520 | } |
| 3521 | write_dependency_chain = read_execution_barriers; |
| 3522 | } |
| 3523 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3524 | bool ResourceAccessState::QueueTagPredicate::operator()(QueueId usage_queue, ResourceUsageTag usage_tag) { |
| 3525 | return (queue == usage_queue) && (tag <= usage_tag); |
| 3526 | } |
| 3527 | |
| 3528 | bool ResourceAccessState::QueuePredicate::operator()(QueueId usage_queue, ResourceUsageTag) { return queue == usage_queue; } |
| 3529 | |
| 3530 | bool ResourceAccessState::TagPredicate::operator()(QueueId, ResourceUsageTag usage_tag) { return tag <= usage_tag; } |
| 3531 | |
| 3532 | // Return if the resulting state is "empty" |
| 3533 | template <typename Pred> |
| 3534 | bool ResourceAccessState::ApplyQueueTagWait(Pred &&queue_tag_test) { |
| 3535 | VkPipelineStageFlags2KHR sync_reads = VK_PIPELINE_STAGE_2_NONE; |
| 3536 | |
| 3537 | // Use the predicate to build a mask of the read stages we are synchronizing |
| 3538 | // Use the sync_stages to also detect reads known to be before any synchronized reads (first pass) |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3539 | for (auto &read_access : last_reads) { |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3540 | if (queue_tag_test(read_access.queue, read_access.tag)) { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3541 | // If we know this stage is before any stage we syncing, or if the predicate tells us that we are waited for.. |
| 3542 | sync_reads |= read_access.stage; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3543 | } |
| 3544 | } |
| 3545 | |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3546 | // Now that we know the reads directly in scopejust need to go over the list again to pick up the "known earlier" stages. |
| 3547 | // NOTE: sync_stages is "deep" catching all stages synchronized after it because we forward barriers |
| 3548 | uint32_t unsync_count = 0; |
| 3549 | for (auto &read_access : last_reads) { |
| 3550 | if (0 != ((read_access.stage | read_access.sync_stages) & sync_reads)) { |
| 3551 | // This is redundant in the "stage" case, but avoids a second branch to get an accurate count |
| 3552 | sync_reads |= read_access.stage; |
| 3553 | } else { |
| 3554 | ++unsync_count; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3555 | } |
| 3556 | } |
| 3557 | |
| 3558 | if (unsync_count) { |
| 3559 | if (sync_reads) { |
| 3560 | // When have some remaining unsynchronized reads, we have to rewrite the last_reads array. |
| 3561 | ReadStates unsync_reads; |
| 3562 | unsync_reads.reserve(unsync_count); |
| 3563 | VkPipelineStageFlags2KHR unsync_read_stages = VK_PIPELINE_STAGE_2_NONE; |
| 3564 | for (auto &read_access : last_reads) { |
| 3565 | if (0 == (read_access.stage & sync_reads)) { |
| 3566 | unsync_reads.emplace_back(read_access); |
| 3567 | unsync_read_stages |= read_access.stage; |
| 3568 | } |
| 3569 | } |
| 3570 | last_read_stages = unsync_read_stages; |
| 3571 | last_reads = std::move(unsync_reads); |
| 3572 | } |
| 3573 | } else { |
| 3574 | // Nothing remains (or it was empty to begin with) |
| 3575 | ClearRead(); |
| 3576 | } |
| 3577 | |
| 3578 | bool all_clear = last_reads.size() == 0; |
| 3579 | if (last_write.any()) { |
| 3580 | if (queue_tag_test(write_queue, write_tag) || sync_reads) { |
| 3581 | // Clear any predicated write, or any the write from any any access with synchronized reads. |
| 3582 | // This could drop RAW detection, but only if the synchronized reads were RAW hazards, and given |
| 3583 | // MRR approach to reporting, this is consistent with other drops, especially since fixing the |
| 3584 | // RAW wit the sync_reads stages would preclude a subsequent RAW. |
| 3585 | ClearWrite(); |
| 3586 | } else { |
| 3587 | all_clear = false; |
| 3588 | } |
| 3589 | } |
| 3590 | return all_clear; |
| 3591 | } |
| 3592 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3593 | bool ResourceAccessState::FirstAccessInTagRange(const ResourceUsageRange &tag_range) const { |
| 3594 | if (!first_accesses_.size()) return false; |
| 3595 | const ResourceUsageRange first_access_range = {first_accesses_.front().tag, first_accesses_.back().tag + 1}; |
| 3596 | return tag_range.intersects(first_access_range); |
| 3597 | } |
| 3598 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3599 | void ResourceAccessState::OffsetTag(ResourceUsageTag offset) { |
| 3600 | if (last_write.any()) write_tag += offset; |
| 3601 | for (auto &read_access : last_reads) { |
| 3602 | read_access.tag += offset; |
| 3603 | } |
| 3604 | for (auto &first : first_accesses_) { |
| 3605 | first.tag += offset; |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | ResourceAccessState::ResourceAccessState() |
| 3610 | : write_barriers(~SyncStageAccessFlags(0)), |
| 3611 | write_dependency_chain(0), |
| 3612 | write_tag(), |
| 3613 | write_queue(QueueSyncState::kQueueIdInvalid), |
| 3614 | last_write(0), |
| 3615 | input_attachment_read(false), |
| 3616 | last_read_stages(0), |
| 3617 | read_execution_barriers(0), |
| 3618 | pending_write_dep_chain(0), |
| 3619 | pending_layout_transition(false), |
| 3620 | pending_write_barriers(0), |
| 3621 | pending_layout_ordering_(), |
| 3622 | first_accesses_(), |
| 3623 | first_read_stages_(0U), |
| 3624 | first_write_layout_ordering_() {} |
| 3625 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3626 | // This should be just Bits or Index, but we don't have an invalid state for Index |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3627 | VkPipelineStageFlags2KHR ResourceAccessState::GetReadBarriers(const SyncStageAccessFlags &usage_bit) const { |
| 3628 | VkPipelineStageFlags2KHR barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3629 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3630 | for (const auto &read_access : last_reads) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3631 | if ((read_access.access & usage_bit).any()) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3632 | barriers = read_access.barriers; |
| 3633 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3634 | } |
| 3635 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3636 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3637 | return barriers; |
| 3638 | } |
| 3639 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3640 | void ResourceAccessState::SetQueueId(QueueId id) { |
| 3641 | for (auto &read_access : last_reads) { |
| 3642 | if (read_access.queue == QueueSyncState::kQueueIdInvalid) { |
| 3643 | read_access.queue = id; |
| 3644 | } |
| 3645 | } |
| 3646 | if (last_write.any() && (write_queue == QueueSyncState::kQueueIdInvalid)) { |
| 3647 | write_queue = id; |
| 3648 | } |
| 3649 | } |
| 3650 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 3651 | bool ResourceAccessState::WriteInChain(VkPipelineStageFlags2KHR src_exec_scope) const { |
| 3652 | return 0 != (write_dependency_chain & src_exec_scope); |
| 3653 | } |
| 3654 | |
| 3655 | bool ResourceAccessState::WriteInScope(const SyncStageAccessFlags &src_access_scope) const { |
| 3656 | return (src_access_scope & last_write).any(); |
| 3657 | } |
| 3658 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3659 | bool ResourceAccessState::WriteBarrierInScope(const SyncStageAccessFlags &src_access_scope) const { |
| 3660 | return (write_barriers & src_access_scope).any(); |
| 3661 | } |
| 3662 | |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3663 | bool ResourceAccessState::WriteInSourceScopeOrChain(VkPipelineStageFlags2KHR src_exec_scope, |
| 3664 | SyncStageAccessFlags src_access_scope) const { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 3665 | return WriteInChain(src_exec_scope) || WriteInScope(src_access_scope); |
| 3666 | } |
| 3667 | |
| 3668 | bool ResourceAccessState::WriteInQueueSourceScopeOrChain(QueueId queue, VkPipelineStageFlags2KHR src_exec_scope, |
| 3669 | SyncStageAccessFlags src_access_scope) const { |
| 3670 | return WriteInChain(src_exec_scope) || ((queue == write_queue) && WriteInScope(src_access_scope)); |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3671 | } |
| 3672 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3673 | bool ResourceAccessState::WriteInEventScope(VkPipelineStageFlags2KHR src_exec_scope, const SyncStageAccessFlags &src_access_scope, |
| 3674 | QueueId scope_queue, ResourceUsageTag scope_tag) const { |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3675 | // The scope logic for events is, if we're asking, the resource usage was flagged as "in the first execution scope" at |
| 3676 | // the time of the SetEvent, thus all we need check is whether the access is the same one (i.e. before the scope tag |
| 3677 | // in order to know if it's in the excecution scope |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3678 | return (write_tag < scope_tag) && WriteInQueueSourceScopeOrChain(scope_queue, src_exec_scope, src_access_scope); |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3679 | } |
| 3680 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3681 | bool ResourceAccessState::WriteInChainedScope(VkPipelineStageFlags2KHR src_exec_scope, |
| 3682 | const SyncStageAccessFlags &src_access_scope) const { |
| 3683 | return WriteInChain(src_exec_scope) && WriteBarrierInScope(src_access_scope); |
| 3684 | } |
| 3685 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3686 | bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlags2KHR usage_stage, const SyncStageAccessFlags &usage) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3687 | assert(IsRead(usage)); |
| 3688 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 3689 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 3690 | // any reads that happen after. |
| 3691 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 3692 | // the current read will be also not be a hazard, thus reporting a hazard here adds no needed information. |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3693 | return last_write.any() && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3694 | } |
| 3695 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3696 | VkPipelineStageFlags2 ResourceAccessState::GetOrderedStages(QueueId queue_id, const OrderingBarrier &ordering) const { |
| 3697 | // At apply queue submission order limits on the effect of ordering |
| 3698 | VkPipelineStageFlags2 non_qso_stages = VK_PIPELINE_STAGE_2_NONE; |
| 3699 | if (queue_id != QueueSyncState::kQueueIdInvalid) { |
| 3700 | for (const auto &read_access : last_reads) { |
| 3701 | if (read_access.queue != queue_id) { |
| 3702 | non_qso_stages |= read_access.stage; |
| 3703 | } |
| 3704 | } |
| 3705 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3706 | // Whether the stage are in the ordering scope only matters if the current write is ordered |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3707 | const VkPipelineStageFlags2 read_stages_in_qso = last_read_stages & ~non_qso_stages; |
| 3708 | VkPipelineStageFlags2 ordered_stages = read_stages_in_qso & ordering.exec_scope; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3709 | // Special input attachment handling as always (not encoded in exec_scop) |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3710 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3711 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3712 | // If we have an input attachment in last_reads and input attachments are ordered we all that stage |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3713 | ordered_stages |= VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3714 | } |
| 3715 | |
| 3716 | return ordered_stages; |
| 3717 | } |
| 3718 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3719 | void ResourceAccessState::UpdateFirst(const ResourceUsageTag tag, SyncStageAccessIndex usage_index, SyncOrdering ordering_rule) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3720 | // Only record until we record a write. |
| 3721 | if (first_accesses_.empty() || IsRead(first_accesses_.back().usage_index)) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3722 | const VkPipelineStageFlags2KHR usage_stage = IsRead(usage_index) ? PipelineStageBit(usage_index) : 0U; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3723 | if (0 == (usage_stage & first_read_stages_)) { |
| 3724 | // If this is a read we haven't seen or a write, record. |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3725 | // We always need to know what stages were found prior to write |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3726 | first_read_stages_ |= usage_stage; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3727 | if (0 == (read_execution_barriers & usage_stage)) { |
| 3728 | // If this stage isn't masked then we add it (since writes map to usage_stage 0, this also records writes) |
| 3729 | first_accesses_.emplace_back(tag, usage_index, ordering_rule); |
| 3730 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3731 | } |
| 3732 | } |
| 3733 | } |
| 3734 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3735 | void ResourceAccessState::TouchupFirstForLayoutTransition(ResourceUsageTag tag, const OrderingBarrier &layout_ordering) { |
| 3736 | // Only call this after recording an image layout transition |
| 3737 | assert(first_accesses_.size()); |
| 3738 | if (first_accesses_.back().tag == tag) { |
| 3739 | // If this layout transition is the the first write, add the additional ordering rules that guard the ILT |
Samuel Iglesias Gonsálvez | 9b4660b | 2021-10-21 08:50:39 +0200 | [diff] [blame] | 3740 | assert(first_accesses_.back().usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3741 | first_write_layout_ordering_ = layout_ordering; |
| 3742 | } |
| 3743 | } |
| 3744 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3745 | ResourceAccessState::ReadState::ReadState(VkPipelineStageFlags2KHR stage_, SyncStageAccessFlags access_, |
| 3746 | VkPipelineStageFlags2KHR barriers_, ResourceUsageTag tag_) |
| 3747 | : stage(stage_), |
| 3748 | access(access_), |
| 3749 | barriers(barriers_), |
| 3750 | sync_stages(VK_PIPELINE_STAGE_2_NONE), |
| 3751 | tag(tag_), |
| 3752 | queue(QueueSyncState::kQueueIdInvalid), |
| 3753 | pending_dep_chain(VK_PIPELINE_STAGE_2_NONE) {} |
| 3754 | |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 3755 | void ResourceAccessState::ReadState::Set(VkPipelineStageFlags2KHR stage_, const SyncStageAccessFlags &access_, |
| 3756 | VkPipelineStageFlags2KHR barriers_, ResourceUsageTag tag_) { |
| 3757 | stage = stage_; |
| 3758 | access = access_; |
| 3759 | barriers = barriers_; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3760 | sync_stages = VK_PIPELINE_STAGE_2_NONE; |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 3761 | tag = tag_; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3762 | pending_dep_chain = VK_PIPELINE_STAGE_2_NONE; // If this is a new read, we aren't applying a barrier set. |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 3763 | } |
| 3764 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 3765 | // Scope test including "queue submission order" effects. Specifically, accesses from a different queue are not |
| 3766 | // considered to be in "queue submission order" with barriers, events, or semaphore signalling, but any barriers |
| 3767 | // that have bee applied (via semaphore) to those accesses can be chained off of. |
| 3768 | bool ResourceAccessState::ReadState::ReadInQueueScopeOrChain(QueueId scope_queue, VkPipelineStageFlags2 exec_scope) const { |
| 3769 | VkPipelineStageFlags2 effective_stages = barriers | ((scope_queue == queue) ? stage : VK_PIPELINE_STAGE_2_NONE); |
| 3770 | return (exec_scope & effective_stages) != 0; |
| 3771 | } |
| 3772 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3773 | ResourceUsageRange SyncValidator::ReserveGlobalTagRange(size_t tag_count) const { |
| 3774 | ResourceUsageRange reserve; |
| 3775 | reserve.begin = tag_limit_.fetch_add(tag_count); |
| 3776 | reserve.end = reserve.begin + tag_count; |
| 3777 | return reserve; |
| 3778 | } |
| 3779 | |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 3780 | const QueueSyncState *SyncValidator::GetQueueSyncState(VkQueue queue) const { |
| 3781 | return GetMappedPlainFromShared(queue_sync_states_, queue); |
| 3782 | } |
| 3783 | |
| 3784 | QueueSyncState *SyncValidator::GetQueueSyncState(VkQueue queue) { return GetMappedPlainFromShared(queue_sync_states_, queue); } |
| 3785 | |
| 3786 | std::shared_ptr<const QueueSyncState> SyncValidator::GetQueueSyncStateShared(VkQueue queue) const { |
| 3787 | return GetMapped(queue_sync_states_, queue, []() { return std::shared_ptr<QueueSyncState>(); }); |
| 3788 | } |
| 3789 | |
| 3790 | std::shared_ptr<QueueSyncState> SyncValidator::GetQueueSyncStateShared(VkQueue queue) { |
| 3791 | return GetMapped(queue_sync_states_, queue, []() { return std::shared_ptr<QueueSyncState>(); }); |
| 3792 | } |
| 3793 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3794 | template <typename T> |
| 3795 | struct GetBatchTraits {}; |
| 3796 | template <> |
| 3797 | struct GetBatchTraits<std::shared_ptr<QueueSyncState>> { |
| 3798 | using Batch = std::shared_ptr<QueueBatchContext>; |
| 3799 | static Batch Get(const std::shared_ptr<QueueSyncState> &qss) { return qss ? qss->LastBatch() : Batch(); } |
| 3800 | }; |
| 3801 | |
| 3802 | template <> |
| 3803 | struct GetBatchTraits<std::shared_ptr<SignaledSemaphores::Signal>> { |
| 3804 | using Batch = std::shared_ptr<QueueBatchContext>; |
| 3805 | static Batch Get(const std::shared_ptr<SignaledSemaphores::Signal> &sig) { return sig ? sig->batch : Batch(); } |
| 3806 | }; |
| 3807 | |
| 3808 | template <typename BatchSet, typename Map, typename Predicate> |
| 3809 | static BatchSet GetQueueBatchSnapshotImpl(const Map &map, Predicate &&pred) { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3810 | BatchSet snapshot; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3811 | for (auto &entry : map) { |
| 3812 | // Intentional copy |
| 3813 | auto batch = GetBatchTraits<typename Map::mapped_type>::Get(entry.second); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3814 | if (batch && pred(batch)) snapshot.emplace(std::move(batch)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3815 | } |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3816 | return snapshot; |
| 3817 | } |
| 3818 | |
| 3819 | template <typename Predicate> |
| 3820 | QueueBatchContext::ConstBatchSet SyncValidator::GetQueueLastBatchSnapshot(Predicate &&pred) const { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3821 | return GetQueueBatchSnapshotImpl<QueueBatchContext::ConstBatchSet>(queue_sync_states_, std::forward<Predicate>(pred)); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | template <typename Predicate> |
| 3825 | QueueBatchContext::BatchSet SyncValidator::GetQueueLastBatchSnapshot(Predicate &&pred) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3826 | return GetQueueBatchSnapshotImpl<QueueBatchContext::BatchSet>(queue_sync_states_, std::forward<Predicate>(pred)); |
| 3827 | } |
| 3828 | |
| 3829 | QueueBatchContext::BatchSet SyncValidator::GetQueueBatchSnapshot() { |
| 3830 | QueueBatchContext::BatchSet snapshot = GetQueueLastBatchSnapshot(); |
| 3831 | auto append = [&snapshot](const std::shared_ptr<QueueBatchContext> batch) { |
| 3832 | if (batch && !layer_data::Contains(snapshot, batch)) { |
| 3833 | snapshot.emplace(batch); |
| 3834 | } |
| 3835 | return false; |
| 3836 | }; |
| 3837 | GetQueueBatchSnapshotImpl<QueueBatchContext::BatchSet>(signaled_semaphores_, append); |
| 3838 | return snapshot; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3839 | } |
| 3840 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3841 | bool SignaledSemaphores::SignalSemaphore(const std::shared_ptr<const SEMAPHORE_STATE> &sem_state, |
| 3842 | const std::shared_ptr<QueueBatchContext> &batch, |
| 3843 | const VkSemaphoreSubmitInfo &signal_info) { |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3844 | assert(batch); |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3845 | const SyncExecScope exec_scope = |
| 3846 | SyncExecScope::MakeSrc(batch->GetQueueFlags(), signal_info.stageMask, VK_PIPELINE_STAGE_2_HOST_BIT); |
| 3847 | const VkSemaphore sem = sem_state->semaphore(); |
| 3848 | auto signal_it = signaled_.find(sem); |
| 3849 | std::shared_ptr<Signal> insert_signal; |
| 3850 | if (signal_it == signaled_.end()) { |
| 3851 | if (prev_) { |
| 3852 | auto prev_sig = GetMapped(prev_->signaled_, sem_state->semaphore(), []() { return std::shared_ptr<Signal>(); }); |
| 3853 | if (prev_sig) { |
| 3854 | // The is an invalid signal, as this semaphore is already signaled... copy the prev state (as prev_ is const) |
| 3855 | insert_signal = std::make_shared<Signal>(*prev_sig); |
| 3856 | } |
| 3857 | } |
| 3858 | auto insert_pair = signaled_.emplace(sem, std::move(insert_signal)); |
| 3859 | signal_it = insert_pair.first; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3860 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3861 | |
| 3862 | bool success = false; |
| 3863 | if (!signal_it->second) { |
| 3864 | signal_it->second = std::make_shared<Signal>(sem_state, batch, exec_scope); |
| 3865 | success = true; |
| 3866 | } |
| 3867 | |
| 3868 | return success; |
| 3869 | } |
| 3870 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3871 | std::shared_ptr<const SignaledSemaphores::Signal> SignaledSemaphores::Unsignal(VkSemaphore sem) { |
| 3872 | std::shared_ptr<const Signal> unsignaled; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3873 | const auto found_it = signaled_.find(sem); |
| 3874 | if (found_it != signaled_.end()) { |
| 3875 | // Move the unsignaled singal out from the signaled list, but keep the shared_ptr as the caller needs the contents for |
| 3876 | // a bit. |
| 3877 | unsignaled = std::move(found_it->second); |
| 3878 | if (!prev_) { |
| 3879 | // No parent, not need to keep the entry |
| 3880 | // IFF (prev_) leave the entry in the leaf table as we use it to export unsignal to prev_ during record phase |
| 3881 | signaled_.erase(found_it); |
| 3882 | } |
| 3883 | } else if (prev_) { |
| 3884 | // We can't unsignal prev_ because it's const * by design. |
| 3885 | // We put in an empty placeholder |
| 3886 | signaled_.emplace(sem, std::shared_ptr<Signal>()); |
| 3887 | unsignaled = GetPrev(sem); |
| 3888 | } |
| 3889 | // NOTE: No else clause. Because if we didn't find it, and there's no previous, this indicates an error, |
| 3890 | // but CoreChecks should have reported it |
| 3891 | |
| 3892 | // If unsignaled is null, there was a missing pending semaphore, and that's also issue CoreChecks reports |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3893 | return unsignaled; |
| 3894 | } |
| 3895 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3896 | void SignaledSemaphores::Import(VkSemaphore sem, std::shared_ptr<Signal> &&from) { |
| 3897 | // Overwrite the s tate with the last state from this |
| 3898 | if (from) { |
| 3899 | assert(sem == from->sem_state->semaphore()); |
| 3900 | signaled_[sem] = std::move(from); |
| 3901 | } else { |
| 3902 | signaled_.erase(sem); |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | void SignaledSemaphores::Reset() { |
| 3907 | signaled_.clear(); |
| 3908 | prev_ = nullptr; |
| 3909 | } |
| 3910 | |
John Zulauf | ea943c5 | 2022-02-22 11:05:17 -0700 | [diff] [blame] | 3911 | std::shared_ptr<CommandBufferAccessContext> SyncValidator::AccessContextFactory(VkCommandBuffer command_buffer) { |
| 3912 | // If we don't have one, make it. |
| 3913 | auto cb_state = Get<CMD_BUFFER_STATE>(command_buffer); |
| 3914 | assert(cb_state.get()); |
| 3915 | auto queue_flags = cb_state->GetQueueFlags(); |
| 3916 | return std::make_shared<CommandBufferAccessContext>(*this, cb_state, queue_flags); |
| 3917 | } |
| 3918 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3919 | std::shared_ptr<CommandBufferAccessContext> SyncValidator::GetAccessContextShared(VkCommandBuffer command_buffer) { |
John Zulauf | ea943c5 | 2022-02-22 11:05:17 -0700 | [diff] [blame] | 3920 | return GetMappedInsert(cb_access_state, command_buffer, |
| 3921 | [this, command_buffer]() { return AccessContextFactory(command_buffer); }); |
| 3922 | } |
| 3923 | |
| 3924 | std::shared_ptr<const CommandBufferAccessContext> SyncValidator::GetAccessContextShared(VkCommandBuffer command_buffer) const { |
| 3925 | return GetMapped(cb_access_state, command_buffer, []() { return std::shared_ptr<CommandBufferAccessContext>(); }); |
| 3926 | } |
| 3927 | |
| 3928 | const CommandBufferAccessContext *SyncValidator::GetAccessContext(VkCommandBuffer command_buffer) const { |
| 3929 | return GetMappedPlainFromShared(cb_access_state, command_buffer); |
| 3930 | } |
| 3931 | |
| 3932 | CommandBufferAccessContext *SyncValidator::GetAccessContext(VkCommandBuffer command_buffer) { |
| 3933 | return GetAccessContextShared(command_buffer).get(); |
| 3934 | } |
| 3935 | |
| 3936 | CommandBufferAccessContext *SyncValidator::GetAccessContextNoInsert(VkCommandBuffer command_buffer) { |
| 3937 | return GetMappedPlainFromShared(cb_access_state, command_buffer); |
| 3938 | } |
| 3939 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3940 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3941 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 3942 | if (access_context) { |
| 3943 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3944 | } |
| 3945 | } |
| 3946 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3947 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 3948 | auto access_found = cb_access_state.find(command_buffer); |
| 3949 | if (access_found != cb_access_state.end()) { |
| 3950 | access_found->second->Reset(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3951 | access_found->second->MarkDestroyed(); |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3952 | cb_access_state.erase(access_found); |
| 3953 | } |
| 3954 | } |
| 3955 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3956 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3957 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 3958 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3959 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3960 | assert(cb_context); |
| 3961 | if (!cb_context) return skip; |
| 3962 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3963 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3964 | // If we have no previous accesses, we have no hazards |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3965 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 3966 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3967 | |
| 3968 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3969 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3970 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3971 | const ResourceAccessRange src_range = MakeRange(*src_buffer, copy_region.srcOffset, copy_region.size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3972 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3973 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3974 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3975 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3976 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3977 | cb_context->FormatHazard(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3978 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3979 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3980 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3981 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3982 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3983 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3984 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3985 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3986 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3987 | cb_context->FormatHazard(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3988 | } |
| 3989 | } |
| 3990 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3991 | } |
| 3992 | return skip; |
| 3993 | } |
| 3994 | |
| 3995 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3996 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3997 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3998 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3999 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4000 | auto *context = cb_context->GetCurrentAccessContext(); |
| 4001 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4002 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 4003 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4004 | |
| 4005 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4006 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 4007 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4008 | const ResourceAccessRange src_range = MakeRange(*src_buffer, copy_region.srcOffset, copy_region.size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4009 | context->UpdateAccessState(*src_buffer, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, src_range, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4010 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 4011 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4012 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4013 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, dst_range, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4014 | } |
| 4015 | } |
| 4016 | } |
| 4017 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4018 | void SyncValidator::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 4019 | // Clear out events from the command buffer contexts |
| 4020 | for (auto &cb_context : cb_access_state) { |
| 4021 | cb_context.second->RecordDestroyEvent(event); |
| 4022 | } |
| 4023 | } |
| 4024 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 4025 | bool SyncValidator::ValidateCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos, |
| 4026 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4027 | bool skip = false; |
| 4028 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4029 | assert(cb_context); |
| 4030 | if (!cb_context) return skip; |
| 4031 | const auto *context = cb_context->GetCurrentAccessContext(); |
| 4032 | |
| 4033 | // If we have no previous accesses, we have no hazards |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4034 | auto src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 4035 | auto dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4036 | |
| 4037 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 4038 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 4039 | if (src_buffer) { |
| 4040 | const ResourceAccessRange src_range = MakeRange(*src_buffer, copy_region.srcOffset, copy_region.size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4041 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4042 | if (hazard.hazard) { |
| 4043 | // TODO -- add tag information to log msg when useful. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4044 | skip |= |
| 4045 | LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4046 | "%s(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 4047 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
| 4048 | region, cb_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4049 | } |
| 4050 | } |
| 4051 | if (dst_buffer && !skip) { |
| 4052 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4053 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4054 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4055 | skip |= |
| 4056 | LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4057 | "%s(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 4058 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
| 4059 | region, cb_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4060 | } |
| 4061 | } |
| 4062 | if (skip) break; |
| 4063 | } |
| 4064 | return skip; |
| 4065 | } |
| 4066 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 4067 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4068 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 4069 | return ValidateCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2KHR); |
| 4070 | } |
| 4071 | |
| 4072 | bool SyncValidator::PreCallValidateCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos) const { |
| 4073 | return ValidateCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2); |
| 4074 | } |
| 4075 | |
| 4076 | void SyncValidator::RecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos, CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4077 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4078 | assert(cb_context); |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 4079 | const auto tag = cb_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4080 | auto *context = cb_context->GetCurrentAccessContext(); |
| 4081 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4082 | auto src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 4083 | auto dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4084 | |
| 4085 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 4086 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 4087 | if (src_buffer) { |
| 4088 | const ResourceAccessRange src_range = MakeRange(*src_buffer, copy_region.srcOffset, copy_region.size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4089 | context->UpdateAccessState(*src_buffer, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, src_range, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4090 | } |
| 4091 | if (dst_buffer) { |
| 4092 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4093 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, dst_range, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4094 | } |
| 4095 | } |
| 4096 | } |
| 4097 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 4098 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 4099 | RecordCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2KHR); |
| 4100 | } |
| 4101 | |
| 4102 | void SyncValidator::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos) { |
| 4103 | RecordCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2); |
| 4104 | } |
| 4105 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4106 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4107 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4108 | const VkImageCopy *pRegions) const { |
| 4109 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4110 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4111 | assert(cb_access_context); |
| 4112 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4113 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4114 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4115 | assert(context); |
| 4116 | if (!context) return skip; |
| 4117 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4118 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4119 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4120 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4121 | const auto ©_region = pRegions[region]; |
| 4122 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4123 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.srcSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4124 | copy_region.srcOffset, copy_region.extent, false); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4125 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4126 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4127 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4128 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4129 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4130 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4134 | auto hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.dstSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4135 | copy_region.dstOffset, copy_region.extent, false); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4136 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4137 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4138 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4139 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4140 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4141 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 4142 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4143 | } |
| 4144 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4145 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4146 | return skip; |
| 4147 | } |
| 4148 | |
| 4149 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4150 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4151 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4152 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4153 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 4154 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4155 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4156 | assert(context); |
| 4157 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4158 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4159 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4160 | |
| 4161 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4162 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4163 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4164 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4165 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4166 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4167 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4168 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
ziga-lunarg | 7374651 | 2022-03-23 23:08:17 +0100 | [diff] [blame] | 4169 | copy_region.dstSubresource, copy_region.dstOffset, copy_region.extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4170 | } |
| 4171 | } |
| 4172 | } |
| 4173 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4174 | bool SyncValidator::ValidateCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo, |
| 4175 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4176 | bool skip = false; |
| 4177 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4178 | assert(cb_access_context); |
| 4179 | if (!cb_access_context) return skip; |
| 4180 | |
| 4181 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4182 | assert(context); |
| 4183 | if (!context) return skip; |
| 4184 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4185 | auto src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 4186 | auto dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4187 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4188 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 4189 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 4190 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4191 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.srcSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4192 | copy_region.srcOffset, copy_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4193 | if (hazard.hazard) { |
| 4194 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4195 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4196 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4197 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4198 | } |
| 4199 | } |
| 4200 | |
| 4201 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4202 | auto hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.dstSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4203 | copy_region.dstOffset, copy_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4204 | if (hazard.hazard) { |
| 4205 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4206 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4207 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4208 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4209 | } |
| 4210 | if (skip) break; |
| 4211 | } |
| 4212 | } |
| 4213 | |
| 4214 | return skip; |
| 4215 | } |
| 4216 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4217 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 4218 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 4219 | return ValidateCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2KHR); |
| 4220 | } |
| 4221 | |
| 4222 | bool SyncValidator::PreCallValidateCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) const { |
| 4223 | return ValidateCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2); |
| 4224 | } |
| 4225 | |
| 4226 | void SyncValidator::RecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo, CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4227 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4228 | assert(cb_access_context); |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4229 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4230 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4231 | assert(context); |
| 4232 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4233 | auto src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 4234 | auto dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4235 | |
| 4236 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 4237 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 4238 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4239 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4240 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4241 | } |
| 4242 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4243 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
ziga-lunarg | 7374651 | 2022-03-23 23:08:17 +0100 | [diff] [blame] | 4244 | copy_region.dstSubresource, copy_region.dstOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4245 | } |
| 4246 | } |
| 4247 | } |
| 4248 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4249 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 4250 | RecordCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2KHR); |
| 4251 | } |
| 4252 | |
| 4253 | void SyncValidator::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) { |
| 4254 | RecordCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2); |
| 4255 | } |
| 4256 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4257 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 4258 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 4259 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4260 | uint32_t bufferMemoryBarrierCount, |
| 4261 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4262 | uint32_t imageMemoryBarrierCount, |
| 4263 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 4264 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4265 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4266 | assert(cb_access_context); |
| 4267 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 4268 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4269 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 4270 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 4271 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 4272 | pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 4273 | skip = pipeline_barrier.Validate(*cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4274 | return skip; |
| 4275 | } |
| 4276 | |
| 4277 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 4278 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 4279 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4280 | uint32_t bufferMemoryBarrierCount, |
| 4281 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4282 | uint32_t imageMemoryBarrierCount, |
| 4283 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4284 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4285 | assert(cb_access_context); |
| 4286 | if (!cb_access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4287 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 4288 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), |
| 4289 | srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, |
| 4290 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 4291 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4292 | } |
| 4293 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4294 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 4295 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 4296 | bool skip = false; |
| 4297 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4298 | assert(cb_access_context); |
| 4299 | if (!cb_access_context) return skip; |
| 4300 | |
| 4301 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 4302 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 4303 | return skip; |
| 4304 | } |
| 4305 | |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 4306 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2(VkCommandBuffer commandBuffer, |
| 4307 | const VkDependencyInfo *pDependencyInfo) const { |
| 4308 | bool skip = false; |
| 4309 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4310 | assert(cb_access_context); |
| 4311 | if (!cb_access_context) return skip; |
| 4312 | |
| 4313 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 4314 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 4315 | return skip; |
| 4316 | } |
| 4317 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4318 | void SyncValidator::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) { |
| 4319 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4320 | assert(cb_access_context); |
| 4321 | if (!cb_access_context) return; |
| 4322 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 4323 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), |
| 4324 | *pDependencyInfo); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4325 | } |
| 4326 | |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 4327 | void SyncValidator::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer, const VkDependencyInfo *pDependencyInfo) { |
| 4328 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4329 | assert(cb_access_context); |
| 4330 | if (!cb_access_context) return; |
| 4331 | |
| 4332 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER2, *this, cb_access_context->GetQueueFlags(), |
| 4333 | *pDependencyInfo); |
| 4334 | } |
| 4335 | |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 4336 | void SyncValidator::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4337 | // The state tracker sets up the device state |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 4338 | StateTracker::CreateDevice(pCreateInfo); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4339 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 4340 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 4341 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4342 | // TODO: Find a good way to do this hooklessly. |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 4343 | SetCommandBufferResetCallback([this](VkCommandBuffer command_buffer) -> void { ResetCommandBufferCallback(command_buffer); }); |
| 4344 | SetCommandBufferFreeCallback([this](VkCommandBuffer command_buffer) -> void { FreeCommandBufferCallback(command_buffer); }); |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 4345 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 4346 | QueueId queue_id = QueueSyncState::kQueueIdBase; |
| 4347 | ForEachShared<QUEUE_STATE>([this, &queue_id](const std::shared_ptr<QUEUE_STATE> &queue_state) { |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 4348 | auto queue_flags = physical_device_state->queue_family_properties[queue_state->queueFamilyIndex].queueFlags; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 4349 | std::shared_ptr<QueueSyncState> queue_sync_state = std::make_shared<QueueSyncState>(queue_state, queue_flags, queue_id++); |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 4350 | queue_sync_states_.emplace(std::make_pair(queue_state->Queue(), std::move(queue_sync_state))); |
| 4351 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4352 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4353 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4354 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4355 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4356 | bool skip = false; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4357 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4358 | if (cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4359 | SyncOpBeginRenderPass sync_op(cmd_type, *this, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4360 | skip = sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4361 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4362 | return skip; |
| 4363 | } |
| 4364 | |
| 4365 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4366 | VkSubpassContents contents) const { |
| 4367 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4368 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4369 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4370 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4371 | return skip; |
| 4372 | } |
| 4373 | |
| 4374 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4375 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4376 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4377 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4378 | return skip; |
| 4379 | } |
| 4380 | |
| 4381 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4382 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4383 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4384 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4385 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4386 | return skip; |
| 4387 | } |
| 4388 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4389 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 4390 | VkResult result) { |
| 4391 | // The state tracker sets up the command buffer state |
| 4392 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 4393 | |
| 4394 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 4395 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 4396 | assert(cb_access_context); |
| 4397 | cb_access_context->Reset(); |
| 4398 | } |
| 4399 | |
| 4400 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4401 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd_type) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4402 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4403 | if (cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4404 | cb_context->RecordSyncOp<SyncOpBeginRenderPass>(cmd_type, *this, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4405 | } |
| 4406 | } |
| 4407 | |
| 4408 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4409 | VkSubpassContents contents) { |
| 4410 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4411 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4412 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4413 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4414 | } |
| 4415 | |
| 4416 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4417 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 4418 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4419 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4423 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4424 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 4425 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4426 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4427 | } |
| 4428 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4429 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4430 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4431 | bool skip = false; |
| 4432 | |
| 4433 | auto cb_context = GetAccessContext(commandBuffer); |
| 4434 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4435 | if (!cb_context) return skip; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4436 | SyncOpNextSubpass sync_op(cmd_type, *this, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4437 | return sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 4441 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4442 | // Convert to a NextSubpass2 |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4443 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4444 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4445 | auto subpass_end_info = LvlInitStruct<VkSubpassEndInfo>(); |
| 4446 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, &subpass_end_info, CMD_NEXTSUBPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4447 | return skip; |
| 4448 | } |
| 4449 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4450 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4451 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4452 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4453 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4454 | return skip; |
| 4455 | } |
| 4456 | |
| 4457 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4458 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 4459 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4460 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4461 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4465 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd_type) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4466 | auto cb_context = GetAccessContext(commandBuffer); |
| 4467 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4468 | if (!cb_context) return; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4469 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4470 | cb_context->RecordSyncOp<SyncOpNextSubpass>(cmd_type, *this, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 4474 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4475 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4476 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4477 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4478 | } |
| 4479 | |
| 4480 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4481 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 4482 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4483 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4487 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 4488 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4489 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2KHR); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4490 | } |
| 4491 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4492 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4493 | CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4494 | bool skip = false; |
| 4495 | |
| 4496 | auto cb_context = GetAccessContext(commandBuffer); |
| 4497 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4498 | if (!cb_context) return skip; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4499 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4500 | SyncOpEndRenderPass sync_op(cmd_type, *this, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4501 | skip |= sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4502 | return skip; |
| 4503 | } |
| 4504 | |
| 4505 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 4506 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4507 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4508 | return skip; |
| 4509 | } |
| 4510 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4511 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4512 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4513 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4514 | return skip; |
| 4515 | } |
| 4516 | |
| 4517 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4518 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4519 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4520 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4521 | return skip; |
| 4522 | } |
| 4523 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4524 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
| 4525 | CMD_TYPE cmd_type) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4526 | // Resolve the all subpass contexts to the command buffer contexts |
| 4527 | auto cb_context = GetAccessContext(commandBuffer); |
| 4528 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4529 | if (!cb_context) return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4530 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4531 | cb_context->RecordSyncOp<SyncOpEndRenderPass>(cmd_type, *this, pSubpassEndInfo); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4532 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4533 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 4534 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 4535 | // updates to a resource which do not conflict at the byte level. |
| 4536 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 4537 | // TODO: Add programatic control over suppression heuristics |
| 4538 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 4539 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 4540 | } |
| 4541 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4542 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4543 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4544 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4548 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4549 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4553 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2KHR); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4554 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4555 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4556 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4557 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4558 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4559 | VkImageLayout dstImageLayout, uint32_t regionCount, const RegionType *pRegions, |
| 4560 | CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4561 | bool skip = false; |
| 4562 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4563 | assert(cb_access_context); |
| 4564 | if (!cb_access_context) return skip; |
| 4565 | |
| 4566 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4567 | assert(context); |
| 4568 | if (!context) return skip; |
| 4569 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4570 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 4571 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4572 | |
| 4573 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4574 | const auto ©_region = pRegions[region]; |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4575 | HazardResult hazard; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4576 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4577 | if (src_buffer) { |
| 4578 | ResourceAccessRange src_range = |
| 4579 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4580 | hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4581 | if (hazard.hazard) { |
| 4582 | // PHASE1 TODO -- add tag information to log msg when useful. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4583 | skip |= |
| 4584 | LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4585 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 4586 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
| 4587 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4588 | } |
| 4589 | } |
| 4590 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4591 | hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.imageSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4592 | copy_region.imageOffset, copy_region.imageExtent, false); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4593 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4594 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4595 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4596 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4597 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4598 | } |
| 4599 | if (skip) break; |
| 4600 | } |
| 4601 | if (skip) break; |
| 4602 | } |
| 4603 | return skip; |
| 4604 | } |
| 4605 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4606 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4607 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4608 | const VkBufferImageCopy *pRegions) const { |
| 4609 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4610 | CMD_COPYBUFFERTOIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 4614 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 4615 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4616 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4617 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2KHR); |
| 4618 | } |
| 4619 | |
| 4620 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, |
| 4621 | const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) const { |
| 4622 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4623 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 4624 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4625 | } |
| 4626 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4627 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4628 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4629 | VkImageLayout dstImageLayout, uint32_t regionCount, const RegionType *pRegions, |
| 4630 | CMD_TYPE cmd_type) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4631 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4632 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4633 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4634 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4635 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4636 | assert(context); |
| 4637 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4638 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 4639 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4640 | |
| 4641 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4642 | const auto ©_region = pRegions[region]; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4643 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4644 | if (src_buffer) { |
| 4645 | ResourceAccessRange src_range = |
| 4646 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4647 | context->UpdateAccessState(*src_buffer, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, src_range, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4648 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4649 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4650 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4651 | } |
| 4652 | } |
| 4653 | } |
| 4654 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4655 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4656 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4657 | const VkBufferImageCopy *pRegions) { |
| 4658 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4659 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, CMD_COPYBUFFERTOIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 4663 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 4664 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 4665 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4666 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4667 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2KHR); |
| 4668 | } |
| 4669 | |
| 4670 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, |
| 4671 | const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) { |
| 4672 | StateTracker::PreCallRecordCmdCopyBufferToImage2(commandBuffer, pCopyBufferToImageInfo); |
| 4673 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4674 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 4675 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4676 | } |
| 4677 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4678 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4679 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4680 | VkBuffer dstBuffer, uint32_t regionCount, const RegionType *pRegions, |
| 4681 | CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4682 | bool skip = false; |
| 4683 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4684 | assert(cb_access_context); |
| 4685 | if (!cb_access_context) return skip; |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4686 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4687 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4688 | assert(context); |
| 4689 | if (!context) return skip; |
| 4690 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4691 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4692 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 4693 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->MemState()->mem() : VK_NULL_HANDLE; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4694 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4695 | const auto ©_region = pRegions[region]; |
| 4696 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4697 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.imageSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4698 | copy_region.imageOffset, copy_region.imageExtent, false); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4699 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4700 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4701 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4702 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4703 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4704 | } |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4705 | if (dst_mem) { |
| 4706 | ResourceAccessRange dst_range = |
| 4707 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4708 | hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4709 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4710 | skip |= |
| 4711 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4712 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 4713 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
| 4714 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4715 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4716 | } |
| 4717 | } |
| 4718 | if (skip) break; |
| 4719 | } |
| 4720 | return skip; |
| 4721 | } |
| 4722 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4723 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 4724 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 4725 | const VkBufferImageCopy *pRegions) const { |
| 4726 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4727 | CMD_COPYIMAGETOBUFFER); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4731 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 4732 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4733 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4734 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2KHR); |
| 4735 | } |
| 4736 | |
| 4737 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, |
| 4738 | const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) const { |
| 4739 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4740 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 4741 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4742 | } |
| 4743 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4744 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4745 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4746 | VkBuffer dstBuffer, uint32_t regionCount, const RegionType *pRegions, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4747 | CMD_TYPE cmd_type) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4748 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4749 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4750 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4751 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4752 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4753 | assert(context); |
| 4754 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4755 | auto src_image = Get<IMAGE_STATE>(srcImage); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4756 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 4757 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->MemState()->mem() : VK_NULL_HANDLE; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 4758 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4759 | |
| 4760 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4761 | const auto ©_region = pRegions[region]; |
| 4762 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4763 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4764 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4765 | if (dst_buffer) { |
| 4766 | ResourceAccessRange dst_range = |
| 4767 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4768 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, dst_range, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4769 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4770 | } |
| 4771 | } |
| 4772 | } |
| 4773 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4774 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4775 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 4776 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4777 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, CMD_COPYIMAGETOBUFFER); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4781 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 4782 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 4783 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4784 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4785 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2KHR); |
| 4786 | } |
| 4787 | |
| 4788 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, |
| 4789 | const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) { |
| 4790 | StateTracker::PreCallRecordCmdCopyImageToBuffer2(commandBuffer, pCopyImageToBufferInfo); |
| 4791 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4792 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 4793 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | template <typename RegionType> |
| 4797 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4798 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4799 | const RegionType *pRegions, VkFilter filter, CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4800 | bool skip = false; |
| 4801 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4802 | assert(cb_access_context); |
| 4803 | if (!cb_access_context) return skip; |
| 4804 | |
| 4805 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4806 | assert(context); |
| 4807 | if (!context) return skip; |
| 4808 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4809 | const char *caller_name = CommandTypeString(cmd_type); |
| 4810 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4811 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4812 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4813 | |
| 4814 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4815 | const auto &blit_region = pRegions[region]; |
| 4816 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4817 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4818 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4819 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4820 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4821 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4822 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].z - blit_region.srcOffsets[0].z))}; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4823 | auto hazard = |
| 4824 | context->DetectHazard(*src_image, SYNC_BLIT_TRANSFER_READ, blit_region.srcSubresource, offset, extent, false); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4825 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4826 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4827 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", caller_name, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4828 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4829 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4830 | } |
| 4831 | } |
| 4832 | |
| 4833 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4834 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4835 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4836 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4837 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4838 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4839 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].z - blit_region.dstOffsets[0].z))}; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4840 | auto hazard = |
| 4841 | context->DetectHazard(*dst_image, SYNC_BLIT_TRANSFER_WRITE, blit_region.dstSubresource, offset, extent, false); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4842 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4843 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4844 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", caller_name, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4845 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4846 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4847 | } |
| 4848 | if (skip) break; |
| 4849 | } |
| 4850 | } |
| 4851 | |
| 4852 | return skip; |
| 4853 | } |
| 4854 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4855 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4856 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4857 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 4858 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4859 | CMD_BLITIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4860 | } |
| 4861 | |
| 4862 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 4863 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 4864 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4865 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4866 | pBlitImageInfo->filter, CMD_BLITIMAGE2KHR); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4867 | } |
| 4868 | |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4869 | bool SyncValidator::PreCallValidateCmdBlitImage2(VkCommandBuffer commandBuffer, |
| 4870 | const VkBlitImageInfo2 *pBlitImageInfo) const { |
| 4871 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4872 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4873 | pBlitImageInfo->filter, CMD_BLITIMAGE2); |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4874 | } |
| 4875 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4876 | template <typename RegionType> |
| 4877 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4878 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4879 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4880 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4881 | assert(cb_access_context); |
| 4882 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4883 | assert(context); |
| 4884 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4885 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4886 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4887 | |
| 4888 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4889 | const auto &blit_region = pRegions[region]; |
| 4890 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4891 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4892 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4893 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4894 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4895 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4896 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].z - blit_region.srcOffsets[0].z))}; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4897 | context->UpdateAccessState(*src_image, SYNC_BLIT_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4898 | blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4899 | } |
| 4900 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4901 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4902 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4903 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4904 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4905 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4906 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].z - blit_region.dstOffsets[0].z))}; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4907 | context->UpdateAccessState(*dst_image, SYNC_BLIT_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4908 | blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4909 | } |
| 4910 | } |
| 4911 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4912 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4913 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4914 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4915 | const VkImageBlit *pRegions, VkFilter filter) { |
| 4916 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4917 | assert(cb_access_context); |
| 4918 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 4919 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4920 | pRegions, filter); |
| 4921 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 4922 | } |
| 4923 | |
| 4924 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 4925 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 4926 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4927 | assert(cb_access_context); |
| 4928 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 4929 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4930 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4931 | pBlitImageInfo->filter, tag); |
| 4932 | } |
| 4933 | |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4934 | void SyncValidator::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) { |
| 4935 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 4936 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4937 | assert(cb_access_context); |
| 4938 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2); |
| 4939 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4940 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4941 | pBlitImageInfo->filter, tag); |
| 4942 | } |
| 4943 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4944 | bool SyncValidator::ValidateIndirectBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4945 | VkCommandBuffer commandBuffer, const VkDeviceSize struct_size, const VkBuffer buffer, |
| 4946 | const VkDeviceSize offset, const uint32_t drawCount, const uint32_t stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4947 | CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4948 | bool skip = false; |
| 4949 | if (drawCount == 0) return skip; |
| 4950 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4951 | const char *caller_name = CommandTypeString(cmd_type); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4952 | auto buf_state = Get<BUFFER_STATE>(buffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4953 | VkDeviceSize size = struct_size; |
| 4954 | if (drawCount == 1 || stride == size) { |
| 4955 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4956 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4957 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4958 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4959 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4960 | "%s: Hazard %s for indirect %s in %s. Access info %s.", caller_name, string_SyncHazard(hazard.hazard), |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4961 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4962 | cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4963 | } |
| 4964 | } else { |
| 4965 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4966 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4967 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4968 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4969 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4970 | "%s: Hazard %s for indirect %s in %s. Access info %s.", caller_name, |
| 4971 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(buffer).c_str(), |
| 4972 | report_data->FormatHandle(commandBuffer).c_str(), cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4973 | break; |
| 4974 | } |
| 4975 | } |
| 4976 | } |
| 4977 | return skip; |
| 4978 | } |
| 4979 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 4980 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag tag, const VkDeviceSize struct_size, |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4981 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 4982 | uint32_t stride) { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4983 | auto buf_state = Get<BUFFER_STATE>(buffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4984 | VkDeviceSize size = struct_size; |
| 4985 | if (drawCount == 1 || stride == size) { |
| 4986 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4987 | const ResourceAccessRange range = MakeRange(offset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4988 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4989 | } else { |
| 4990 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4991 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4992 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, |
| 4993 | tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4994 | } |
| 4995 | } |
| 4996 | } |
| 4997 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4998 | bool SyncValidator::ValidateCountBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4999 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5000 | CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5001 | bool skip = false; |
| 5002 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5003 | auto count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5004 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5005 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 5006 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5007 | skip |= LogError(count_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5008 | "%s: Hazard %s for countBuffer %s in %s. Access info %s.", CommandTypeString(cmd_type), |
| 5009 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(buffer).c_str(), |
| 5010 | report_data->FormatHandle(commandBuffer).c_str(), cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5011 | } |
| 5012 | return skip; |
| 5013 | } |
| 5014 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 5015 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag tag, VkBuffer buffer, VkDeviceSize offset) { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5016 | auto count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5017 | const ResourceAccessRange range = MakeRange(offset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5018 | context.UpdateAccessState(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5019 | } |
| 5020 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 5021 | bool SyncValidator::PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5022 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5023 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5024 | assert(cb_access_context); |
| 5025 | if (!cb_access_context) return skip; |
| 5026 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5027 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5028 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | void SyncValidator::PreCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5032 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5033 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5034 | assert(cb_access_context); |
| 5035 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5036 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5037 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 5038 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5039 | |
| 5040 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5041 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5042 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5043 | assert(cb_access_context); |
| 5044 | if (!cb_access_context) return skip; |
| 5045 | |
| 5046 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5047 | assert(context); |
| 5048 | if (!context) return skip; |
| 5049 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5050 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, CMD_DISPATCHINDIRECT); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5051 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5052 | 1, sizeof(VkDispatchIndirectCommand), CMD_DISPATCHINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5053 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5057 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5058 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5059 | assert(cb_access_context); |
| 5060 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 5061 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5062 | assert(context); |
| 5063 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5064 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 5065 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5066 | } |
| 5067 | |
| 5068 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 5069 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 5070 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5071 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5072 | assert(cb_access_context); |
| 5073 | if (!cb_access_context) return skip; |
| 5074 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5075 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAW); |
| 5076 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, CMD_DRAW); |
| 5077 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAW); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 5078 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 5082 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5083 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5084 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5085 | assert(cb_access_context); |
| 5086 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5087 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5088 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5089 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 5090 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 5094 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 5095 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5096 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5097 | assert(cb_access_context); |
| 5098 | if (!cb_access_context) return skip; |
| 5099 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5100 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAWINDEXED); |
| 5101 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, CMD_DRAWINDEXED); |
| 5102 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAWINDEXED); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 5103 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5104 | } |
| 5105 | |
| 5106 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 5107 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5108 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5109 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5110 | assert(cb_access_context); |
| 5111 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5112 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5113 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5114 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 5115 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5119 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5120 | bool skip = false; |
| 5121 | if (drawCount == 0) return skip; |
| 5122 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5123 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5124 | assert(cb_access_context); |
| 5125 | if (!cb_access_context) return skip; |
| 5126 | |
| 5127 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5128 | assert(context); |
| 5129 | if (!context) return skip; |
| 5130 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5131 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAWINDIRECT); |
| 5132 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAWINDIRECT); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5133 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5134 | drawCount, stride, CMD_DRAWINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5135 | |
| 5136 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 5137 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5138 | // We will validate the vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5139 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, CMD_DRAWINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5140 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5144 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5145 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5146 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5147 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5148 | assert(cb_access_context); |
| 5149 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 5150 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5151 | assert(context); |
| 5152 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5153 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5154 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5155 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5156 | |
| 5157 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 5158 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5159 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5160 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5164 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5165 | bool skip = false; |
| 5166 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5167 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5168 | assert(cb_access_context); |
| 5169 | if (!cb_access_context) return skip; |
| 5170 | |
| 5171 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5172 | assert(context); |
| 5173 | if (!context) return skip; |
| 5174 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5175 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAWINDEXEDINDIRECT); |
| 5176 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAWINDEXEDINDIRECT); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5177 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5178 | offset, drawCount, stride, CMD_DRAWINDEXEDINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5179 | |
| 5180 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 5181 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 5182 | // We will validate the index and vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5183 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, CMD_DRAWINDEXEDINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5184 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5185 | } |
| 5186 | |
| 5187 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5188 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5189 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5190 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5191 | assert(cb_access_context); |
| 5192 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 5193 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5194 | assert(context); |
| 5195 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5196 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5197 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5198 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5199 | |
| 5200 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 5201 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 5202 | // We will record the index and vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5203 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5207 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5208 | uint32_t stride, CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5209 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5210 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5211 | assert(cb_access_context); |
| 5212 | if (!cb_access_context) return skip; |
| 5213 | |
| 5214 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5215 | assert(context); |
| 5216 | if (!context) return skip; |
| 5217 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5218 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, cmd_type); |
| 5219 | skip |= cb_access_context->ValidateDrawSubpassAttachment(cmd_type); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5220 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5221 | maxDrawCount, stride, cmd_type); |
| 5222 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5223 | |
| 5224 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 5225 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5226 | // We will validate the vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5227 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5228 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5229 | } |
| 5230 | |
| 5231 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5232 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5233 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5234 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5235 | CMD_DRAWINDIRECTCOUNT); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5236 | } |
| 5237 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5238 | void SyncValidator::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5239 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5240 | uint32_t stride, CMD_TYPE cmd_type) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5241 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5242 | assert(cb_access_context); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5243 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5244 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5245 | assert(context); |
| 5246 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5247 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5248 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5249 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 5250 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5251 | |
| 5252 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 5253 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5254 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5255 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5256 | } |
| 5257 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5258 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5259 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5260 | uint32_t stride) { |
| 5261 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 5262 | stride); |
| 5263 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5264 | CMD_DRAWINDIRECTCOUNT); |
| 5265 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5266 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5267 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5268 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5269 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5270 | CMD_DRAWINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5274 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5275 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5276 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 5277 | stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5278 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5279 | CMD_DRAWINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5280 | } |
| 5281 | |
| 5282 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5283 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5284 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5285 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5286 | CMD_DRAWINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5290 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5291 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5292 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 5293 | stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5294 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5295 | CMD_DRAWINDIRECTCOUNTAMD); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5299 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5300 | uint32_t stride, CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5301 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5302 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5303 | assert(cb_access_context); |
| 5304 | if (!cb_access_context) return skip; |
| 5305 | |
| 5306 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5307 | assert(context); |
| 5308 | if (!context) return skip; |
| 5309 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5310 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, cmd_type); |
| 5311 | skip |= cb_access_context->ValidateDrawSubpassAttachment(cmd_type); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5312 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5313 | offset, maxDrawCount, stride, cmd_type); |
| 5314 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5315 | |
| 5316 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 5317 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 5318 | // We will validate the index and vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5319 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5320 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5324 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5325 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5326 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5327 | CMD_DRAWINDEXEDINDIRECTCOUNT); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5328 | } |
| 5329 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5330 | void SyncValidator::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5331 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5332 | uint32_t stride, CMD_TYPE cmd_type) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5333 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5334 | assert(cb_access_context); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5335 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5336 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5337 | assert(context); |
| 5338 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5339 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5340 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5341 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 5342 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5343 | |
| 5344 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 5345 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5346 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 5347 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5348 | } |
| 5349 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5350 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5351 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5352 | uint32_t maxDrawCount, uint32_t stride) { |
| 5353 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 5354 | maxDrawCount, stride); |
| 5355 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5356 | CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 5357 | } |
| 5358 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5359 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5360 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5361 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5362 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5363 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5364 | CMD_DRAWINDEXEDINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5368 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5369 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5370 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 5371 | maxDrawCount, stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5372 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5373 | CMD_DRAWINDEXEDINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5377 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5378 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5379 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5380 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5381 | CMD_DRAWINDEXEDINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5385 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5386 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5387 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 5388 | maxDrawCount, stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5389 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5390 | CMD_DRAWINDEXEDINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5394 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 5395 | const VkImageSubresourceRange *pRanges) const { |
| 5396 | bool skip = false; |
| 5397 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5398 | assert(cb_access_context); |
| 5399 | if (!cb_access_context) return skip; |
| 5400 | |
| 5401 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5402 | assert(context); |
| 5403 | if (!context) return skip; |
| 5404 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5405 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5406 | |
| 5407 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5408 | const auto &range = pRanges[index]; |
| 5409 | if (image_state) { |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5410 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5411 | if (hazard.hazard) { |
| 5412 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5413 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5414 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5415 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5416 | } |
| 5417 | } |
| 5418 | } |
| 5419 | return skip; |
| 5420 | } |
| 5421 | |
| 5422 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5423 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 5424 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5425 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5426 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5427 | assert(cb_access_context); |
| 5428 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 5429 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5430 | assert(context); |
| 5431 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5432 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5433 | |
| 5434 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5435 | const auto &range = pRanges[index]; |
| 5436 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5437 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5438 | } |
| 5439 | } |
| 5440 | } |
| 5441 | |
| 5442 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 5443 | VkImageLayout imageLayout, |
| 5444 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 5445 | const VkImageSubresourceRange *pRanges) const { |
| 5446 | bool skip = false; |
| 5447 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5448 | assert(cb_access_context); |
| 5449 | if (!cb_access_context) return skip; |
| 5450 | |
| 5451 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5452 | assert(context); |
| 5453 | if (!context) return skip; |
| 5454 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5455 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5456 | |
| 5457 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5458 | const auto &range = pRanges[index]; |
| 5459 | if (image_state) { |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5460 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5461 | if (hazard.hazard) { |
| 5462 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5463 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5464 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5465 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5466 | } |
| 5467 | } |
| 5468 | } |
| 5469 | return skip; |
| 5470 | } |
| 5471 | |
| 5472 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5473 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 5474 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5475 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5476 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5477 | assert(cb_access_context); |
| 5478 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 5479 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5480 | assert(context); |
| 5481 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5482 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5483 | |
| 5484 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5485 | const auto &range = pRanges[index]; |
| 5486 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5487 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5488 | } |
| 5489 | } |
| 5490 | } |
| 5491 | |
| 5492 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 5493 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 5494 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 5495 | VkQueryResultFlags flags) const { |
| 5496 | bool skip = false; |
| 5497 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5498 | assert(cb_access_context); |
| 5499 | if (!cb_access_context) return skip; |
| 5500 | |
| 5501 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5502 | assert(context); |
| 5503 | if (!context) return skip; |
| 5504 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5505 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5506 | |
| 5507 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5508 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5509 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5510 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5511 | skip |= |
| 5512 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5513 | "vkCmdCopyQueryPoolResults: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5514 | report_data->FormatHandle(dstBuffer).c_str(), cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5515 | } |
| 5516 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5517 | |
| 5518 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5519 | return skip; |
| 5520 | } |
| 5521 | |
| 5522 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 5523 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5524 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5525 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 5526 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5527 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5528 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5529 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5530 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5531 | assert(context); |
| 5532 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5533 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5534 | |
| 5535 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5536 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5537 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5538 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5539 | |
| 5540 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5541 | } |
| 5542 | |
| 5543 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5544 | VkDeviceSize size, uint32_t data) const { |
| 5545 | bool skip = false; |
| 5546 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5547 | assert(cb_access_context); |
| 5548 | if (!cb_access_context) return skip; |
| 5549 | |
| 5550 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5551 | assert(context); |
| 5552 | if (!context) return skip; |
| 5553 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5554 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5555 | |
| 5556 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5557 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5558 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5559 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5560 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5561 | "vkCmdFillBuffer: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5562 | report_data->FormatHandle(dstBuffer).c_str(), cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5563 | } |
| 5564 | } |
| 5565 | return skip; |
| 5566 | } |
| 5567 | |
| 5568 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5569 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5570 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5571 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5572 | assert(cb_access_context); |
| 5573 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 5574 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5575 | assert(context); |
| 5576 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5577 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5578 | |
| 5579 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5580 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5581 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 5586 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 5587 | const VkImageResolve *pRegions) const { |
| 5588 | bool skip = false; |
| 5589 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5590 | assert(cb_access_context); |
| 5591 | if (!cb_access_context) return skip; |
| 5592 | |
| 5593 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5594 | assert(context); |
| 5595 | if (!context) return skip; |
| 5596 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5597 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 5598 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5599 | |
| 5600 | for (uint32_t region = 0; region < regionCount; region++) { |
| 5601 | const auto &resolve_region = pRegions[region]; |
| 5602 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5603 | auto hazard = context->DetectHazard(*src_image, SYNC_RESOLVE_TRANSFER_READ, resolve_region.srcSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5604 | resolve_region.srcOffset, resolve_region.extent, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5605 | if (hazard.hazard) { |
| 5606 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5607 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5608 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5609 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5614 | auto hazard = context->DetectHazard(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, resolve_region.dstSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5615 | resolve_region.dstOffset, resolve_region.extent, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5616 | if (hazard.hazard) { |
| 5617 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5618 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5619 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5620 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5621 | } |
| 5622 | if (skip) break; |
| 5623 | } |
| 5624 | } |
| 5625 | |
| 5626 | return skip; |
| 5627 | } |
| 5628 | |
| 5629 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 5630 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 5631 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5632 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 5633 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5634 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5635 | assert(cb_access_context); |
| 5636 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 5637 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5638 | assert(context); |
| 5639 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 5640 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 5641 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5642 | |
| 5643 | for (uint32_t region = 0; region < regionCount; region++) { |
| 5644 | const auto &resolve_region = pRegions[region]; |
| 5645 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5646 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5647 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5648 | } |
| 5649 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5650 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5651 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5652 | } |
| 5653 | } |
| 5654 | } |
| 5655 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5656 | bool SyncValidator::ValidateCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2KHR *pResolveImageInfo, |
| 5657 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5658 | bool skip = false; |
| 5659 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5660 | assert(cb_access_context); |
| 5661 | if (!cb_access_context) return skip; |
| 5662 | |
| 5663 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5664 | assert(context); |
| 5665 | if (!context) return skip; |
| 5666 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5667 | auto src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 5668 | auto dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5669 | |
| 5670 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 5671 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 5672 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5673 | auto hazard = context->DetectHazard(*src_image, SYNC_RESOLVE_TRANSFER_READ, resolve_region.srcSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5674 | resolve_region.srcOffset, resolve_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5675 | if (hazard.hazard) { |
| 5676 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5677 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5678 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5679 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5680 | } |
| 5681 | } |
| 5682 | |
| 5683 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5684 | auto hazard = context->DetectHazard(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, resolve_region.dstSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5685 | resolve_region.dstOffset, resolve_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5686 | if (hazard.hazard) { |
| 5687 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5688 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5689 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5690 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5691 | } |
| 5692 | if (skip) break; |
| 5693 | } |
| 5694 | } |
| 5695 | |
| 5696 | return skip; |
| 5697 | } |
| 5698 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5699 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 5700 | const VkResolveImageInfo2KHR *pResolveImageInfo) const { |
| 5701 | return ValidateCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2KHR); |
| 5702 | } |
| 5703 | |
| 5704 | bool SyncValidator::PreCallValidateCmdResolveImage2(VkCommandBuffer commandBuffer, |
| 5705 | const VkResolveImageInfo2 *pResolveImageInfo) const { |
| 5706 | return ValidateCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2); |
| 5707 | } |
| 5708 | |
| 5709 | void SyncValidator::RecordCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2KHR *pResolveImageInfo, |
| 5710 | CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5711 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 5712 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5713 | assert(cb_access_context); |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5714 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5715 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5716 | assert(context); |
| 5717 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 5718 | auto src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 5719 | auto dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5720 | |
| 5721 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 5722 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 5723 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5724 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5725 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5726 | } |
| 5727 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5728 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5729 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5730 | } |
| 5731 | } |
| 5732 | } |
| 5733 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5734 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 5735 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 5736 | RecordCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2KHR); |
| 5737 | } |
| 5738 | |
| 5739 | void SyncValidator::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2 *pResolveImageInfo) { |
| 5740 | RecordCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2); |
| 5741 | } |
| 5742 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5743 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5744 | VkDeviceSize dataSize, const void *pData) const { |
| 5745 | bool skip = false; |
| 5746 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5747 | assert(cb_access_context); |
| 5748 | if (!cb_access_context) return skip; |
| 5749 | |
| 5750 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5751 | assert(context); |
| 5752 | if (!context) return skip; |
| 5753 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5754 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5755 | |
| 5756 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5757 | // VK_WHOLE_SIZE not allowed |
| 5758 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5759 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5760 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5761 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5762 | "vkCmdUpdateBuffer: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5763 | report_data->FormatHandle(dstBuffer).c_str(), cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5764 | } |
| 5765 | } |
| 5766 | return skip; |
| 5767 | } |
| 5768 | |
| 5769 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5770 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5771 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5772 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5773 | assert(cb_access_context); |
| 5774 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 5775 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5776 | assert(context); |
| 5777 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5778 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5779 | |
| 5780 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5781 | // VK_WHOLE_SIZE not allowed |
| 5782 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5783 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5784 | } |
| 5785 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5786 | |
| 5787 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 5788 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 5789 | bool skip = false; |
| 5790 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5791 | assert(cb_access_context); |
| 5792 | if (!cb_access_context) return skip; |
| 5793 | |
| 5794 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5795 | assert(context); |
| 5796 | if (!context) return skip; |
| 5797 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5798 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5799 | |
| 5800 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5801 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5802 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5803 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5804 | skip |= |
| 5805 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5806 | "vkCmdWriteBufferMarkerAMD: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5807 | report_data->FormatHandle(dstBuffer).c_str(), cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5808 | } |
| 5809 | } |
| 5810 | return skip; |
| 5811 | } |
| 5812 | |
| 5813 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 5814 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5815 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5816 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5817 | assert(cb_access_context); |
| 5818 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 5819 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5820 | assert(context); |
| 5821 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5822 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5823 | |
| 5824 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5825 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5826 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5827 | } |
| 5828 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5829 | |
| 5830 | bool SyncValidator::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
| 5831 | bool skip = false; |
| 5832 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5833 | assert(cb_context); |
| 5834 | if (!cb_context) return skip; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5835 | const auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5836 | assert(access_context); |
| 5837 | if (!access_context) return skip; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5838 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5839 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask, nullptr); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5840 | return set_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5841 | } |
| 5842 | |
| 5843 | void SyncValidator::PostCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 5844 | StateTracker::PostCallRecordCmdSetEvent(commandBuffer, event, stageMask); |
| 5845 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5846 | assert(cb_context); |
| 5847 | if (!cb_context) return; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5848 | |
| 5849 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask, |
| 5850 | cb_context->GetCurrentAccessContext()); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5851 | } |
| 5852 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5853 | bool SyncValidator::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5854 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 5855 | bool skip = false; |
| 5856 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5857 | assert(cb_context); |
| 5858 | if (!cb_context || !pDependencyInfo) return skip; |
| 5859 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5860 | const auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5861 | assert(access_context); |
| 5862 | if (!access_context) return skip; |
| 5863 | |
| 5864 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo, nullptr); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5865 | return set_event_op.Validate(*cb_context); |
| 5866 | } |
| 5867 | |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5868 | bool SyncValidator::PreCallValidateCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5869 | const VkDependencyInfo *pDependencyInfo) const { |
| 5870 | bool skip = false; |
| 5871 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5872 | assert(cb_context); |
| 5873 | if (!cb_context || !pDependencyInfo) return skip; |
| 5874 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5875 | SyncOpSetEvent set_event_op(CMD_SETEVENT2, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo, nullptr); |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5876 | return set_event_op.Validate(*cb_context); |
| 5877 | } |
| 5878 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5879 | void SyncValidator::PostCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5880 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 5881 | StateTracker::PostCallRecordCmdSetEvent2KHR(commandBuffer, event, pDependencyInfo); |
| 5882 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5883 | assert(cb_context); |
| 5884 | if (!cb_context || !pDependencyInfo) return; |
| 5885 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5886 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo, |
| 5887 | cb_context->GetCurrentAccessContext()); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5888 | } |
| 5889 | |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5890 | void SyncValidator::PostCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5891 | const VkDependencyInfo *pDependencyInfo) { |
| 5892 | StateTracker::PostCallRecordCmdSetEvent2(commandBuffer, event, pDependencyInfo); |
| 5893 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5894 | assert(cb_context); |
| 5895 | if (!cb_context || !pDependencyInfo) return; |
| 5896 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5897 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT2, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo, |
| 5898 | cb_context->GetCurrentAccessContext()); |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5899 | } |
| 5900 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5901 | bool SyncValidator::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 5902 | VkPipelineStageFlags stageMask) const { |
| 5903 | bool skip = false; |
| 5904 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5905 | assert(cb_context); |
| 5906 | if (!cb_context) return skip; |
| 5907 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5908 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5909 | return reset_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | void SyncValidator::PostCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 5913 | StateTracker::PostCallRecordCmdResetEvent(commandBuffer, event, stageMask); |
| 5914 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5915 | assert(cb_context); |
| 5916 | if (!cb_context) return; |
| 5917 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5918 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5919 | } |
| 5920 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5921 | bool SyncValidator::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5922 | VkPipelineStageFlags2KHR stageMask) const { |
| 5923 | bool skip = false; |
| 5924 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5925 | assert(cb_context); |
| 5926 | if (!cb_context) return skip; |
| 5927 | |
| 5928 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5929 | return reset_event_op.Validate(*cb_context); |
| 5930 | } |
| 5931 | |
Tony-LunarG | a2662db | 2021-11-16 07:26:24 -0700 | [diff] [blame] | 5932 | bool SyncValidator::PreCallValidateCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5933 | VkPipelineStageFlags2 stageMask) const { |
| 5934 | bool skip = false; |
| 5935 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5936 | assert(cb_context); |
| 5937 | if (!cb_context) return skip; |
| 5938 | |
| 5939 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5940 | return reset_event_op.Validate(*cb_context); |
| 5941 | } |
| 5942 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5943 | void SyncValidator::PostCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5944 | VkPipelineStageFlags2KHR stageMask) { |
| 5945 | StateTracker::PostCallRecordCmdResetEvent2KHR(commandBuffer, event, stageMask); |
| 5946 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5947 | assert(cb_context); |
| 5948 | if (!cb_context) return; |
| 5949 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5950 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5951 | } |
| 5952 | |
Tony-LunarG | a2662db | 2021-11-16 07:26:24 -0700 | [diff] [blame] | 5953 | void SyncValidator::PostCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2 stageMask) { |
| 5954 | StateTracker::PostCallRecordCmdResetEvent2(commandBuffer, event, stageMask); |
| 5955 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5956 | assert(cb_context); |
| 5957 | if (!cb_context) return; |
| 5958 | |
| 5959 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT2, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5960 | } |
| 5961 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5962 | bool SyncValidator::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5963 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5964 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5965 | uint32_t bufferMemoryBarrierCount, |
| 5966 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5967 | uint32_t imageMemoryBarrierCount, |
| 5968 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 5969 | bool skip = false; |
| 5970 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5971 | assert(cb_context); |
| 5972 | if (!cb_context) return skip; |
| 5973 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5974 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 5975 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 5976 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5977 | return wait_events_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5978 | } |
| 5979 | |
| 5980 | void SyncValidator::PostCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5981 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5982 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5983 | uint32_t bufferMemoryBarrierCount, |
| 5984 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5985 | uint32_t imageMemoryBarrierCount, |
| 5986 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 5987 | StateTracker::PostCallRecordCmdWaitEvents(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
| 5988 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 5989 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 5990 | |
| 5991 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5992 | assert(cb_context); |
| 5993 | if (!cb_context) return; |
| 5994 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5995 | cb_context->RecordSyncOp<SyncOpWaitEvents>( |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 5996 | CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5997 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5998 | } |
| 5999 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6000 | bool SyncValidator::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 6001 | const VkDependencyInfoKHR *pDependencyInfos) const { |
| 6002 | bool skip = false; |
| 6003 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 6004 | assert(cb_context); |
| 6005 | if (!cb_context) return skip; |
| 6006 | |
| 6007 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 6008 | skip |= wait_events_op.Validate(*cb_context); |
| 6009 | return skip; |
| 6010 | } |
| 6011 | |
| 6012 | void SyncValidator::PostCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 6013 | const VkDependencyInfoKHR *pDependencyInfos) { |
| 6014 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 6015 | |
| 6016 | auto *cb_context = GetAccessContext(commandBuffer); |
| 6017 | assert(cb_context); |
| 6018 | if (!cb_context) return; |
| 6019 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6020 | cb_context->RecordSyncOp<SyncOpWaitEvents>(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, |
| 6021 | pDependencyInfos); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6022 | } |
| 6023 | |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 6024 | bool SyncValidator::PreCallValidateCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 6025 | const VkDependencyInfo *pDependencyInfos) const { |
| 6026 | bool skip = false; |
| 6027 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 6028 | assert(cb_context); |
| 6029 | if (!cb_context) return skip; |
| 6030 | |
| 6031 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 6032 | skip |= wait_events_op.Validate(*cb_context); |
| 6033 | return skip; |
| 6034 | } |
| 6035 | |
| 6036 | void SyncValidator::PostCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 6037 | const VkDependencyInfo *pDependencyInfos) { |
| 6038 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 6039 | |
| 6040 | auto *cb_context = GetAccessContext(commandBuffer); |
| 6041 | assert(cb_context); |
| 6042 | if (!cb_context) return; |
| 6043 | |
| 6044 | cb_context->RecordSyncOp<SyncOpWaitEvents>(CMD_WAITEVENTS2, *this, cb_context->GetQueueFlags(), eventCount, pEvents, |
| 6045 | pDependencyInfos); |
| 6046 | } |
| 6047 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6048 | void SyncEventState::ResetFirstScope() { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6049 | first_scope.reset(); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 6050 | scope = SyncExecScope(); |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6051 | first_scope_tag = 0; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6052 | } |
| 6053 | |
| 6054 | // Keep the "ignore this event" logic in same place for ValidateWait and RecordWait to use |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6055 | SyncEventState::IgnoreReason SyncEventState::IsIgnoredByWait(CMD_TYPE cmd_type, VkPipelineStageFlags2KHR srcStageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6056 | IgnoreReason reason = NotIgnored; |
| 6057 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6058 | if ((CMD_WAITEVENTS2KHR == cmd_type || CMD_WAITEVENTS2 == cmd_type) && (CMD_SETEVENT == last_command)) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6059 | reason = SetVsWait2; |
| 6060 | } else if ((last_command == CMD_RESETEVENT || last_command == CMD_RESETEVENT2KHR) && !HasBarrier(0U, 0U)) { |
| 6061 | reason = (last_command == CMD_RESETEVENT) ? ResetWaitRace : Reset2WaitRace; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6062 | } else if (unsynchronized_set) { |
| 6063 | reason = SetRace; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6064 | } else if (first_scope) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6065 | const VkPipelineStageFlags2KHR missing_bits = scope.mask_param & ~srcStageMask; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6066 | // Note it is the "not missing bits" path that is the only "NotIgnored" path |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6067 | if (missing_bits) reason = MissingStageBits; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6068 | } else { |
| 6069 | reason = MissingSetEvent; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | return reason; |
| 6073 | } |
| 6074 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6075 | bool SyncEventState::HasBarrier(VkPipelineStageFlags2KHR stageMask, VkPipelineStageFlags2KHR exec_scope_arg) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6076 | bool has_barrier = (last_command == CMD_NONE) || (stageMask & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) || |
| 6077 | (barriers & exec_scope_arg) || (barriers & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 6078 | return has_barrier; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 6079 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6080 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6081 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 6082 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 6083 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6084 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 6085 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 6086 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6087 | : SyncOpBase(cmd_type), barriers_(1) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6088 | auto &barrier_set = barriers_[0]; |
| 6089 | barrier_set.dependency_flags = dependencyFlags; |
| 6090 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, srcStageMask); |
| 6091 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, dstStageMask); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6092 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6093 | barrier_set.MakeMemoryBarriers(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, memoryBarrierCount, |
| 6094 | pMemoryBarriers); |
| 6095 | barrier_set.MakeBufferMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 6096 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
| 6097 | barrier_set.MakeImageMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 6098 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6099 | } |
| 6100 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6101 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t event_count, |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6102 | const VkDependencyInfoKHR *dep_infos) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6103 | : SyncOpBase(cmd_type), barriers_(event_count) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6104 | for (uint32_t i = 0; i < event_count; i++) { |
| 6105 | const auto &dep_info = dep_infos[i]; |
| 6106 | auto &barrier_set = barriers_[i]; |
| 6107 | barrier_set.dependency_flags = dep_info.dependencyFlags; |
| 6108 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 6109 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, stage_masks.src); |
| 6110 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, stage_masks.dst); |
| 6111 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
| 6112 | barrier_set.MakeMemoryBarriers(queue_flags, dep_info.dependencyFlags, dep_info.memoryBarrierCount, |
| 6113 | dep_info.pMemoryBarriers); |
| 6114 | barrier_set.MakeBufferMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.bufferMemoryBarrierCount, |
| 6115 | dep_info.pBufferMemoryBarriers); |
| 6116 | barrier_set.MakeImageMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.imageMemoryBarrierCount, |
| 6117 | dep_info.pImageMemoryBarriers); |
| 6118 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6119 | } |
| 6120 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6121 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6122 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 6123 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 6124 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 6125 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 6126 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6127 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, |
| 6128 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 6129 | pImageMemoryBarriers) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6130 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6131 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6132 | const VkDependencyInfoKHR &dep_info) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6133 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, 1, &dep_info) {} |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6134 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6135 | bool SyncOpPipelineBarrier::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6136 | bool skip = false; |
| 6137 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 6138 | assert(context); |
| 6139 | if (!context) return skip; |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 6140 | assert(barriers_.size() == 1); // PipelineBarriers only support a single barrier set. |
| 6141 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6142 | // Validate Image Layout transitions |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 6143 | const auto &barrier_set = barriers_[0]; |
| 6144 | for (const auto &image_barrier : barrier_set.image_memory_barriers) { |
| 6145 | if (image_barrier.new_layout == image_barrier.old_layout) continue; // Only interested in layout transitions at this point. |
| 6146 | const auto *image_state = image_barrier.image.get(); |
| 6147 | if (!image_state) continue; |
| 6148 | const auto hazard = context->DetectImageBarrierHazard(image_barrier); |
| 6149 | if (hazard.hazard) { |
| 6150 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 6151 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6152 | const auto image_handle = image_state->image(); |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 6153 | skip |= sync_state.LogError(image_handle, string_SyncHazardVUID(hazard.hazard), |
| 6154 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 6155 | string_SyncHazard(hazard.hazard), image_barrier.index, |
| 6156 | sync_state.report_data->FormatHandle(image_handle).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6157 | cb_context.FormatHazard(hazard).c_str()); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6158 | } |
| 6159 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6160 | return skip; |
| 6161 | } |
| 6162 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6163 | struct SyncOpPipelineBarrierFunctorFactory { |
| 6164 | using BarrierOpFunctor = PipelineBarrierOp; |
| 6165 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 6166 | using GlobalBarrierOpFunctor = PipelineBarrierOp; |
| 6167 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 6168 | using BufferRange = ResourceAccessRange; |
| 6169 | using ImageRange = subresource_adapter::ImageRangeGenerator; |
| 6170 | using GlobalRange = ResourceAccessRange; |
| 6171 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6172 | ApplyFunctor MakeApplyFunctor(QueueId queue_id, const SyncBarrier &barrier, bool layout_transition) const { |
| 6173 | return ApplyFunctor(BarrierOpFunctor(queue_id, barrier, layout_transition)); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6174 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 6175 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6176 | return GlobalApplyFunctor(true /* resolve */, size_hint, tag); |
| 6177 | } |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6178 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(QueueId queue_id, const SyncBarrier &barrier) const { |
| 6179 | return GlobalBarrierOpFunctor(queue_id, barrier, false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6180 | } |
| 6181 | |
| 6182 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range) const { |
| 6183 | if (!SimpleBinding(buffer)) return ResourceAccessRange(); |
| 6184 | const auto base_address = ResourceBaseAddress(buffer); |
| 6185 | return (range + base_address); |
| 6186 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 6187 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 6188 | if (!SimpleBinding(image)) return subresource_adapter::ImageRangeGenerator(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6189 | |
| 6190 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 6191 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address, false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6192 | return range_gen; |
| 6193 | } |
| 6194 | GlobalRange MakeGlobalRangeGen(AccessAddressType) const { return kFullRange; } |
| 6195 | }; |
| 6196 | |
| 6197 | template <typename Barriers, typename FunctorFactory> |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6198 | void SyncOpBarriers::ApplyBarriers(const Barriers &barriers, const FunctorFactory &factory, const QueueId queue_id, |
| 6199 | const ResourceUsageTag tag, AccessContext *context) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6200 | for (const auto &barrier : barriers) { |
| 6201 | const auto *state = barrier.GetState(); |
| 6202 | if (state) { |
| 6203 | auto *const accesses = &context->GetAccessStateMap(GetAccessAddressType(*state)); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6204 | auto update_action = factory.MakeApplyFunctor(queue_id, barrier.barrier, barrier.IsLayoutTransition()); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6205 | auto range_gen = factory.MakeRangeGen(*state, barrier.Range()); |
| 6206 | UpdateMemoryAccessState(accesses, update_action, &range_gen); |
| 6207 | } |
| 6208 | } |
| 6209 | } |
| 6210 | |
| 6211 | template <typename Barriers, typename FunctorFactory> |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6212 | void SyncOpBarriers::ApplyGlobalBarriers(const Barriers &barriers, const FunctorFactory &factory, const QueueId queue_id, |
| 6213 | const ResourceUsageTag tag, AccessContext *access_context) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6214 | auto barriers_functor = factory.MakeGlobalApplyFunctor(barriers.size(), tag); |
| 6215 | for (const auto &barrier : barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6216 | barriers_functor.EmplaceBack(factory.MakeGlobalBarrierOpFunctor(queue_id, barrier)); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6217 | } |
| 6218 | for (const auto address_type : kAddressTypes) { |
| 6219 | auto range_gen = factory.MakeGlobalRangeGen(address_type); |
| 6220 | UpdateMemoryAccessState(&(access_context->GetAccessStateMap(address_type)), barriers_functor, &range_gen); |
| 6221 | } |
| 6222 | } |
| 6223 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 6224 | ResourceUsageTag SyncOpPipelineBarrier::Record(CommandBufferAccessContext *cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6225 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6226 | ReplayRecord(*cb_context, tag); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6227 | return tag; |
| 6228 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6229 | |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6230 | void SyncOpPipelineBarrier::ReplayRecord(CommandExecutionContext &exec_context, const ResourceUsageTag tag) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6231 | SyncOpPipelineBarrierFunctorFactory factory; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6232 | // Pipeline barriers only have a single barrier set, unlike WaitEvents2 |
| 6233 | assert(barriers_.size() == 1); |
| 6234 | const auto &barrier_set = barriers_[0]; |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6235 | if (!exec_context.ValidForSyncOps()) return; |
| 6236 | |
| 6237 | SyncEventsContext *events_context = exec_context.GetCurrentEventsContext(); |
| 6238 | AccessContext *access_context = exec_context.GetCurrentAccessContext(); |
| 6239 | const auto queue_id = exec_context.GetQueueId(); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6240 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, queue_id, tag, access_context); |
| 6241 | ApplyBarriers(barrier_set.image_memory_barriers, factory, queue_id, tag, access_context); |
| 6242 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, queue_id, tag, access_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6243 | if (barrier_set.single_exec_scope) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6244 | events_context->ApplyBarrier(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, tag); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6245 | } else { |
| 6246 | for (const auto &barrier : barrier_set.memory_barriers) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6247 | events_context->ApplyBarrier(barrier.src_exec_scope, barrier.dst_exec_scope, tag); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6248 | } |
| 6249 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6250 | } |
| 6251 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6252 | bool SyncOpPipelineBarrier::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6253 | ResourceUsageTag base_tag, CommandExecutionContext &exec_context) const { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6254 | // No Validation for replay, as the layout transition accesses are checked directly, and the src*Mask ordering is captured |
| 6255 | // with first access information. |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6256 | return false; |
| 6257 | } |
| 6258 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6259 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(const SyncExecScope &src, const SyncExecScope &dst, |
| 6260 | VkDependencyFlags dependency_flags, uint32_t memory_barrier_count, |
| 6261 | const VkMemoryBarrier *barriers) { |
| 6262 | memory_barriers.reserve(std::max<uint32_t>(1, memory_barrier_count)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6263 | for (uint32_t barrier_index = 0; barrier_index < memory_barrier_count; barrier_index++) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6264 | const auto &barrier = barriers[barrier_index]; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6265 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6266 | memory_barriers.emplace_back(sync_barrier); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6267 | } |
| 6268 | if (0 == memory_barrier_count) { |
| 6269 | // If there are no global memory barriers, force an exec barrier |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6270 | memory_barriers.emplace_back(SyncBarrier(src, dst)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6271 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6272 | single_exec_scope = true; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6275 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 6276 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 6277 | uint32_t barrier_count, const VkBufferMemoryBarrier *barriers) { |
| 6278 | buffer_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6279 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6280 | const auto &barrier = barriers[index]; |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6281 | auto buffer = sync_state.Get<BUFFER_STATE>(barrier.buffer); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6282 | if (buffer) { |
| 6283 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 6284 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 6285 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6286 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6287 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6288 | buffer_memory_barriers.emplace_back(); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6289 | } |
| 6290 | } |
| 6291 | } |
| 6292 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6293 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(VkQueueFlags queue_flags, VkDependencyFlags dependency_flags, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 6294 | uint32_t memory_barrier_count, const VkMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6295 | memory_barriers.reserve(memory_barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6296 | for (uint32_t barrier_index = 0; barrier_index < memory_barrier_count; barrier_index++) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6297 | const auto &barrier = barriers[barrier_index]; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6298 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 6299 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 6300 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6301 | memory_barriers.emplace_back(sync_barrier); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6302 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6303 | single_exec_scope = false; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6304 | } |
| 6305 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6306 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6307 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 6308 | const VkBufferMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6309 | buffer_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6310 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6311 | const auto &barrier = barriers[index]; |
| 6312 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 6313 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6314 | auto buffer = sync_state.Get<BUFFER_STATE>(barrier.buffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6315 | if (buffer) { |
| 6316 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 6317 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 6318 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6319 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6320 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6321 | buffer_memory_barriers.emplace_back(); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6322 | } |
| 6323 | } |
| 6324 | } |
| 6325 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6326 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 6327 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 6328 | uint32_t barrier_count, const VkImageMemoryBarrier *barriers) { |
| 6329 | image_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6330 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6331 | const auto &barrier = barriers[index]; |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6332 | auto image = sync_state.Get<IMAGE_STATE>(barrier.image); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6333 | if (image) { |
| 6334 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 6335 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6336 | image_memory_barriers.emplace_back(image, index, sync_barrier, barrier.oldLayout, barrier.newLayout, subresource_range); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6337 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6338 | image_memory_barriers.emplace_back(); |
| 6339 | image_memory_barriers.back().index = index; // Just in case we're interested in the ones we skipped. |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6340 | } |
| 6341 | } |
| 6342 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6343 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6344 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6345 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 6346 | const VkImageMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6347 | image_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6348 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6349 | const auto &barrier = barriers[index]; |
| 6350 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 6351 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6352 | auto image = sync_state.Get<IMAGE_STATE>(barrier.image); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6353 | if (image) { |
| 6354 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 6355 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6356 | image_memory_barriers.emplace_back(image, index, sync_barrier, barrier.oldLayout, barrier.newLayout, subresource_range); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6357 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6358 | image_memory_barriers.emplace_back(); |
| 6359 | image_memory_barriers.back().index = index; // Just in case we're interested in the ones we skipped. |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6360 | } |
| 6361 | } |
| 6362 | } |
| 6363 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6364 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6365 | uint32_t eventCount, const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, |
| 6366 | VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, |
| 6367 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 6368 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 6369 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
| 6370 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, srcStageMask, dstStageMask, VkDependencyFlags(0U), memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6371 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 6372 | pImageMemoryBarriers) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6373 | MakeEventsList(sync_state, eventCount, pEvents); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6374 | } |
| 6375 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6376 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6377 | uint32_t eventCount, const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfo) |
| 6378 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, eventCount, pDependencyInfo) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6379 | MakeEventsList(sync_state, eventCount, pEvents); |
| 6380 | assert(events_.size() == barriers_.size()); // Just so nobody gets clever and decides to cull the event or barrier arrays |
| 6381 | } |
| 6382 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6383 | const char *const SyncOpWaitEvents::kIgnored = "Wait operation is ignored for this event."; |
| 6384 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6385 | bool SyncOpWaitEvents::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6386 | bool skip = false; |
| 6387 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6388 | const auto command_buffer_handle = cb_context.GetCBState().commandBuffer(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6389 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6390 | // This is only interesting at record and not replay (Execute/Submit) time. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6391 | for (size_t barrier_set_index = 0; barrier_set_index < barriers_.size(); barrier_set_index++) { |
| 6392 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6393 | if (barrier_set.single_exec_scope) { |
| 6394 | if (barrier_set.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 6395 | const std::string vuid = std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 6396 | skip = sync_state.LogInfo(command_buffer_handle, vuid, |
| 6397 | "%s, srcStageMask includes %s, unsupported by synchronization validation.", CmdName(), |
| 6398 | string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT)); |
| 6399 | } else { |
| 6400 | const auto &barriers = barrier_set.memory_barriers; |
| 6401 | for (size_t barrier_index = 0; barrier_index < barriers.size(); barrier_index++) { |
| 6402 | const auto &barrier = barriers[barrier_index]; |
| 6403 | if (barrier.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 6404 | const std::string vuid = |
| 6405 | std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 6406 | skip = |
| 6407 | sync_state.LogInfo(command_buffer_handle, vuid, |
| 6408 | "%s, srcStageMask %s of %s %zu, %s %zu, unsupported by synchronization validation.", |
| 6409 | CmdName(), string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT), |
| 6410 | "pDependencyInfo", barrier_set_index, "pMemoryBarriers", barrier_index); |
| 6411 | } |
| 6412 | } |
| 6413 | } |
| 6414 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6415 | } |
| 6416 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6417 | // The rest is common to record time and replay time. |
| 6418 | skip |= DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6419 | return skip; |
| 6420 | } |
| 6421 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6422 | bool SyncOpWaitEvents::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6423 | bool skip = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6424 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6425 | const QueueId queue_id = exec_context.GetQueueId(); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6426 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6427 | VkPipelineStageFlags2KHR event_stage_masks = 0U; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6428 | VkPipelineStageFlags2KHR barrier_mask_params = 0U; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6429 | bool events_not_found = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6430 | const auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6431 | assert(events_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6432 | size_t barrier_set_index = 0; |
| 6433 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6434 | for (const auto &event : events_) { |
| 6435 | const auto *sync_event = events_context->Get(event.get()); |
| 6436 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6437 | if (!sync_event) { |
| 6438 | // NOTE PHASE2: This is where we'll need queue submit time validation to come back and check the srcStageMask bits |
| 6439 | // or solve this with replay creating the SyncEventState in the queue context... also this will be a |
| 6440 | // new validation error... wait without previously submitted set event... |
| 6441 | events_not_found = true; // Demote "extra_stage_bits" error to warning, to avoid false positives at *record time* |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6442 | barrier_set_index += barrier_set_incr; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6443 | continue; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6444 | } |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6445 | |
| 6446 | // For replay calls, don't revalidate "same command buffer" events |
| 6447 | if (sync_event->last_command_tag > base_tag) continue; |
| 6448 | |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6449 | const auto event_handle = sync_event->event->event(); |
| 6450 | // TODO add "destroyed" checks |
| 6451 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6452 | if (sync_event->first_scope) { |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6453 | // Only accumulate barrier and event stages if there is a pending set in the current context |
| 6454 | barrier_mask_params |= barrier_set.src_exec_scope.mask_param; |
| 6455 | event_stage_masks |= sync_event->scope.mask_param; |
| 6456 | } |
| 6457 | |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6458 | const auto &src_exec_scope = barrier_set.src_exec_scope; |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6459 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6460 | const auto ignore_reason = sync_event->IsIgnoredByWait(cmd_type_, src_exec_scope.mask_param); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6461 | if (ignore_reason) { |
| 6462 | switch (ignore_reason) { |
| 6463 | case SyncEventState::ResetWaitRace: |
| 6464 | case SyncEventState::Reset2WaitRace: { |
| 6465 | // Four permuations of Reset and Wait calls... |
| 6466 | const char *vuid = |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6467 | (cmd_type_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent-event-03834" : "VUID-vkCmdResetEvent-event-03835"; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6468 | if (ignore_reason == SyncEventState::Reset2WaitRace) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6469 | vuid = (cmd_type_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent2-event-03831" |
| 6470 | : "VUID-vkCmdResetEvent2-event-03832"; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6471 | } |
| 6472 | const char *const message = |
| 6473 | "%s: %s %s operation following %s without intervening execution barrier, may cause race condition. %s"; |
| 6474 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6475 | sync_state.report_data->FormatHandle(event_handle).c_str(), CmdName(), |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6476 | CommandTypeString(sync_event->last_command), kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6477 | break; |
| 6478 | } |
| 6479 | case SyncEventState::SetRace: { |
| 6480 | // Issue error message that Wait is waiting on an signal subject to race condition, and is thus ignored for |
| 6481 | // this event |
| 6482 | const char *const vuid = "SYNC-vkCmdWaitEvents-unsynchronized-setops"; |
| 6483 | const char *const message = |
| 6484 | "%s: %s Unsychronized %s calls result in race conditions w.r.t. event signalling, %s %s"; |
| 6485 | const char *const reason = "First synchronization scope is undefined."; |
| 6486 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6487 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6488 | CommandTypeString(sync_event->last_command), reason, kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6489 | break; |
| 6490 | } |
| 6491 | case SyncEventState::MissingStageBits: { |
| 6492 | const auto missing_bits = sync_event->scope.mask_param & ~src_exec_scope.mask_param; |
| 6493 | // Issue error message that event waited for is not in wait events scope |
| 6494 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 6495 | const char *const message = "%s: %s stageMask %" PRIx64 " includes bits not present in srcStageMask 0x%" PRIx64 |
| 6496 | ". Bits missing from srcStageMask %s. %s"; |
| 6497 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6498 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 6499 | sync_event->scope.mask_param, src_exec_scope.mask_param, |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6500 | sync_utils::StringPipelineStageFlags(missing_bits).c_str(), kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6501 | break; |
| 6502 | } |
| 6503 | case SyncEventState::SetVsWait2: { |
Tony-LunarG | 279601c | 2021-11-16 10:50:51 -0700 | [diff] [blame] | 6504 | skip |= sync_state.LogError(event_handle, "VUID-vkCmdWaitEvents2-pEvents-03837", |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6505 | "%s: Follows set of %s by %s. Disallowed.", CmdName(), |
| 6506 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 6507 | CommandTypeString(sync_event->last_command)); |
| 6508 | break; |
| 6509 | } |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6510 | case SyncEventState::MissingSetEvent: { |
| 6511 | // TODO: There are conditions at queue submit time where we can definitively say that |
| 6512 | // a missing set event is an error. Add those if not captured in CoreChecks |
| 6513 | break; |
| 6514 | } |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6515 | default: |
| 6516 | assert(ignore_reason == SyncEventState::NotIgnored); |
| 6517 | } |
| 6518 | } else if (barrier_set.image_memory_barriers.size()) { |
| 6519 | const auto &image_memory_barriers = barrier_set.image_memory_barriers; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6520 | const auto *context = exec_context.GetCurrentAccessContext(); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6521 | assert(context); |
| 6522 | for (const auto &image_memory_barrier : image_memory_barriers) { |
| 6523 | if (image_memory_barrier.old_layout == image_memory_barrier.new_layout) continue; |
| 6524 | const auto *image_state = image_memory_barrier.image.get(); |
| 6525 | if (!image_state) continue; |
| 6526 | const auto &subresource_range = image_memory_barrier.range; |
| 6527 | const auto &src_access_scope = image_memory_barrier.barrier.src_access_scope; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6528 | const auto hazard = context->DetectImageBarrierHazard(*image_state, subresource_range, sync_event->scope.exec_scope, |
| 6529 | src_access_scope, queue_id, *sync_event, |
| 6530 | AccessContext::DetectOptions::kDetectAll); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6531 | if (hazard.hazard) { |
| 6532 | skip |= sync_state.LogError(image_state->image(), string_SyncHazardVUID(hazard.hazard), |
| 6533 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 6534 | string_SyncHazard(hazard.hazard), image_memory_barrier.index, |
| 6535 | sync_state.report_data->FormatHandle(image_state->image()).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6536 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6537 | break; |
| 6538 | } |
| 6539 | } |
| 6540 | } |
| 6541 | // TODO: Add infrastructure for checking pDependencyInfo's vs. CmdSetEvent2 VUID - vkCmdWaitEvents2KHR - pEvents - |
| 6542 | // 03839 |
| 6543 | barrier_set_index += barrier_set_incr; |
| 6544 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6545 | |
| 6546 | // Note that we can't check for HOST in pEvents as we don't track that set event type |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6547 | const auto extra_stage_bits = (barrier_mask_params & ~VK_PIPELINE_STAGE_2_HOST_BIT_KHR) & ~event_stage_masks; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6548 | if (extra_stage_bits) { |
| 6549 | // Issue error message that event waited for is not in wait events scope |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6550 | // NOTE: This isn't exactly the right VUID for WaitEvents2, but it's as close as we currently have support for |
| 6551 | const char *const vuid = |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6552 | (CMD_WAITEVENTS == cmd_type_) ? "VUID-vkCmdWaitEvents-srcStageMask-01158" : "VUID-vkCmdWaitEvents2-pEvents-03838"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6553 | const char *const message = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6554 | "%s: srcStageMask 0x%" PRIx64 " contains stages not present in pEvents stageMask. Extra stages are %s.%s"; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6555 | const auto handle = exec_context.Handle(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6556 | if (events_not_found) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6557 | skip |= sync_state.LogInfo(handle, vuid, message, CmdName(), barrier_mask_params, |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6558 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6559 | " vkCmdSetEvent may be in previously submitted command buffer."); |
| 6560 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6561 | skip |= sync_state.LogError(handle, vuid, message, CmdName(), barrier_mask_params, |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6562 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), ""); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6563 | } |
| 6564 | } |
| 6565 | return skip; |
| 6566 | } |
| 6567 | |
| 6568 | struct SyncOpWaitEventsFunctorFactory { |
| 6569 | using BarrierOpFunctor = WaitEventBarrierOp; |
| 6570 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 6571 | using GlobalBarrierOpFunctor = WaitEventBarrierOp; |
| 6572 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 6573 | using BufferRange = EventSimpleRangeGenerator; |
| 6574 | using ImageRange = EventImageRangeGenerator; |
| 6575 | using GlobalRange = EventSimpleRangeGenerator; |
| 6576 | |
| 6577 | // Need to restrict to only valid exec and access scope for this event |
| 6578 | // Pass by value is intentional to get a copy we can change without modifying the passed barrier |
| 6579 | SyncBarrier RestrictToEvent(SyncBarrier barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 6580 | barrier.src_exec_scope.exec_scope = sync_event->scope.exec_scope & barrier.src_exec_scope.exec_scope; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6581 | barrier.src_access_scope = sync_event->scope.valid_accesses & barrier.src_access_scope; |
| 6582 | return barrier; |
| 6583 | } |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6584 | ApplyFunctor MakeApplyFunctor(QueueId queue_id, const SyncBarrier &barrier_arg, bool layout_transition) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6585 | auto barrier = RestrictToEvent(barrier_arg); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6586 | return ApplyFunctor(BarrierOpFunctor(queue_id, sync_event->first_scope_tag, barrier, layout_transition)); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6587 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 6588 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6589 | return GlobalApplyFunctor(false /* don't resolve */, size_hint, tag); |
| 6590 | } |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6591 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const QueueId queue_id, const SyncBarrier &barrier_arg) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6592 | auto barrier = RestrictToEvent(barrier_arg); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6593 | return GlobalBarrierOpFunctor(queue_id, sync_event->first_scope_tag, barrier, false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6594 | } |
| 6595 | |
| 6596 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range_arg) const { |
| 6597 | const AccessAddressType address_type = GetAccessAddressType(buffer); |
| 6598 | const auto base_address = ResourceBaseAddress(buffer); |
| 6599 | ResourceAccessRange range = SimpleBinding(buffer) ? (range_arg + base_address) : ResourceAccessRange(); |
| 6600 | EventSimpleRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), range); |
| 6601 | return filtered_range_gen; |
| 6602 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 6603 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6604 | if (!SimpleBinding(image)) return ImageRange(); |
| 6605 | const auto address_type = GetAccessAddressType(image); |
| 6606 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 6607 | subresource_adapter::ImageRangeGenerator image_range_gen(*image.fragment_encoder.get(), subresource_range, base_address, |
| 6608 | false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6609 | EventImageRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), image_range_gen); |
| 6610 | |
| 6611 | return filtered_range_gen; |
| 6612 | } |
| 6613 | GlobalRange MakeGlobalRangeGen(AccessAddressType address_type) const { |
| 6614 | return EventSimpleRangeGenerator(sync_event->FirstScope(address_type), kFullRange); |
| 6615 | } |
| 6616 | SyncOpWaitEventsFunctorFactory(SyncEventState *sync_event_) : sync_event(sync_event_) { assert(sync_event); } |
| 6617 | SyncEventState *sync_event; |
| 6618 | }; |
| 6619 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 6620 | ResourceUsageTag SyncOpWaitEvents::Record(CommandBufferAccessContext *cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6621 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6622 | |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6623 | ReplayRecord(*cb_context, tag); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6624 | return tag; |
| 6625 | } |
| 6626 | |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6627 | void SyncOpWaitEvents::ReplayRecord(CommandExecutionContext &exec_context, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6628 | // Unlike PipelineBarrier, WaitEvent is *not* limited to accesses within the current subpass (if any) and thus needs to import |
| 6629 | // all accesses. Can instead import for all first_scopes, or a union of them, if this becomes a performance/memory issue, |
| 6630 | // but with no idea of the performance of the union, nor of whether it even matters... take the simplest approach here, |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6631 | if (!exec_context.ValidForSyncOps()) return; |
| 6632 | AccessContext *access_context = exec_context.GetCurrentAccessContext(); |
| 6633 | SyncEventsContext *events_context = exec_context.GetCurrentEventsContext(); |
| 6634 | const QueueId queue_id = exec_context.GetQueueId(); |
| 6635 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6636 | access_context->ResolvePreviousAccesses(); |
| 6637 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6638 | size_t barrier_set_index = 0; |
| 6639 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 6640 | assert(barriers_.size() == 1 || (barriers_.size() == events_.size())); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6641 | for (auto &event_shared : events_) { |
| 6642 | if (!event_shared.get()) continue; |
| 6643 | auto *sync_event = events_context->GetFromShared(event_shared); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6644 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6645 | sync_event->last_command = cmd_type_; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6646 | sync_event->last_command_tag = tag; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6647 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6648 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6649 | const auto &dst = barrier_set.dst_exec_scope; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6650 | if (!sync_event->IsIgnoredByWait(cmd_type_, barrier_set.src_exec_scope.mask_param)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6651 | // These apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 6652 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 6653 | // of the barriers is maintained. |
| 6654 | SyncOpWaitEventsFunctorFactory factory(sync_event); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6655 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, queue_id, tag, access_context); |
| 6656 | ApplyBarriers(barrier_set.image_memory_barriers, factory, queue_id, tag, access_context); |
| 6657 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, queue_id, tag, access_context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6658 | |
| 6659 | // Apply the global barrier to the event itself (for race condition tracking) |
| 6660 | // Events don't happen at a stage, so we need to store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 6661 | sync_event->barriers = dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 6662 | sync_event->barriers |= dst.exec_scope; |
| 6663 | } else { |
| 6664 | // We ignored this wait, so we don't have any effective synchronization barriers for it. |
| 6665 | sync_event->barriers = 0U; |
| 6666 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6667 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | // Apply the pending barriers |
| 6671 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
| 6672 | access_context->ApplyToContext(apply_pending_action); |
| 6673 | } |
| 6674 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6675 | bool SyncOpWaitEvents::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6676 | ResourceUsageTag base_tag, CommandExecutionContext &exec_context) const { |
| 6677 | return DoValidate(exec_context, base_tag); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6678 | } |
| 6679 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6680 | bool SyncValidator::PreCallValidateCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 6681 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 6682 | bool skip = false; |
| 6683 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 6684 | assert(cb_access_context); |
| 6685 | if (!cb_access_context) return skip; |
| 6686 | |
| 6687 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 6688 | assert(context); |
| 6689 | if (!context) return skip; |
| 6690 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6691 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6692 | |
| 6693 | if (dst_buffer) { |
| 6694 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 6695 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
| 6696 | if (hazard.hazard) { |
| 6697 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 6698 | "vkCmdWriteBufferMarkerAMD2: Hazard %s for dstBuffer %s. Access info %s.", |
| 6699 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6700 | cb_access_context->FormatHazard(hazard).c_str()); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6701 | } |
| 6702 | } |
| 6703 | return skip; |
| 6704 | } |
| 6705 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6706 | void SyncOpWaitEvents::MakeEventsList(const SyncValidator &sync_state, uint32_t event_count, const VkEvent *events) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6707 | events_.reserve(event_count); |
| 6708 | for (uint32_t event_index = 0; event_index < event_count; event_index++) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6709 | events_.emplace_back(sync_state.Get<EVENT_STATE>(events[event_index])); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6710 | } |
| 6711 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6712 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6713 | SyncOpResetEvent::SyncOpResetEvent(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6714 | VkPipelineStageFlags2KHR stageMask) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6715 | : SyncOpBase(cmd_type), |
| 6716 | event_(sync_state.Get<EVENT_STATE>(event)), |
| 6717 | exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6718 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6719 | bool SyncOpResetEvent::Validate(const CommandBufferAccessContext& cb_context) const { |
| 6720 | return DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6721 | } |
| 6722 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6723 | bool SyncOpResetEvent::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
| 6724 | auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6725 | assert(events_context); |
| 6726 | bool skip = false; |
| 6727 | if (!events_context) return skip; |
| 6728 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6729 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6730 | const auto *sync_event = events_context->Get(event_); |
| 6731 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 6732 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6733 | if (sync_event->last_command_tag > base_tag) return skip; // if we validated this in recording of the secondary, don't repeat |
| 6734 | |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6735 | const char *const set_wait = |
| 6736 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 6737 | "hazards."; |
| 6738 | const char *message = set_wait; // Only one message this call. |
| 6739 | if (!sync_event->HasBarrier(exec_scope_.mask_param, exec_scope_.exec_scope)) { |
| 6740 | const char *vuid = nullptr; |
| 6741 | switch (sync_event->last_command) { |
| 6742 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6743 | case CMD_SETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6744 | case CMD_SETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6745 | // Needs a barrier between set and reset |
| 6746 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-set"; |
| 6747 | break; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6748 | case CMD_WAITEVENTS: |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 6749 | case CMD_WAITEVENTS2: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6750 | case CMD_WAITEVENTS2KHR: { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6751 | // Needs to be in the barriers chain (either because of a barrier, or because of dstStageMask |
| 6752 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-wait"; |
| 6753 | break; |
| 6754 | } |
| 6755 | default: |
| 6756 | // The only other valid last command that wasn't one. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6757 | assert((sync_event->last_command == CMD_NONE) || (sync_event->last_command == CMD_RESETEVENT) || |
| 6758 | (sync_event->last_command == CMD_RESETEVENT2KHR)); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6759 | break; |
| 6760 | } |
| 6761 | if (vuid) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6762 | skip |= sync_state.LogError(event_->event(), vuid, message, CmdName(), |
| 6763 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6764 | CommandTypeString(sync_event->last_command)); |
| 6765 | } |
| 6766 | } |
| 6767 | return skip; |
| 6768 | } |
| 6769 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 6770 | ResourceUsageTag SyncOpResetEvent::Record(CommandBufferAccessContext *cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6771 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6772 | ReplayRecord(*cb_context, tag); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6773 | return tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6774 | } |
| 6775 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6776 | bool SyncOpResetEvent::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6777 | ResourceUsageTag base_tag, CommandExecutionContext &exec_context) const { |
| 6778 | return DoValidate(exec_context, base_tag); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6779 | } |
| 6780 | |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6781 | void SyncOpResetEvent::ReplayRecord(CommandExecutionContext &exec_context, ResourceUsageTag tag) const { |
| 6782 | if (!exec_context.ValidForSyncOps()) return; |
| 6783 | SyncEventsContext *events_context = exec_context.GetCurrentEventsContext(); |
| 6784 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6785 | auto *sync_event = events_context->GetFromShared(event_); |
| 6786 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 6787 | |
| 6788 | // Update the event state |
| 6789 | sync_event->last_command = cmd_type_; |
| 6790 | sync_event->last_command_tag = tag; |
| 6791 | sync_event->unsynchronized_set = CMD_NONE; |
| 6792 | sync_event->ResetFirstScope(); |
| 6793 | sync_event->barriers = 0U; |
| 6794 | } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6795 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6796 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6797 | VkPipelineStageFlags2KHR stageMask, const AccessContext *access_context) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6798 | : SyncOpBase(cmd_type), |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6799 | event_(sync_state.Get<EVENT_STATE>(event)), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6800 | recorded_context_(), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6801 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6802 | dep_info_() { |
| 6803 | // Snapshot the current access_context for later inspection at wait time. |
| 6804 | // NOTE: This appears brute force, but given that we only save a "first-last" model of access history, the current |
| 6805 | // access context (include barrier state for chaining) won't necessarily contain the needed information at Wait |
| 6806 | // or Submit time reference. |
| 6807 | if (access_context) { |
| 6808 | recorded_context_ = std::make_shared<const AccessContext>(*access_context); |
| 6809 | } |
| 6810 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6811 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6812 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6813 | const VkDependencyInfoKHR &dep_info, const AccessContext *access_context) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6814 | : SyncOpBase(cmd_type), |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6815 | event_(sync_state.Get<EVENT_STATE>(event)), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6816 | recorded_context_(), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6817 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, sync_utils::GetGlobalStageMasks(dep_info).src)), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6818 | dep_info_(new safe_VkDependencyInfo(&dep_info)) { |
| 6819 | if (access_context) { |
| 6820 | recorded_context_ = std::make_shared<const AccessContext>(*access_context); |
| 6821 | } |
| 6822 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6823 | |
| 6824 | bool SyncOpSetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6825 | return DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6826 | } |
| 6827 | bool SyncOpSetEvent::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6828 | ResourceUsageTag base_tag, CommandExecutionContext &exec_context) const { |
| 6829 | return DoValidate(exec_context, base_tag); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6830 | } |
| 6831 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6832 | bool SyncOpSetEvent::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6833 | bool skip = false; |
| 6834 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6835 | const auto &sync_state = exec_context.GetSyncState(); |
| 6836 | auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6837 | assert(events_context); |
| 6838 | if (!events_context) return skip; |
| 6839 | |
| 6840 | const auto *sync_event = events_context->Get(event_); |
| 6841 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 6842 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6843 | if (sync_event->last_command_tag >= base_tag) return skip; // for replay we don't want to revalidate internal "last commmand" |
| 6844 | |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6845 | const char *const reset_set = |
| 6846 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 6847 | "hazards."; |
| 6848 | const char *const wait = |
| 6849 | "%s: %s %s operation following %s without intervening vkCmdResetEvent, may result in data hazard and is ignored."; |
| 6850 | |
| 6851 | if (!sync_event->HasBarrier(src_exec_scope_.mask_param, src_exec_scope_.exec_scope)) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6852 | const char *vuid_stem = nullptr; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6853 | const char *message = nullptr; |
| 6854 | switch (sync_event->last_command) { |
| 6855 | case CMD_RESETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6856 | case CMD_RESETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6857 | case CMD_RESETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6858 | // Needs a barrier between reset and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6859 | vuid_stem = "-missingbarrier-reset"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6860 | message = reset_set; |
| 6861 | break; |
| 6862 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6863 | case CMD_SETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6864 | case CMD_SETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6865 | // Needs a barrier between set and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6866 | vuid_stem = "-missingbarrier-set"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6867 | message = reset_set; |
| 6868 | break; |
| 6869 | case CMD_WAITEVENTS: |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 6870 | case CMD_WAITEVENTS2: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6871 | case CMD_WAITEVENTS2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6872 | // Needs a barrier or is in second execution scope |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6873 | vuid_stem = "-missingbarrier-wait"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6874 | message = wait; |
| 6875 | break; |
| 6876 | default: |
| 6877 | // The only other valid last command that wasn't one. |
| 6878 | assert(sync_event->last_command == CMD_NONE); |
| 6879 | break; |
| 6880 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6881 | if (vuid_stem) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6882 | assert(nullptr != message); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6883 | std::string vuid("SYNC-"); |
| 6884 | vuid.append(CmdName()).append(vuid_stem); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6885 | skip |= sync_state.LogError(event_->event(), vuid.c_str(), message, CmdName(), |
| 6886 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6887 | CommandTypeString(sync_event->last_command)); |
| 6888 | } |
| 6889 | } |
| 6890 | |
| 6891 | return skip; |
| 6892 | } |
| 6893 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 6894 | ResourceUsageTag SyncOpSetEvent::Record(CommandBufferAccessContext *cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6895 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6896 | auto *events_context = cb_context->GetCurrentEventsContext(); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6897 | const QueueId queue_id = cb_context->GetQueueId(); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6898 | assert(recorded_context_); |
| 6899 | if (recorded_context_ && events_context) { |
| 6900 | DoRecord(queue_id, tag, recorded_context_, events_context); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6901 | } |
| 6902 | return tag; |
| 6903 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6904 | |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6905 | void SyncOpSetEvent::ReplayRecord(CommandExecutionContext &exec_context, ResourceUsageTag tag) const { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6906 | // Create a copy of the current context, and merge in the state snapshot at record set event time |
| 6907 | // Note: we mustn't change the recorded context copy, as a given CB could be submitted more than once (in generaL) |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 6908 | if (!exec_context.ValidForSyncOps()) return; |
| 6909 | SyncEventsContext *events_context = exec_context.GetCurrentEventsContext(); |
| 6910 | AccessContext *access_context = exec_context.GetCurrentAccessContext(); |
| 6911 | const QueueId queue_id = exec_context.GetQueueId(); |
| 6912 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6913 | auto merged_context = std::make_shared<AccessContext>(*access_context); |
| 6914 | merged_context->ResolveFromContext(QueueTagOffsetBarrierAction(queue_id, tag), *recorded_context_); |
| 6915 | DoRecord(queue_id, tag, merged_context, events_context); |
| 6916 | } |
| 6917 | |
| 6918 | void SyncOpSetEvent::DoRecord(QueueId queue_id, ResourceUsageTag tag, const std::shared_ptr<const AccessContext> &access_context, |
| 6919 | SyncEventsContext *events_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6920 | auto *sync_event = events_context->GetFromShared(event_); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6921 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6922 | |
| 6923 | // NOTE: We're going to simply record the sync scope here, as anything else would be implementation defined/undefined |
| 6924 | // and we're issuing errors re: missing barriers between event commands, which if the user fixes would fix |
| 6925 | // any issues caused by naive scope setting here. |
| 6926 | |
| 6927 | // What happens with two SetEvent is that one cannot know what group of operations will be waited for. |
| 6928 | // Given: |
| 6929 | // Stuff1; SetEvent; Stuff2; SetEvent; WaitEvents; |
| 6930 | // WaitEvents cannot know which of Stuff1, Stuff2, or both has completed execution. |
| 6931 | |
| 6932 | if (!sync_event->HasBarrier(src_exec_scope_.mask_param, src_exec_scope_.exec_scope)) { |
| 6933 | sync_event->unsynchronized_set = sync_event->last_command; |
| 6934 | sync_event->ResetFirstScope(); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6935 | } else if (!sync_event->first_scope) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6936 | // We only set the scope if there isn't one |
| 6937 | sync_event->scope = src_exec_scope_; |
| 6938 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6939 | // Save the shared_ptr to copy of the access_context present at set time (sent us by the caller) |
| 6940 | sync_event->first_scope = access_context; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6941 | sync_event->unsynchronized_set = CMD_NONE; |
| 6942 | sync_event->first_scope_tag = tag; |
| 6943 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6944 | // TODO: Store dep_info_ shared ptr in sync_state for WaitEvents2 validation |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6945 | sync_event->last_command = cmd_type_; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6946 | sync_event->last_command_tag = tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6947 | sync_event->barriers = 0U; |
| 6948 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6949 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6950 | SyncOpBeginRenderPass::SyncOpBeginRenderPass(CMD_TYPE cmd_type, const SyncValidator &sync_state, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6951 | const VkRenderPassBeginInfo *pRenderPassBegin, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 6952 | const VkSubpassBeginInfo *pSubpassBeginInfo) |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 6953 | : SyncOpBase(cmd_type), rp_context_(nullptr) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6954 | if (pRenderPassBegin) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6955 | rp_state_ = sync_state.Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6956 | renderpass_begin_info_ = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6957 | auto fb_state = sync_state.Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6958 | if (fb_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6959 | shared_attachments_ = sync_state.GetAttachmentViews(*renderpass_begin_info_.ptr(), *fb_state); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6960 | // TODO: Revisit this when all attachment validation is through SyncOps to see if we can discard the plain pointer copy |
| 6961 | // Note that this a safe to presist as long as shared_attachments is not cleared |
| 6962 | attachments_.reserve(shared_attachments_.size()); |
sfricke-samsung | 01c9ae9 | 2021-02-09 22:30:52 -0800 | [diff] [blame] | 6963 | for (const auto &attachment : shared_attachments_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6964 | attachments_.emplace_back(attachment.get()); |
| 6965 | } |
| 6966 | } |
| 6967 | if (pSubpassBeginInfo) { |
| 6968 | subpass_begin_info_ = safe_VkSubpassBeginInfo(pSubpassBeginInfo); |
| 6969 | } |
| 6970 | } |
| 6971 | } |
| 6972 | |
| 6973 | bool SyncOpBeginRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6974 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 6975 | bool skip = false; |
| 6976 | |
| 6977 | assert(rp_state_.get()); |
| 6978 | if (nullptr == rp_state_.get()) return skip; |
| 6979 | auto &rp_state = *rp_state_.get(); |
| 6980 | |
| 6981 | const uint32_t subpass = 0; |
| 6982 | |
| 6983 | // Construct the state we can use to validate against... (since validation is const and RecordCmdBeginRenderPass |
| 6984 | // hasn't happened yet) |
| 6985 | const std::vector<AccessContext> empty_context_vector; |
| 6986 | AccessContext temp_context(subpass, cb_context.GetQueueFlags(), rp_state.subpass_dependencies, empty_context_vector, |
| 6987 | cb_context.GetCurrentAccessContext()); |
| 6988 | |
| 6989 | // Validate attachment operations |
| 6990 | if (attachments_.size() == 0) return skip; |
| 6991 | const auto &render_area = renderpass_begin_info_.renderArea; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 6992 | |
| 6993 | // Since the isn't a valid RenderPassAccessContext until Record, needs to create the view/generator list... we could limit this |
| 6994 | // by predicating on whether subpass 0 uses the attachment if it is too expensive to create the full list redundantly here. |
| 6995 | // More broadly we could look at thread specific state shared between Validate and Record as is done for other heavyweight |
| 6996 | // operations (though it's currently a messy approach) |
| 6997 | AttachmentViewGenVector view_gens = RenderPassAccessContext::CreateAttachmentViewGen(render_area, attachments_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6998 | skip |= temp_context.ValidateLayoutTransitions(cb_context, rp_state, render_area, subpass, view_gens, cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6999 | |
| 7000 | // Validate load operations if there were no layout transition hazards |
| 7001 | if (!skip) { |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 7002 | temp_context.RecordLayoutTransitions(rp_state, subpass, view_gens, kInvalidTag); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7003 | skip |= temp_context.ValidateLoadOperation(cb_context, rp_state, render_area, subpass, view_gens, cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7004 | } |
| 7005 | |
| 7006 | return skip; |
| 7007 | } |
| 7008 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 7009 | ResourceUsageTag SyncOpBeginRenderPass::Record(CommandBufferAccessContext *cb_context) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7010 | assert(rp_state_.get()); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7011 | if (nullptr == rp_state_.get()) return cb_context->NextCommandTag(cmd_type_); |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 7012 | const ResourceUsageTag begin_tag = |
| 7013 | cb_context->RecordBeginRenderPass(cmd_type_, *rp_state_.get(), renderpass_begin_info_.renderArea, attachments_); |
| 7014 | |
| 7015 | // Note: this state update must be after RecordBeginRenderPass as there is no current render pass until that function runs |
| 7016 | rp_context_ = cb_context->GetCurrentRenderPassContext(); |
| 7017 | |
| 7018 | return begin_tag; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7019 | } |
| 7020 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7021 | bool SyncOpBeginRenderPass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 7022 | ResourceUsageTag base_tag, CommandExecutionContext &exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7023 | return false; |
| 7024 | } |
| 7025 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 7026 | void SyncOpBeginRenderPass::ReplayRecord(CommandExecutionContext &exec_context, ResourceUsageTag tag) const { |
| 7027 | // Need to update the exec_contexts state (which for RenderPass operations *must* be a QueueBatchContext, as |
| 7028 | // render pass operations are not allowed in secondary command buffers. |
| 7029 | const QueueId queue_id = exec_context.GetQueueId(); |
| 7030 | assert(queue_id != QueueSyncState::kQueueIdInvalid); // Renderpass replay only valid at submit (not exec) time |
| 7031 | if (queue_id == QueueSyncState::kQueueIdInvalid) return; |
| 7032 | |
| 7033 | exec_context.BeginRenderPassReplay(*this, tag); |
| 7034 | } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7035 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7036 | SyncOpNextSubpass::SyncOpNextSubpass(CMD_TYPE cmd_type, const SyncValidator &sync_state, |
| 7037 | const VkSubpassBeginInfo *pSubpassBeginInfo, const VkSubpassEndInfo *pSubpassEndInfo) |
| 7038 | : SyncOpBase(cmd_type) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7039 | if (pSubpassBeginInfo) { |
| 7040 | subpass_begin_info_.initialize(pSubpassBeginInfo); |
| 7041 | } |
| 7042 | if (pSubpassEndInfo) { |
| 7043 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 7044 | } |
| 7045 | } |
| 7046 | |
| 7047 | bool SyncOpNextSubpass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 7048 | bool skip = false; |
| 7049 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 7050 | if (!renderpass_context) return skip; |
| 7051 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7052 | skip |= renderpass_context->ValidateNextSubpass(cb_context.GetExecutionContext(), cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7053 | return skip; |
| 7054 | } |
| 7055 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 7056 | ResourceUsageTag SyncOpNextSubpass::Record(CommandBufferAccessContext *cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7057 | return cb_context->RecordNextSubpass(cmd_type_); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7058 | } |
| 7059 | |
| 7060 | bool SyncOpNextSubpass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 7061 | ResourceUsageTag base_tag, CommandExecutionContext &exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7062 | return false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7063 | } |
| 7064 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7065 | SyncOpEndRenderPass::SyncOpEndRenderPass(CMD_TYPE cmd_type, const SyncValidator &sync_state, |
| 7066 | const VkSubpassEndInfo *pSubpassEndInfo) |
| 7067 | : SyncOpBase(cmd_type) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7068 | if (pSubpassEndInfo) { |
| 7069 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 7070 | } |
| 7071 | } |
| 7072 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 7073 | void SyncOpNextSubpass::ReplayRecord(CommandExecutionContext &exec_context, ResourceUsageTag tag) const { |
| 7074 | exec_context.NextSubpassReplay(); |
| 7075 | } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7076 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7077 | bool SyncOpEndRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 7078 | bool skip = false; |
| 7079 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 7080 | |
| 7081 | if (!renderpass_context) return skip; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7082 | skip |= renderpass_context->ValidateEndRenderPass(cb_context.GetExecutionContext(), cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7083 | return skip; |
| 7084 | } |
| 7085 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 7086 | ResourceUsageTag SyncOpEndRenderPass::Record(CommandBufferAccessContext *cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7087 | return cb_context->RecordEndRenderPass(cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7088 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 7089 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7090 | bool SyncOpEndRenderPass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 7091 | ResourceUsageTag base_tag, CommandExecutionContext &exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7092 | return false; |
| 7093 | } |
| 7094 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 7095 | void SyncOpEndRenderPass::ReplayRecord(CommandExecutionContext &exec_context, ResourceUsageTag tag) const { |
| 7096 | exec_context.EndRenderPassReplay(); |
| 7097 | } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7098 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 7099 | void SyncValidator::PreCallRecordCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 7100 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
| 7101 | StateTracker::PreCallRecordCmdWriteBufferMarker2AMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
| 7102 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 7103 | assert(cb_access_context); |
| 7104 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 7105 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 7106 | assert(context); |
| 7107 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 7108 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 7109 | |
| 7110 | if (dst_buffer) { |
| 7111 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 7112 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
| 7113 | } |
| 7114 | } |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 7115 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7116 | bool SyncValidator::PreCallValidateCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 7117 | const VkCommandBuffer *pCommandBuffers) const { |
| 7118 | bool skip = StateTracker::PreCallValidateCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7119 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 7120 | assert(cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7121 | |
| 7122 | // Heavyweight, but we need a proxy copy of the active command buffer access context |
| 7123 | CommandBufferAccessContext proxy_cb_context(*cb_context, CommandBufferAccessContext::AsProxyContext()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7124 | |
| 7125 | // Make working copies of the access and events contexts |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7126 | for (uint32_t cb_index = 0; cb_index < commandBufferCount; ++cb_index) { |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 7127 | proxy_cb_context.NextIndexedCommandTag(CMD_EXECUTECOMMANDS, cb_index); |
| 7128 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7129 | const auto *recorded_cb_context = GetAccessContext(pCommandBuffers[cb_index]); |
| 7130 | if (!recorded_cb_context) continue; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7131 | |
| 7132 | const auto *recorded_context = recorded_cb_context->GetCurrentAccessContext(); |
| 7133 | assert(recorded_context); |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 7134 | skip |= recorded_cb_context->ValidateFirstUse(proxy_cb_context, "vkCmdExecuteCommands", cb_index); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7135 | |
| 7136 | // The barriers have already been applied in ValidatFirstUse |
| 7137 | ResourceUsageRange tag_range = proxy_cb_context.ImportRecordedAccessLog(*recorded_cb_context); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7138 | proxy_cb_context.ResolveExecutedCommandBuffer(*recorded_context, tag_range.begin); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7139 | } |
| 7140 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7141 | return skip; |
| 7142 | } |
| 7143 | |
| 7144 | void SyncValidator::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 7145 | const VkCommandBuffer *pCommandBuffers) { |
| 7146 | StateTracker::PreCallRecordCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7147 | auto *cb_context = GetAccessContext(commandBuffer); |
| 7148 | assert(cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7149 | for (uint32_t cb_index = 0; cb_index < commandBufferCount; ++cb_index) { |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 7150 | cb_context->NextIndexedCommandTag(CMD_EXECUTECOMMANDS, cb_index); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7151 | const auto *recorded_cb_context = GetAccessContext(pCommandBuffers[cb_index]); |
| 7152 | if (!recorded_cb_context) continue; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7153 | cb_context->RecordExecutedCommandBuffer(*recorded_cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7154 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7155 | } |
| 7156 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7157 | void SyncValidator::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) { |
| 7158 | StateTracker::PostCallRecordQueueWaitIdle(queue, result); |
| 7159 | if ((result != VK_SUCCESS) || (!enabled[sync_validation_queue_submit]) || (queue == VK_NULL_HANDLE)) return; |
| 7160 | |
| 7161 | const auto queue_state = GetQueueSyncStateShared(queue); |
| 7162 | if (!queue_state) return; // Invalid queue |
| 7163 | QueueId waited_queue = queue_state->GetQueueId(); |
| 7164 | |
| 7165 | // We need to go through every queue batch context and clear all accesses this wait synchronizes |
| 7166 | // As usual -- two groups, the "last batch" and the signaled semaphores |
| 7167 | // NOTE: Since ApplyTaggedWait crawls through every usage in every ResourceAccessState in the AccessContext of *every* |
| 7168 | // QueueBatchContext, track which we've done to avoid duplicate traversals |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7169 | QueueBatchContext::BatchSet queue_batch_contexts = GetQueueBatchSnapshot(); |
| 7170 | for (auto &batch : queue_batch_contexts) { |
| 7171 | batch->ApplyTaggedWait(waited_queue, ResourceUsageRecord::kMaxIndex); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7172 | } |
| 7173 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7174 | // TODO: Fences affected by Wait |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7175 | } |
| 7176 | |
| 7177 | void SyncValidator::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) { |
| 7178 | StateTracker::PostCallRecordDeviceWaitIdle(device, result); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7179 | |
| 7180 | QueueBatchContext::BatchSet queue_batch_contexts = GetQueueBatchSnapshot(); |
| 7181 | for (auto &batch : queue_batch_contexts) { |
| 7182 | batch->ApplyDeviceWait(); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7183 | } |
| 7184 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7185 | // TODO: Update Fences affected by Wait |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7186 | } |
| 7187 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7188 | struct QueueSubmitCmdState { |
| 7189 | std::shared_ptr<const QueueSyncState> queue; |
| 7190 | std::shared_ptr<QueueBatchContext> last_batch; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7191 | AccessLogger logger; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7192 | SignaledSemaphores signaled; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7193 | QueueSubmitCmdState(const AccessLogger &parent_log, const SignaledSemaphores &parent_semaphores) |
| 7194 | : logger(&parent_log), signaled(parent_semaphores) {} |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7195 | }; |
| 7196 | |
| 7197 | template <> |
| 7198 | thread_local layer_data::optional<QueueSubmitCmdState> layer_data::TlsGuard<QueueSubmitCmdState>::payload_{}; |
| 7199 | |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7200 | bool SyncValidator::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, |
| 7201 | VkFence fence) const { |
| 7202 | bool skip = false; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7203 | |
| 7204 | // Since this early return is above the TlsGuard, the Record phase must also be. |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7205 | if (!enabled[sync_validation_queue_submit]) return skip; |
| 7206 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7207 | layer_data::TlsGuard<QueueSubmitCmdState> cmd_state(&skip, global_access_log_, signaled_semaphores_); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7208 | const auto fence_state = Get<FENCE_STATE>(fence); |
| 7209 | cmd_state->queue = GetQueueSyncStateShared(queue); |
| 7210 | if (!cmd_state->queue) return skip; // Invalid Queue |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7211 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7212 | // The submit id is a mutable automic which is not recoverable on a skip == true condition |
| 7213 | uint64_t submit_id = cmd_state->queue->ReserveSubmitId(); |
| 7214 | |
| 7215 | // verify each submit batch |
| 7216 | // Since the last batch from the queue state is const, we need to track the last_batch separately from the |
| 7217 | // most recently created batch |
| 7218 | std::shared_ptr<const QueueBatchContext> last_batch = cmd_state->queue->LastBatch(); |
| 7219 | std::shared_ptr<QueueBatchContext> batch; |
| 7220 | for (uint32_t batch_idx = 0; batch_idx < submitCount; batch_idx++) { |
| 7221 | const VkSubmitInfo &submit = pSubmits[batch_idx]; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7222 | batch = std::make_shared<QueueBatchContext>(*this, *cmd_state->queue); |
| 7223 | batch->Setup(last_batch, submit, cmd_state->signaled); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7224 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7225 | // Skip import and validation of empty batches |
| 7226 | if (batch->GetTagRange().size()) { |
| 7227 | batch->SetBatchLog(cmd_state->logger, submit_id, batch_idx); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7228 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7229 | // For each submit in the batch... |
| 7230 | for (const auto &cb : *batch) { |
| 7231 | if (cb.cb->GetTagLimit() == 0) continue; // Skip empty CB's |
John Zulauf | 0223f14 | 2022-07-06 09:05:39 -0600 | [diff] [blame] | 7232 | skip |= cb.cb->ValidateFirstUse(*batch.get(), "vkQueueSubmit", cb.index); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7233 | |
| 7234 | // The barriers have already been applied in ValidatFirstUse |
| 7235 | ResourceUsageRange tag_range = batch->ImportRecordedAccessLog(*cb.cb); |
| 7236 | batch->ResolveSubmittedCommandBuffer(*cb.cb->GetCurrentAccessContext(), tag_range.begin); |
| 7237 | } |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7238 | } |
| 7239 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7240 | // Empty batches could have semaphores, though. |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7241 | for (auto &sem : layer_data::make_span(submit.pSignalSemaphores, submit.signalSemaphoreCount)) { |
| 7242 | // Make a copy of the state, signal the copy and pend it... |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7243 | auto sem_state = Get<SEMAPHORE_STATE>(sem); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7244 | if (!sem_state) continue; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7245 | auto semaphore_info = lvl_init_struct<VkSemaphoreSubmitInfo>(); |
| 7246 | semaphore_info.stageMask = VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT; |
| 7247 | cmd_state->signaled.SignalSemaphore(sem_state, batch, semaphore_info); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7248 | } |
| 7249 | // Unless the previous batch was referenced by a signal, the QueueBatchContext will self destruct, but as |
| 7250 | // we ResolvePrevious as we can let any contexts we've fully referenced go. |
| 7251 | last_batch = batch; |
| 7252 | } |
| 7253 | // The most recently created batch will become the queue's "last batch" in the record phase |
| 7254 | if (batch) { |
| 7255 | cmd_state->last_batch = std::move(batch); |
| 7256 | } |
| 7257 | |
| 7258 | // Note that if we skip, guard cleans up for us, but cannot release the reserved tag range |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7259 | return skip; |
| 7260 | } |
| 7261 | |
| 7262 | void SyncValidator::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence, |
| 7263 | VkResult result) { |
| 7264 | StateTracker::PostCallRecordQueueSubmit(queue, submitCount, pSubmits, fence, result); |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7265 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7266 | // If this return is above the TlsGuard, then the Validate phase return must also be. |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7267 | if (!enabled[sync_validation_queue_submit]) return; // Queue submit validation must be affirmatively enabled |
| 7268 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7269 | // The earliest return (when enabled), must be *after* the TlsGuard, as it is the TlsGuard that cleans up the cmd_state |
| 7270 | // static payload |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7271 | layer_data::TlsGuard<QueueSubmitCmdState> cmd_state; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7272 | |
| 7273 | if (VK_SUCCESS != result) return; // dispatched QueueSubmit failed |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7274 | if (!cmd_state->queue) return; // Validation couldn't find a valid queue object |
| 7275 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7276 | // Don't need to look up the queue state again, but we need a non-const version |
| 7277 | std::shared_ptr<QueueSyncState> queue_state = std::const_pointer_cast<QueueSyncState>(std::move(cmd_state->queue)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7278 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7279 | // The global the semaphores we applied to the cmd_state QueueBatchContexts |
| 7280 | // NOTE: All conserved QueueBatchContext's need to have there access logs reset to use the global logger and the only conserved |
| 7281 | // QBC's are those referenced by unwaited signals and the last batch. |
| 7282 | for (auto &sig_sem : cmd_state->signaled) { |
| 7283 | if (sig_sem.second && sig_sem.second->batch) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7284 | auto &sig_batch = sig_sem.second->batch; |
| 7285 | sig_batch->ResetAccessLog(); |
| 7286 | // Batches retained for signalled semaphore don't need to retain event data, unless it's the last batch in the submit |
| 7287 | if (sig_batch != cmd_state->last_batch) { |
| 7288 | sig_batch->ResetEventsContext(); |
| 7289 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7290 | } |
| 7291 | signaled_semaphores_.Import(sig_sem.first, std::move(sig_sem.second)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7292 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7293 | cmd_state->signaled.Reset(); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7294 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7295 | // Update the queue to point to the last batch from the submit |
| 7296 | if (cmd_state->last_batch) { |
| 7297 | cmd_state->last_batch->ResetAccessLog(); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7298 | |
| 7299 | // Clean up the events data in the previous last batch on queue, as only the subsequent batches have valid use for them |
| 7300 | // and the QueueBatchContext::Setup calls have be copying them along from batch to batch during submit. |
| 7301 | auto last_batch = queue_state->LastBatch(); |
| 7302 | if (last_batch) { |
| 7303 | last_batch->ResetEventsContext(); |
| 7304 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7305 | queue_state->SetLastBatch(std::move(cmd_state->last_batch)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7306 | } |
| 7307 | |
| 7308 | // Update the global access log from the one built during validation |
| 7309 | global_access_log_.MergeMove(std::move(cmd_state->logger)); |
| 7310 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7311 | |
| 7312 | // WIP: record information about fences |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7313 | } |
| 7314 | |
| 7315 | bool SyncValidator::PreCallValidateQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 7316 | VkFence fence) const { |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7317 | bool skip = false; |
| 7318 | if (!enabled[sync_validation_queue_submit]) return skip; |
| 7319 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7320 | // WIP: Add Submit2 support |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7321 | return skip; |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7322 | } |
| 7323 | |
| 7324 | void SyncValidator::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 7325 | VkFence fence, VkResult result) { |
| 7326 | StateTracker::PostCallRecordQueueSubmit2KHR(queue, submitCount, pSubmits, fence, result); |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7327 | if (VK_SUCCESS != result) return; // dispatched QueueSubmit2 failed |
| 7328 | |
| 7329 | if (!enabled[sync_validation_queue_submit]) return; |
| 7330 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7331 | // WIP: Add Submit2 support |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7332 | } |
| 7333 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7334 | AttachmentViewGen::AttachmentViewGen(const IMAGE_VIEW_STATE *view, const VkOffset3D &offset, const VkExtent3D &extent) |
| 7335 | : view_(view), view_mask_(), gen_store_() { |
| 7336 | if (!view_ || !view_->image_state || !SimpleBinding(*view_->image_state)) return; |
| 7337 | const IMAGE_STATE &image_state = *view_->image_state.get(); |
| 7338 | const auto base_address = ResourceBaseAddress(image_state); |
| 7339 | const auto *encoder = image_state.fragment_encoder.get(); |
| 7340 | if (!encoder) return; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 7341 | // Get offset and extent for the view, accounting for possible depth slicing |
| 7342 | const VkOffset3D zero_offset = view->GetOffset(); |
| 7343 | const VkExtent3D &image_extent = view->GetExtent(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7344 | // Intentional copy |
| 7345 | VkImageSubresourceRange subres_range = view_->normalized_subresource_range; |
| 7346 | view_mask_ = subres_range.aspectMask; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 7347 | gen_store_[Gen::kViewSubresource].emplace(*encoder, subres_range, zero_offset, image_extent, base_address, |
| 7348 | view->IsDepthSliced()); |
| 7349 | gen_store_[Gen::kRenderArea].emplace(*encoder, subres_range, offset, extent, base_address, view->IsDepthSliced()); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7350 | |
| 7351 | const auto depth = view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT; |
| 7352 | if (depth && (depth != view_mask_)) { |
| 7353 | subres_range.aspectMask = depth; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 7354 | gen_store_[Gen::kDepthOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address, view->IsDepthSliced()); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7355 | } |
| 7356 | const auto stencil = view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT; |
| 7357 | if (stencil && (stencil != view_mask_)) { |
| 7358 | subres_range.aspectMask = stencil; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 7359 | gen_store_[Gen::kStencilOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address, |
| 7360 | view->IsDepthSliced()); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7361 | } |
| 7362 | } |
| 7363 | |
| 7364 | const ImageRangeGen *AttachmentViewGen::GetRangeGen(AttachmentViewGen::Gen gen_type) const { |
| 7365 | const ImageRangeGen *got = nullptr; |
| 7366 | switch (gen_type) { |
| 7367 | case kViewSubresource: |
| 7368 | got = &gen_store_[kViewSubresource]; |
| 7369 | break; |
| 7370 | case kRenderArea: |
| 7371 | got = &gen_store_[kRenderArea]; |
| 7372 | break; |
| 7373 | case kDepthOnlyRenderArea: |
| 7374 | got = |
| 7375 | (view_mask_ == VK_IMAGE_ASPECT_DEPTH_BIT) ? &gen_store_[Gen::kRenderArea] : &gen_store_[Gen::kDepthOnlyRenderArea]; |
| 7376 | break; |
| 7377 | case kStencilOnlyRenderArea: |
| 7378 | got = (view_mask_ == VK_IMAGE_ASPECT_STENCIL_BIT) ? &gen_store_[Gen::kRenderArea] |
| 7379 | : &gen_store_[Gen::kStencilOnlyRenderArea]; |
| 7380 | break; |
| 7381 | default: |
| 7382 | assert(got); |
| 7383 | } |
| 7384 | return got; |
| 7385 | } |
| 7386 | |
| 7387 | AttachmentViewGen::Gen AttachmentViewGen::GetDepthStencilRenderAreaGenType(bool depth_op, bool stencil_op) const { |
| 7388 | assert(IsValid()); |
| 7389 | assert(view_mask_ & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); |
| 7390 | if (depth_op) { |
| 7391 | assert(view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 7392 | if (stencil_op) { |
| 7393 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 7394 | return kRenderArea; |
| 7395 | } |
| 7396 | return kDepthOnlyRenderArea; |
| 7397 | } |
| 7398 | if (stencil_op) { |
| 7399 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 7400 | return kStencilOnlyRenderArea; |
| 7401 | } |
| 7402 | |
| 7403 | assert(depth_op || stencil_op); |
| 7404 | return kRenderArea; |
| 7405 | } |
| 7406 | |
| 7407 | AccessAddressType AttachmentViewGen::GetAddressType() const { return AccessContext::ImageAddressType(*view_->image_state); } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7408 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7409 | void SyncEventsContext::ApplyBarrier(const SyncExecScope &src, const SyncExecScope &dst, ResourceUsageTag tag) { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7410 | const bool all_commands_bit = 0 != (src.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 7411 | for (auto &event_pair : map_) { |
| 7412 | assert(event_pair.second); // Shouldn't be storing empty |
| 7413 | auto &sync_event = *event_pair.second; |
| 7414 | // Events don't happen at a stage, so we need to check and store the unexpanded ALL_COMMANDS if set for inter-event-calls |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7415 | // But only if occuring before the tag |
| 7416 | if (((sync_event.barriers & src.exec_scope) || all_commands_bit) && (sync_event.last_command_tag <= tag)) { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7417 | sync_event.barriers |= dst.exec_scope; |
| 7418 | sync_event.barriers |= dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 7419 | } |
| 7420 | } |
| 7421 | } |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 7422 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7423 | void SyncEventsContext::ApplyTaggedWait(VkQueueFlags queue_flags, ResourceUsageTag tag) { |
| 7424 | const SyncExecScope src_scope = |
| 7425 | SyncExecScope::MakeSrc(queue_flags, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_2_HOST_BIT); |
| 7426 | const SyncExecScope dst_scope = SyncExecScope::MakeDst(queue_flags, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT); |
| 7427 | ApplyBarrier(src_scope, dst_scope, tag); |
| 7428 | } |
| 7429 | |
| 7430 | SyncEventsContext &SyncEventsContext::DeepCopy(const SyncEventsContext &from) { |
| 7431 | // We need a deep copy of the const context to update during validation phase |
| 7432 | for (const auto &event : from.map_) { |
| 7433 | map_.emplace(event.first, std::make_shared<SyncEventState>(*event.second)); |
| 7434 | } |
| 7435 | return *this; |
| 7436 | } |
| 7437 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7438 | QueueBatchContext::QueueBatchContext(const SyncValidator &sync_state, const QueueSyncState &queue_state) |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 7439 | : CommandExecutionContext(&sync_state), |
| 7440 | queue_state_(&queue_state), |
| 7441 | tag_range_(0, 0), |
| 7442 | current_access_context_(&access_context_), |
| 7443 | batch_log_(nullptr) {} |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7444 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7445 | template <typename BatchInfo> |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7446 | void QueueBatchContext::Setup(const std::shared_ptr<const QueueBatchContext> &prev_batch, const BatchInfo &batch_info, |
| 7447 | SignaledSemaphores &signaled) { |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7448 | SetupCommandBufferInfo(batch_info); |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7449 | SetupAccessContext(prev_batch, batch_info, signaled); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7450 | } |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7451 | void QueueBatchContext::ResolveSubmittedCommandBuffer(const AccessContext &recorded_context, ResourceUsageTag offset) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7452 | GetCurrentAccessContext()->ResolveFromContext(QueueTagOffsetBarrierAction(GetQueueId(), offset), recorded_context); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7453 | } |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7454 | |
| 7455 | VulkanTypedHandle QueueBatchContext::Handle() const { return queue_state_->Handle(); } |
| 7456 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7457 | void QueueBatchContext::ApplyTaggedWait(QueueId queue_id, ResourceUsageTag tag) { |
| 7458 | QueueWaitWorm wait_worm(queue_id); |
| 7459 | access_context_.ForAll(wait_worm); |
| 7460 | if (wait_worm.erase_all) { |
| 7461 | access_context_.Reset(); |
| 7462 | } else { |
| 7463 | // TODO: Profiling will tell us if we need a more efficient clean up. |
| 7464 | for (const auto &address : wait_worm.erase_list) { |
| 7465 | access_context_.DeleteAccess(address); |
| 7466 | } |
| 7467 | } |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7468 | |
| 7469 | if (queue_id == GetQueueId()) { |
| 7470 | events_context_.ApplyTaggedWait(GetQueueFlags(), tag); |
| 7471 | } |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7472 | } |
| 7473 | |
| 7474 | // Clear all accesses |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7475 | void QueueBatchContext::ApplyDeviceWait() { |
| 7476 | access_context_.Reset(); |
| 7477 | events_context_.ApplyTaggedWait(GetQueueFlags(), ResourceUsageRecord::kMaxIndex); |
| 7478 | } |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7479 | |
John Zulauf | dab327f | 2022-07-08 12:02:05 -0600 | [diff] [blame^] | 7480 | HazardResult QueueBatchContext::DetectFirstUseHazard(const ResourceUsageRange &tag_range) { |
| 7481 | // Queue batch handling requires dealing with renderpass state and picking the correct access context |
| 7482 | if (rp_replay_) { |
| 7483 | return rp_replay_.replay_context->DetectFirstUseHazard(GetQueueId(), tag_range, *current_access_context_); |
| 7484 | } |
| 7485 | return current_replay_->GetCurrentAccessContext()->DetectFirstUseHazard(GetQueueId(), tag_range, access_context_); |
| 7486 | } |
| 7487 | |
| 7488 | void QueueBatchContext::BeginRenderPassReplay(const SyncOpBeginRenderPass &begin_op, const ResourceUsageTag tag) { |
| 7489 | current_access_context_ = rp_replay_.Begin(GetQueueFlags(), begin_op, access_context_); |
| 7490 | current_access_context_->ResolvePreviousAccesses(); |
| 7491 | } |
| 7492 | |
| 7493 | void QueueBatchContext::NextSubpassReplay() { |
| 7494 | current_access_context_ = rp_replay_.Next(); |
| 7495 | current_access_context_->ResolvePreviousAccesses(); |
| 7496 | } |
| 7497 | |
| 7498 | void QueueBatchContext::EndRenderPassReplay() { |
| 7499 | rp_replay_.End(access_context_); |
| 7500 | current_access_context_ = &access_context_; |
| 7501 | } |
| 7502 | |
| 7503 | AccessContext *QueueBatchContext::RenderPassReplayState::Begin(VkQueueFlags queue_flags, const SyncOpBeginRenderPass &begin_op_, |
| 7504 | const AccessContext &external_context) { |
| 7505 | Reset(); |
| 7506 | |
| 7507 | begin_op = &begin_op_; |
| 7508 | subpass = 0; |
| 7509 | |
| 7510 | const RenderPassAccessContext *rp_context = begin_op->GetRenderPassAccessContext(); |
| 7511 | assert(rp_context); |
| 7512 | replay_context = &rp_context->GetContexts()[0]; |
| 7513 | |
| 7514 | InitSubpassContexts(queue_flags, *rp_context->GetRenderPassState(), &external_context, subpass_contexts); |
| 7515 | return &subpass_contexts[0]; |
| 7516 | } |
| 7517 | |
| 7518 | AccessContext *QueueBatchContext::RenderPassReplayState::Next() { |
| 7519 | subpass++; |
| 7520 | |
| 7521 | const RenderPassAccessContext *rp_context = begin_op->GetRenderPassAccessContext(); |
| 7522 | |
| 7523 | replay_context = &rp_context->GetContexts()[subpass]; |
| 7524 | return &subpass_contexts[subpass]; |
| 7525 | } |
| 7526 | |
| 7527 | void QueueBatchContext::RenderPassReplayState::End(AccessContext &external_context) { |
| 7528 | external_context.ResolveChildContexts(subpass_contexts); |
| 7529 | Reset(); |
| 7530 | } |
| 7531 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7532 | class ApplySemaphoreBarrierAction { |
| 7533 | public: |
| 7534 | ApplySemaphoreBarrierAction(const SemaphoreScope &signal, const SemaphoreScope &wait) : signal_(signal), wait_(wait) {} |
| 7535 | void operator()(ResourceAccessState *access) const { access->ApplySemaphore(signal_, wait_); } |
| 7536 | |
| 7537 | private: |
| 7538 | const SemaphoreScope &signal_; |
| 7539 | const SemaphoreScope wait_; |
| 7540 | }; |
| 7541 | |
| 7542 | std::shared_ptr<QueueBatchContext> QueueBatchContext::ResolveOneWaitSemaphore(VkSemaphore sem, VkPipelineStageFlags2 wait_mask, |
| 7543 | SignaledSemaphores &signaled) { |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7544 | auto sem_state = sync_state_->Get<SEMAPHORE_STATE>(sem); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7545 | if (!sem_state) return nullptr; // Semaphore validity is handled by CoreChecks |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7546 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7547 | // When signal state goes out of scope, the signal information will be dropped, as Unsignal has released ownership. |
| 7548 | auto signal_state = signaled.Unsignal(sem); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7549 | if (!signal_state) return nullptr; // Invalid signal, skip it. |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7550 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7551 | assert(signal_state->batch); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7552 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7553 | const SemaphoreScope &signal_scope = signal_state->first_scope; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7554 | const auto queue_flags = queue_state_->GetQueueFlags(); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7555 | SemaphoreScope wait_scope{GetQueueId(), SyncExecScope::MakeDst(queue_flags, wait_mask)}; |
| 7556 | if (signal_scope.queue == wait_scope.queue) { |
| 7557 | // If signal queue == wait queue, signal is treated as a memory barrier with an access scope equal to the |
| 7558 | // valid accesses for the sync scope. |
| 7559 | SyncBarrier sem_barrier(signal_scope, wait_scope, SyncBarrier::AllAccess()); |
| 7560 | const BatchBarrierOp sem_barrier_op(wait_scope.queue, sem_barrier); |
| 7561 | access_context_.ResolveFromContext(sem_barrier_op, signal_state->batch->access_context_); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7562 | events_context_.ApplyBarrier(sem_barrier.src_exec_scope, sem_barrier.dst_exec_scope, ResourceUsageRecord::kMaxIndex); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7563 | } else { |
| 7564 | ApplySemaphoreBarrierAction sem_op(signal_scope, wait_scope); |
| 7565 | access_context_.ResolveFromContext(sem_op, signal_state->batch->access_context_); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7566 | } |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7567 | // Cannot move from the signal state because it could be from the const global state, and C++ doesn't |
| 7568 | // enforce deep constness. |
| 7569 | return signal_state->batch; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7570 | } |
| 7571 | |
| 7572 | // Accessor Traits to allow Submit and Submit2 constructors to call the same utilities |
| 7573 | template <> |
| 7574 | class QueueBatchContext::SubmitInfoAccessor<VkSubmitInfo> { |
| 7575 | public: |
| 7576 | SubmitInfoAccessor(const VkSubmitInfo &info) : info_(info) {} |
| 7577 | inline uint32_t WaitSemaphoreCount() const { return info_.waitSemaphoreCount; } |
| 7578 | inline VkSemaphore WaitSemaphore(uint32_t index) { return info_.pWaitSemaphores[index]; } |
| 7579 | inline VkPipelineStageFlags2 WaitDstMask(uint32_t index) { return info_.pWaitDstStageMask[index]; } |
| 7580 | inline uint32_t CommandBufferCount() const { return info_.commandBufferCount; } |
| 7581 | inline VkCommandBuffer CommandBuffer(uint32_t index) { return info_.pCommandBuffers[index]; } |
| 7582 | |
| 7583 | private: |
| 7584 | const VkSubmitInfo &info_; |
| 7585 | }; |
| 7586 | template <typename BatchInfo, typename Fn> |
| 7587 | void QueueBatchContext::ForEachWaitSemaphore(const BatchInfo &batch_info, Fn &&func) { |
| 7588 | using Accessor = QueueBatchContext::SubmitInfoAccessor<BatchInfo>; |
| 7589 | Accessor batch(batch_info); |
| 7590 | const uint32_t wait_count = batch.WaitSemaphoreCount(); |
| 7591 | for (uint32_t i = 0; i < wait_count; ++i) { |
| 7592 | func(batch.WaitSemaphore(i), batch.WaitDstMask(i)); |
| 7593 | } |
| 7594 | } |
| 7595 | |
| 7596 | template <typename BatchInfo> |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7597 | void QueueBatchContext::SetupAccessContext(const std::shared_ptr<const QueueBatchContext> &prev, const BatchInfo &batch_info, |
| 7598 | SignaledSemaphores &signaled) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7599 | // Copy in the event state from the previous batch (on this queue) |
| 7600 | if (prev) { |
| 7601 | events_context_.DeepCopy(prev->events_context_); |
| 7602 | } |
| 7603 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7604 | // Import (resolve) the batches that are waited on, with the semaphore's effective barriers applied |
| 7605 | layer_data::unordered_set<std::shared_ptr<const QueueBatchContext>> batches_resolved; |
| 7606 | ForEachWaitSemaphore(batch_info, [this, &signaled, &batches_resolved](VkSemaphore sem, VkPipelineStageFlags2 wait_mask) { |
| 7607 | std::shared_ptr<QueueBatchContext> resolved = ResolveOneWaitSemaphore(sem, wait_mask, signaled); |
| 7608 | if (resolved) { |
| 7609 | batches_resolved.emplace(std::move(resolved)); |
| 7610 | } |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7611 | }); |
| 7612 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7613 | // If there are no semaphores to the previous batch, make sure a "submit order" non-barriered import is done |
| 7614 | if (prev && !layer_data::Contains(batches_resolved, prev)) { |
| 7615 | access_context_.ResolveFromContext(NoopBarrierAction(), prev->access_context_); |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7616 | } |
| 7617 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7618 | // Gather async context information for hazard checks and conserve the QBC's for the async batches |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7619 | async_batches_ = |
| 7620 | sync_state_->GetQueueLastBatchSnapshot([&batches_resolved, &prev](const std::shared_ptr<const QueueBatchContext> &batch) { |
| 7621 | return (batch != prev) && !layer_data::Contains(batches_resolved, batch); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7622 | }); |
| 7623 | for (const auto &async_batch : async_batches_) { |
| 7624 | access_context_.AddAsyncContext(async_batch->GetCurrentAccessContext()); |
| 7625 | } |
| 7626 | } |
| 7627 | |
| 7628 | template <typename BatchInfo> |
| 7629 | void QueueBatchContext::SetupCommandBufferInfo(const BatchInfo &batch_info) { |
| 7630 | using Accessor = QueueBatchContext::SubmitInfoAccessor<BatchInfo>; |
| 7631 | Accessor batch(batch_info); |
| 7632 | |
| 7633 | // Create the list of command buffers to submit |
| 7634 | const uint32_t cb_count = batch.CommandBufferCount(); |
| 7635 | command_buffers_.reserve(cb_count); |
| 7636 | for (uint32_t index = 0; index < cb_count; ++index) { |
| 7637 | auto cb_context = sync_state_->GetAccessContextShared(batch.CommandBuffer(index)); |
| 7638 | if (cb_context) { |
| 7639 | tag_range_.end += cb_context->GetTagLimit(); |
| 7640 | command_buffers_.emplace_back(index, std::move(cb_context)); |
| 7641 | } |
| 7642 | } |
| 7643 | } |
| 7644 | |
| 7645 | // Look up the usage informaiton from the local or global logger |
| 7646 | std::string QueueBatchContext::FormatUsage(ResourceUsageTag tag) const { |
| 7647 | const AccessLogger &use_logger = (logger_) ? *logger_ : sync_state_->global_access_log_; |
| 7648 | std::stringstream out; |
| 7649 | AccessLogger::AccessRecord access = use_logger[tag]; |
| 7650 | if (access.IsValid()) { |
| 7651 | const AccessLogger::BatchRecord &batch = *access.batch; |
| 7652 | const ResourceUsageRecord &record = *access.record; |
| 7653 | // Queue and Batch information |
| 7654 | out << SyncNodeFormatter(*sync_state_, batch.queue->GetQueueState()); |
| 7655 | out << ", submit: " << batch.submit_index << ", batch: " << batch.batch_index; |
| 7656 | |
| 7657 | // Commandbuffer Usages Information |
| 7658 | out << record; |
| 7659 | out << SyncNodeFormatter(*sync_state_, record.cb_state); |
| 7660 | out << ", reset_no: " << std::to_string(record.reset_count); |
| 7661 | } |
| 7662 | return out.str(); |
| 7663 | } |
| 7664 | |
| 7665 | VkQueueFlags QueueBatchContext::GetQueueFlags() const { return queue_state_->GetQueueFlags(); } |
| 7666 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7667 | QueueId QueueBatchContext::GetQueueId() const { |
| 7668 | QueueId id = queue_state_ ? queue_state_->GetQueueId() : QueueSyncState::kQueueIdInvalid; |
| 7669 | return id; |
| 7670 | } |
| 7671 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7672 | void QueueBatchContext::SetBatchLog(AccessLogger &logger, uint64_t submit_id, uint32_t batch_id) { |
| 7673 | // Need new global tags for all accesses... the Reserve updates a mutable atomic |
| 7674 | ResourceUsageRange global_tags = sync_state_->ReserveGlobalTagRange(GetTagRange().size()); |
| 7675 | SetTagBias(global_tags.begin); |
| 7676 | // Add an access log for the batches range and point the batch at it. |
| 7677 | logger_ = &logger; |
| 7678 | batch_log_ = logger.AddBatch(queue_state_, submit_id, batch_id, global_tags); |
| 7679 | } |
| 7680 | |
| 7681 | void QueueBatchContext::InsertRecordedAccessLogEntries(const CommandBufferAccessContext &submitted_cb) { |
| 7682 | assert(batch_log_); // Don't import command buffer contexts until you've set up the log for the batch context |
| 7683 | batch_log_->Append(submitted_cb.GetAccessLog()); |
| 7684 | } |
| 7685 | |
| 7686 | void QueueBatchContext::SetTagBias(ResourceUsageTag bias) { |
| 7687 | const auto size = tag_range_.size(); |
| 7688 | tag_range_.begin = bias; |
| 7689 | tag_range_.end = bias + size; |
| 7690 | access_context_.SetStartTag(bias); |
| 7691 | } |
| 7692 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7693 | QueueBatchContext::QueueWaitWorm::QueueWaitWorm(QueueId queue, ResourceUsageTag tag) : predicate(queue) {} |
| 7694 | |
| 7695 | void QueueBatchContext::QueueWaitWorm::operator()(AccessAddressType address_type, ResourceAccessRangeMap::value_type &access) { |
| 7696 | bool erased = access.second.ApplyQueueTagWait(predicate); |
| 7697 | if (erased) { |
| 7698 | erase_list.emplace_back(address_type, access.first); |
| 7699 | } else { |
| 7700 | erase_all = false; |
| 7701 | } |
| 7702 | } |
| 7703 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7704 | AccessLogger::BatchLog *AccessLogger::AddBatch(const QueueSyncState *queue_state, uint64_t submit_id, uint32_t batch_id, |
| 7705 | const ResourceUsageRange &range) { |
| 7706 | const auto inserted = access_log_map_.insert(std::make_pair(range, BatchLog(BatchRecord(queue_state, submit_id, batch_id)))); |
| 7707 | assert(inserted.second); |
| 7708 | return &inserted.first->second; |
| 7709 | } |
| 7710 | |
| 7711 | void AccessLogger::MergeMove(AccessLogger &&child) { |
| 7712 | for (auto &range : child.access_log_map_) { |
| 7713 | BatchLog &child_batch = range.second; |
| 7714 | auto insert_pair = access_log_map_.insert(std::make_pair(range.first, BatchLog())); |
| 7715 | insert_pair.first->second = std::move(child_batch); |
| 7716 | assert(insert_pair.second); |
| 7717 | } |
| 7718 | child.Reset(); |
| 7719 | } |
| 7720 | |
| 7721 | void AccessLogger::Reset() { |
| 7722 | prev_ = nullptr; |
| 7723 | access_log_map_.clear(); |
| 7724 | } |
| 7725 | |
| 7726 | // Since we're updating the QueueSync state, this is Record phase and the access log needs to point to the global one |
| 7727 | // Batch Contexts saved during signalling have their AccessLog reset when the pending signals are signalled. |
| 7728 | // NOTE: By design, QueueBatchContexts that are neither last, nor referenced by a signal are abandoned as unowned, since |
| 7729 | // the contexts Resolve all history from previous all contexts when created |
| 7730 | void QueueSyncState::SetLastBatch(std::shared_ptr<QueueBatchContext> &&last) { |
| 7731 | last_batch_ = std::move(last); |
| 7732 | last_batch_->ResetAccessLog(); |
| 7733 | } |
| 7734 | |
| 7735 | // Note that function is const, but updates mutable submit_index to allow Validate to create correct tagging for command invocation |
| 7736 | // scope state. |
| 7737 | // Given that queue submits are supposed to be externally synchronized for the same queue, this should safe without being |
| 7738 | // atomic... but as the ops are per submit, the performance cost is negible for the peace of mind. |
| 7739 | uint64_t QueueSyncState::ReserveSubmitId() const { return submit_index_.fetch_add(1); } |
| 7740 | |
| 7741 | void AccessLogger::BatchLog::Append(const CommandExecutionContext::AccessLog &other) { |
| 7742 | log_.insert(log_.end(), other.cbegin(), other.cend()); |
| 7743 | for (const auto &record : other) { |
| 7744 | assert(record.cb_state); |
| 7745 | cbs_referenced_.insert(record.cb_state->shared_from_this()); |
| 7746 | } |
| 7747 | } |
| 7748 | |
| 7749 | AccessLogger::AccessRecord AccessLogger::BatchLog::operator[](size_t index) const { |
| 7750 | assert(index < log_.size()); |
| 7751 | return AccessRecord{&batch_, &log_[index]}; |
| 7752 | } |
| 7753 | |
| 7754 | AccessLogger::AccessRecord AccessLogger::operator[](ResourceUsageTag tag) const { |
| 7755 | AccessRecord access_record = {nullptr, nullptr}; |
| 7756 | |
| 7757 | auto found_range = access_log_map_.find(tag); |
| 7758 | if (found_range != access_log_map_.cend()) { |
| 7759 | const ResourceUsageTag bias = found_range->first.begin; |
| 7760 | assert(tag >= bias); |
| 7761 | access_record = found_range->second[tag - bias]; |
| 7762 | } else if (prev_) { |
| 7763 | access_record = (*prev_)[tag]; |
| 7764 | } |
| 7765 | |
| 7766 | return access_record; |
| 7767 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7768 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7769 | // This is a const method, force the returned value to be const |
| 7770 | std::shared_ptr<const SignaledSemaphores::Signal> SignaledSemaphores::GetPrev(VkSemaphore sem) const { |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7771 | std::shared_ptr<Signal> prev_state; |
| 7772 | if (prev_) { |
| 7773 | prev_state = GetMapped(prev_->signaled_, sem, [&prev_state]() { return prev_state; }); |
| 7774 | } |
| 7775 | return prev_state; |
| 7776 | } |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7777 | |
| 7778 | SignaledSemaphores::Signal::Signal(const std::shared_ptr<const SEMAPHORE_STATE> &sem_state_, |
| 7779 | const std::shared_ptr<QueueBatchContext> &batch_, const SyncExecScope &exec_scope_) |
| 7780 | : sem_state(sem_state_), batch(batch_), first_scope({batch->GetQueueId(), exec_scope_}) { |
| 7781 | // Illegal to create a signal from no batch or an invalid semaphore... caller must assure validity |
| 7782 | assert(batch); |
| 7783 | assert(sem_state); |
| 7784 | } |