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 | |
| 272 | // NOTE: Make sure the proxy doesn't outlive from, as the proxy is pointing directly to access contexts owned by from. |
| 273 | CommandBufferAccessContext::CommandBufferAccessContext(const CommandBufferAccessContext &from, AsProxyContext dummy) |
| 274 | : CommandBufferAccessContext(from.sync_state_) { |
| 275 | // Copy only the needed fields out of from for a temporary, proxy command buffer context |
| 276 | cb_state_ = from.cb_state_; |
| 277 | queue_flags_ = from.queue_flags_; |
| 278 | destroyed_ = from.destroyed_; |
| 279 | access_log_ = from.access_log_; // potentially large, but no choice given tagging lookup. |
| 280 | command_number_ = from.command_number_; |
| 281 | subcommand_number_ = from.subcommand_number_; |
| 282 | reset_count_ = from.reset_count_; |
| 283 | |
| 284 | const auto *from_context = from.GetCurrentAccessContext(); |
| 285 | assert(from_context); |
| 286 | |
| 287 | // Construct a fully resolved single access context out of from |
| 288 | const NoopBarrierAction noop_barrier; |
| 289 | for (AccessAddressType address_type : kAddressTypes) { |
| 290 | from_context->ResolveAccessRange(address_type, kFullRange, noop_barrier, |
| 291 | &cb_access_context_.GetAccessStateMap(address_type), nullptr); |
| 292 | } |
| 293 | // The proxy has flatten the current render pass context (if any), but the async contexts are needed for hazard detection |
| 294 | cb_access_context_.ImportAsyncContexts(*from_context); |
| 295 | |
| 296 | events_context_ = from.events_context_; |
| 297 | |
| 298 | // We don't want to copy the full render_pass_context_ history just for the proxy. |
| 299 | } |
| 300 | |
| 301 | std::string CommandBufferAccessContext::FormatUsage(const ResourceUsageTag tag) const { |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 302 | if (tag >= access_log_.size()) return std::string(); |
| 303 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 304 | std::stringstream out; |
| 305 | assert(tag < access_log_.size()); |
| 306 | const auto &record = access_log_[tag]; |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 307 | out << record; |
| 308 | if (cb_state_.get() != record.cb_state) { |
| 309 | out << SyncNodeFormatter(*sync_state_, record.cb_state); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 310 | } |
John Zulauf | d142c9a | 2022-04-12 14:22:44 -0600 | [diff] [blame] | 311 | out << ", reset_no: " << std::to_string(record.reset_count); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 312 | return out.str(); |
| 313 | } |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 314 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 315 | std::string CommandBufferAccessContext::FormatUsage(const ResourceFirstAccess &access) const { |
| 316 | std::stringstream out; |
| 317 | out << "(recorded_usage: " << string_UsageIndex(access.usage_index); |
| 318 | out << ", " << FormatUsage(access.tag) << ")"; |
| 319 | return out.str(); |
| 320 | } |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 321 | |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 322 | std::string CommandExecutionContext::FormatHazard(const HazardResult &hazard) const { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 323 | std::stringstream out; |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 324 | out << hazard; |
| 325 | out << ", " << FormatUsage(hazard.tag) << ")"; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 326 | return out.str(); |
| 327 | } |
| 328 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 329 | // NOTE: the attachement read flag is put *only* in the access scope and not in the exect scope, since the ordering |
| 330 | // rules apply only to this specific access for this stage, and not the stage as a whole. The ordering detection |
| 331 | // 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] | 332 | 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] | 333 | static const SyncStageAccessFlags kColorAttachmentAccessScope = |
| 334 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_BIT | |
| 335 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT | |
| 336 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE_BIT | |
| 337 | 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] | 338 | static constexpr VkPipelineStageFlags2KHR kDepthStencilAttachmentExecScope = |
| 339 | 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] | 340 | static const SyncStageAccessFlags kDepthStencilAttachmentAccessScope = |
| 341 | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 342 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 343 | 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] | 344 | static constexpr VkPipelineStageFlags2KHR kRasterAttachmentExecScope = kDepthStencilAttachmentExecScope | kColorAttachmentExecScope; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 345 | static const SyncStageAccessFlags kRasterAttachmentAccessScope = kDepthStencilAttachmentAccessScope | kColorAttachmentAccessScope; |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 346 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 347 | ResourceAccessState::OrderingBarriers ResourceAccessState::kOrderingRules = { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 348 | {{VK_PIPELINE_STAGE_2_NONE_KHR, SyncStageAccessFlags()}, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 349 | {kColorAttachmentExecScope, kColorAttachmentAccessScope}, |
| 350 | {kDepthStencilAttachmentExecScope, kDepthStencilAttachmentAccessScope}, |
| 351 | {kRasterAttachmentExecScope, kRasterAttachmentAccessScope}}}; |
| 352 | |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 353 | // Sometimes we have an internal access conflict, and we using the kInvalidTag to set and detect in temporary/proxy contexts |
| 354 | static const ResourceUsageTag kInvalidTag(ResourceUsageRecord::kMaxIndex); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 355 | |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 356 | static VkDeviceSize ResourceBaseAddress(const BINDABLE &bindable) { return bindable.GetFakeBaseAddress(); } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 357 | |
locke-lunarg | 3c03800 | 2020-04-30 23:08:08 -0600 | [diff] [blame] | 358 | inline VkDeviceSize GetRealWholeSize(VkDeviceSize offset, VkDeviceSize size, VkDeviceSize whole_size) { |
| 359 | if (size == VK_WHOLE_SIZE) { |
| 360 | return (whole_size - offset); |
| 361 | } |
| 362 | return size; |
| 363 | } |
| 364 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 365 | static inline VkDeviceSize GetBufferWholeSize(const BUFFER_STATE &buf_state, VkDeviceSize offset, VkDeviceSize size) { |
| 366 | return GetRealWholeSize(offset, size, buf_state.createInfo.size); |
| 367 | } |
| 368 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 369 | template <typename T> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 370 | static ResourceAccessRange MakeRange(const T &has_offset_and_size) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 371 | return ResourceAccessRange(has_offset_and_size.offset, (has_offset_and_size.offset + has_offset_and_size.size)); |
| 372 | } |
| 373 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 374 | static ResourceAccessRange MakeRange(VkDeviceSize start, VkDeviceSize size) { return ResourceAccessRange(start, (start + size)); } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 375 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 376 | static inline ResourceAccessRange MakeRange(const BUFFER_STATE &buffer, VkDeviceSize offset, VkDeviceSize size) { |
| 377 | return MakeRange(offset, GetBufferWholeSize(buffer, offset, size)); |
| 378 | } |
| 379 | |
| 380 | static inline ResourceAccessRange MakeRange(const BUFFER_VIEW_STATE &buf_view_state) { |
| 381 | return MakeRange(*buf_view_state.buffer_state.get(), buf_view_state.create_info.offset, buf_view_state.create_info.range); |
| 382 | } |
| 383 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 384 | // Range generators for to allow event scope filtration to be limited to the top of the resource access traversal pipeline |
| 385 | // |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 386 | // Note: there is no "begin/end" or reset facility. These are each written as "one time through" generators. |
| 387 | // |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 388 | // Usage: |
| 389 | // Constructor() -- initializes the generator to point to the begin of the space declared. |
| 390 | // * -- the current range of the generator empty signfies end |
| 391 | // ++ -- advance to the next non-empty range (or end) |
| 392 | |
| 393 | // A wrapper for a single range with the same semantics as the actual generators below |
| 394 | template <typename KeyType> |
| 395 | class SingleRangeGenerator { |
| 396 | public: |
| 397 | SingleRangeGenerator(const KeyType &range) : current_(range) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 398 | const KeyType &operator*() const { return current_; } |
| 399 | const KeyType *operator->() const { return ¤t_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 400 | SingleRangeGenerator &operator++() { |
| 401 | current_ = KeyType(); // just one real range |
| 402 | return *this; |
| 403 | } |
| 404 | |
| 405 | bool operator==(const SingleRangeGenerator &other) const { return current_ == other.current_; } |
| 406 | |
| 407 | private: |
| 408 | SingleRangeGenerator() = default; |
| 409 | const KeyType range_; |
| 410 | KeyType current_; |
| 411 | }; |
| 412 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 413 | // Generate the ranges that are the intersection of range and the entries in the RangeMap |
| 414 | template <typename RangeMap, typename KeyType = typename RangeMap::key_type> |
| 415 | class MapRangesRangeGenerator { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 416 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 417 | // 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] | 418 | MapRangesRangeGenerator() : range_(), map_(nullptr), map_pos_(), current_() { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 419 | // Default construction for KeyType *must* be empty range |
| 420 | assert(current_.empty()); |
| 421 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 422 | 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] | 423 | SeekBegin(); |
| 424 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 425 | MapRangesRangeGenerator(const MapRangesRangeGenerator &from) = default; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 426 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 427 | const KeyType &operator*() const { return current_; } |
| 428 | const KeyType *operator->() const { return ¤t_; } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 429 | MapRangesRangeGenerator &operator++() { |
| 430 | ++map_pos_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 431 | UpdateCurrent(); |
| 432 | return *this; |
| 433 | } |
| 434 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 435 | bool operator==(const MapRangesRangeGenerator &other) const { return current_ == other.current_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 436 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 437 | protected: |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 438 | void UpdateCurrent() { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 439 | if (map_pos_ != map_->cend()) { |
| 440 | current_ = range_ & map_pos_->first; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 441 | } else { |
| 442 | current_ = KeyType(); |
| 443 | } |
| 444 | } |
| 445 | void SeekBegin() { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 446 | map_pos_ = map_->lower_bound(range_); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 447 | UpdateCurrent(); |
| 448 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 449 | |
| 450 | // Adding this functionality here, to avoid gratuitous Base:: qualifiers in the derived class |
| 451 | // Note: Not exposed in this classes public interface to encourage using a consistent ++/empty generator semantic |
| 452 | template <typename Pred> |
| 453 | MapRangesRangeGenerator &PredicatedIncrement(Pred &pred) { |
| 454 | do { |
| 455 | ++map_pos_; |
| 456 | } while (map_pos_ != map_->cend() && map_pos_->first.intersects(range_) && !pred(map_pos_)); |
| 457 | UpdateCurrent(); |
| 458 | return *this; |
| 459 | } |
| 460 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 461 | const KeyType range_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 462 | const RangeMap *map_; |
| 463 | typename RangeMap::const_iterator map_pos_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 464 | KeyType current_; |
| 465 | }; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 466 | using SingleAccessRangeGenerator = SingleRangeGenerator<ResourceAccessRange>; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 467 | using EventSimpleRangeGenerator = MapRangesRangeGenerator<SyncEventState::ScopeMap>; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 468 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 469 | // Generate the ranges for entries meeting the predicate that are the intersection of range and the entries in the RangeMap |
| 470 | template <typename RangeMap, typename Predicate, typename KeyType = typename RangeMap::key_type> |
| 471 | class PredicatedMapRangesRangeGenerator : public MapRangesRangeGenerator<RangeMap, KeyType> { |
| 472 | public: |
| 473 | using Base = MapRangesRangeGenerator<RangeMap, KeyType>; |
| 474 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 475 | PredicatedMapRangesRangeGenerator() : Base(), pred_() {} |
| 476 | PredicatedMapRangesRangeGenerator(const RangeMap &filter, const KeyType &range, Predicate pred) |
| 477 | : Base(filter, range), pred_(pred) {} |
| 478 | PredicatedMapRangesRangeGenerator(const PredicatedMapRangesRangeGenerator &from) = default; |
| 479 | |
| 480 | PredicatedMapRangesRangeGenerator &operator++() { |
| 481 | Base::PredicatedIncrement(pred_); |
| 482 | return *this; |
| 483 | } |
| 484 | |
| 485 | protected: |
| 486 | Predicate pred_; |
| 487 | }; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 488 | |
| 489 | // 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] | 490 | // Templated to allow for different Range generators or map sources... |
| 491 | template <typename RangeMap, typename RangeGen, typename KeyType = typename RangeMap::key_type> |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 492 | class FilteredGeneratorGenerator { |
| 493 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 494 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 495 | FilteredGeneratorGenerator() : filter_(nullptr), gen_(), filter_pos_(), current_() { |
| 496 | // Default construction for KeyType *must* be empty range |
| 497 | assert(current_.empty()); |
| 498 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 499 | 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] | 500 | SeekBegin(); |
| 501 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 502 | FilteredGeneratorGenerator(const FilteredGeneratorGenerator &from) = default; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 503 | const KeyType &operator*() const { return current_; } |
| 504 | const KeyType *operator->() const { return ¤t_; } |
| 505 | FilteredGeneratorGenerator &operator++() { |
| 506 | KeyType gen_range = GenRange(); |
| 507 | KeyType filter_range = FilterRange(); |
| 508 | current_ = KeyType(); |
| 509 | while (gen_range.non_empty() && filter_range.non_empty() && current_.empty()) { |
| 510 | if (gen_range.end > filter_range.end) { |
| 511 | // if the generated range is beyond the filter_range, advance the filter range |
| 512 | filter_range = AdvanceFilter(); |
| 513 | } else { |
| 514 | gen_range = AdvanceGen(); |
| 515 | } |
| 516 | current_ = gen_range & filter_range; |
| 517 | } |
| 518 | return *this; |
| 519 | } |
| 520 | |
| 521 | bool operator==(const FilteredGeneratorGenerator &other) const { return current_ == other.current_; } |
| 522 | |
| 523 | private: |
| 524 | KeyType AdvanceFilter() { |
| 525 | ++filter_pos_; |
| 526 | auto filter_range = FilterRange(); |
| 527 | if (filter_range.valid()) { |
| 528 | FastForwardGen(filter_range); |
| 529 | } |
| 530 | return filter_range; |
| 531 | } |
| 532 | KeyType AdvanceGen() { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 533 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 534 | auto gen_range = GenRange(); |
| 535 | if (gen_range.valid()) { |
| 536 | FastForwardFilter(gen_range); |
| 537 | } |
| 538 | return gen_range; |
| 539 | } |
| 540 | |
| 541 | KeyType FilterRange() const { return (filter_pos_ != filter_->cend()) ? filter_pos_->first : KeyType(); } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 542 | KeyType GenRange() const { return *gen_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 543 | |
| 544 | KeyType FastForwardFilter(const KeyType &range) { |
| 545 | auto filter_range = FilterRange(); |
| 546 | int retry_count = 0; |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 547 | const static int kRetryLimit = 2; // TODO -- determine whether this limit is optimal |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 548 | while (!filter_range.empty() && (filter_range.end <= range.begin)) { |
| 549 | if (retry_count < kRetryLimit) { |
| 550 | ++filter_pos_; |
| 551 | filter_range = FilterRange(); |
| 552 | retry_count++; |
| 553 | } else { |
| 554 | // Okay we've tried walking, do a seek. |
| 555 | filter_pos_ = filter_->lower_bound(range); |
| 556 | break; |
| 557 | } |
| 558 | } |
| 559 | return FilterRange(); |
| 560 | } |
| 561 | |
| 562 | // TODO: Consider adding "seek" (or an absolute bound "get" to range generators to make this walk |
| 563 | // faster. |
| 564 | KeyType FastForwardGen(const KeyType &range) { |
| 565 | auto gen_range = GenRange(); |
| 566 | while (!gen_range.empty() && (gen_range.end <= range.begin)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 567 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 568 | gen_range = GenRange(); |
| 569 | } |
| 570 | return gen_range; |
| 571 | } |
| 572 | |
| 573 | void SeekBegin() { |
| 574 | auto gen_range = GenRange(); |
| 575 | if (gen_range.empty()) { |
| 576 | current_ = KeyType(); |
| 577 | filter_pos_ = filter_->cend(); |
| 578 | } else { |
| 579 | filter_pos_ = filter_->lower_bound(gen_range); |
| 580 | current_ = gen_range & FilterRange(); |
| 581 | } |
| 582 | } |
| 583 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 584 | const RangeMap *filter_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 585 | RangeGen gen_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 586 | typename RangeMap::const_iterator filter_pos_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 587 | KeyType current_; |
| 588 | }; |
| 589 | |
| 590 | using EventImageRangeGenerator = FilteredGeneratorGenerator<SyncEventState::ScopeMap, subresource_adapter::ImageRangeGenerator>; |
| 591 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 592 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 593 | ResourceAccessRange GetBufferRange(VkDeviceSize offset, VkDeviceSize buf_whole_size, uint32_t first_index, uint32_t count, |
| 594 | VkDeviceSize stride) { |
| 595 | VkDeviceSize range_start = offset + first_index * stride; |
| 596 | VkDeviceSize range_size = 0; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 597 | if (count == UINT32_MAX) { |
| 598 | range_size = buf_whole_size - range_start; |
| 599 | } else { |
| 600 | range_size = count * stride; |
| 601 | } |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 602 | return MakeRange(range_start, range_size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 603 | } |
| 604 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 605 | SyncStageAccessIndex GetSyncStageAccessIndexsByDescriptorSet(VkDescriptorType descriptor_type, const interface_var &descriptor_data, |
| 606 | VkShaderStageFlagBits stage_flag) { |
| 607 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 608 | assert(stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT); |
| 609 | return SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ; |
| 610 | } |
| 611 | auto stage_access = syncStageAccessMaskByShaderStage.find(stage_flag); |
| 612 | if (stage_access == syncStageAccessMaskByShaderStage.end()) { |
| 613 | assert(0); |
| 614 | } |
| 615 | if (descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) { |
| 616 | return stage_access->second.uniform_read; |
| 617 | } |
| 618 | |
| 619 | // If the desriptorSet is writable, we don't need to care SHADER_READ. SHADER_WRITE is enough. |
| 620 | // Because if write hazard happens, read hazard might or might not happen. |
| 621 | // But if write hazard doesn't happen, read hazard is impossible to happen. |
| 622 | if (descriptor_data.is_writable) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 623 | return stage_access->second.storage_write; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 624 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 625 | // TODO: sampled_read |
| 626 | return stage_access->second.storage_read; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 627 | } |
| 628 | |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 629 | bool IsImageLayoutDepthWritable(VkImageLayout image_layout) { |
| 630 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 631 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL || |
| 632 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) |
| 633 | ? true |
| 634 | : false; |
| 635 | } |
| 636 | |
| 637 | bool IsImageLayoutStencilWritable(VkImageLayout image_layout) { |
| 638 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 639 | image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL || |
| 640 | image_layout == VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL) |
| 641 | ? true |
| 642 | : false; |
| 643 | } |
| 644 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 645 | // 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] | 646 | template <typename Action> |
| 647 | static void ApplyOverImageRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &subresource_range_arg, |
| 648 | Action &action) { |
| 649 | // At this point the "apply over range" logic only supports a single memory binding |
| 650 | if (!SimpleBinding(image_state)) return; |
| 651 | auto subresource_range = NormalizeSubresourceRange(image_state.createInfo, subresource_range_arg); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 652 | const auto base_address = ResourceBaseAddress(image_state); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 653 | subresource_adapter::ImageRangeGenerator range_gen(*image_state.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
| 654 | image_state.createInfo.extent, base_address); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 655 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 656 | action(*range_gen); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 660 | // Tranverse the attachment resolves for this a specific subpass, and do action() to them. |
| 661 | // Used by both validation and record operations |
| 662 | // |
| 663 | // The signature for Action() reflect the needs of both uses. |
| 664 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 665 | void ResolveOperation(Action &action, const RENDER_PASS_STATE &rp_state, const AttachmentViewGenVector &attachment_views, |
| 666 | uint32_t subpass) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 667 | const auto &rp_ci = rp_state.createInfo; |
| 668 | const auto *attachment_ci = rp_ci.pAttachments; |
| 669 | const auto &subpass_ci = rp_ci.pSubpasses[subpass]; |
| 670 | |
| 671 | // Color resolves -- require an inuse color attachment and a matching inuse resolve attachment |
| 672 | const auto *color_attachments = subpass_ci.pColorAttachments; |
| 673 | const auto *color_resolve = subpass_ci.pResolveAttachments; |
| 674 | if (color_resolve && color_attachments) { |
| 675 | for (uint32_t i = 0; i < subpass_ci.colorAttachmentCount; i++) { |
| 676 | const auto &color_attach = color_attachments[i].attachment; |
| 677 | const auto &resolve_attach = subpass_ci.pResolveAttachments[i].attachment; |
| 678 | if ((color_attach != VK_ATTACHMENT_UNUSED) && (resolve_attach != VK_ATTACHMENT_UNUSED)) { |
| 679 | action("color", "resolve read", color_attach, resolve_attach, attachment_views[color_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 680 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, |
| 681 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 682 | action("color", "resolve write", color_attach, resolve_attach, attachment_views[resolve_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 683 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 684 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | // Depth stencil resolve only if the extension is present |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 690 | const auto ds_resolve = LvlFindInChain<VkSubpassDescriptionDepthStencilResolve>(subpass_ci.pNext); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 691 | if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment && |
| 692 | (ds_resolve->pDepthStencilResolveAttachment->attachment != VK_ATTACHMENT_UNUSED) && subpass_ci.pDepthStencilAttachment && |
| 693 | (subpass_ci.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) { |
| 694 | const auto src_at = subpass_ci.pDepthStencilAttachment->attachment; |
| 695 | const auto src_ci = attachment_ci[src_at]; |
| 696 | // The formats are required to match so we can pick either |
| 697 | const bool resolve_depth = (ds_resolve->depthResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasDepth(src_ci.format); |
| 698 | const bool resolve_stencil = (ds_resolve->stencilResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasStencil(src_ci.format); |
| 699 | const auto dst_at = ds_resolve->pDepthStencilResolveAttachment->attachment; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 700 | |
| 701 | // Figure out which aspects are actually touched during resolve operations |
| 702 | const char *aspect_string = nullptr; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 703 | AttachmentViewGen::Gen gen_type = AttachmentViewGen::Gen::kRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 704 | if (resolve_depth && resolve_stencil) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 705 | aspect_string = "depth/stencil"; |
| 706 | } else if (resolve_depth) { |
| 707 | // Validate depth only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 708 | gen_type = AttachmentViewGen::Gen::kDepthOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 709 | aspect_string = "depth"; |
| 710 | } else if (resolve_stencil) { |
| 711 | // Validate all stencil only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 712 | gen_type = AttachmentViewGen::Gen::kStencilOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 713 | aspect_string = "stencil"; |
| 714 | } |
| 715 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 716 | if (aspect_string) { |
| 717 | action(aspect_string, "resolve read", src_at, dst_at, attachment_views[src_at], gen_type, |
| 718 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, SyncOrdering::kRaster); |
| 719 | action(aspect_string, "resolve write", src_at, dst_at, attachment_views[dst_at], gen_type, |
| 720 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | // Action for validating resolve operations |
| 726 | class ValidateResolveAction { |
| 727 | public: |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 728 | ValidateResolveAction(VkRenderPass render_pass, uint32_t subpass, const AccessContext &context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 729 | const CommandExecutionContext &exec_context, const char *func_name) |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 730 | : render_pass_(render_pass), |
| 731 | subpass_(subpass), |
| 732 | context_(context), |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 733 | exec_context_(exec_context), |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 734 | func_name_(func_name), |
| 735 | skip_(false) {} |
| 736 | 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] | 737 | const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, |
| 738 | SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 739 | HazardResult hazard; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 740 | hazard = context_.DetectHazard(view_gen, gen_type, current_usage, ordering_rule); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 741 | if (hazard.hazard) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 742 | skip_ |= |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 743 | exec_context_.GetSyncState().LogError(render_pass_, string_SyncHazardVUID(hazard.hazard), |
| 744 | "%s: Hazard %s in subpass %" PRIu32 "during %s %s, from attachment %" PRIu32 |
| 745 | " to resolve attachment %" PRIu32 ". Access info %s.", |
| 746 | func_name_, string_SyncHazard(hazard.hazard), subpass_, aspect_name, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 747 | attachment_name, src_at, dst_at, exec_context_.FormatHazard(hazard).c_str()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | // Providing a mechanism for the constructing caller to get the result of the validation |
| 751 | bool GetSkip() const { return skip_; } |
| 752 | |
| 753 | private: |
| 754 | VkRenderPass render_pass_; |
| 755 | const uint32_t subpass_; |
| 756 | const AccessContext &context_; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 757 | const CommandExecutionContext &exec_context_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 758 | const char *func_name_; |
| 759 | bool skip_; |
| 760 | }; |
| 761 | |
| 762 | // Update action for resolve operations |
| 763 | class UpdateStateResolveAction { |
| 764 | public: |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 765 | UpdateStateResolveAction(AccessContext &context, ResourceUsageTag tag) : context_(context), tag_(tag) {} |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 766 | void operator()(const char *, const char *, uint32_t, uint32_t, const AttachmentViewGen &view_gen, |
| 767 | AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 768 | // Ignores validation only arguments... |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 769 | context_.UpdateAccessState(view_gen, gen_type, current_usage, ordering_rule, tag_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | private: |
| 773 | AccessContext &context_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 774 | const ResourceUsageTag tag_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 775 | }; |
| 776 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 777 | void HazardResult::Set(const ResourceAccessState *access_state_, SyncStageAccessIndex usage_index_, SyncHazard hazard_, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 778 | const SyncStageAccessFlags &prior_, const ResourceUsageTag tag_) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 779 | access_state = layer_data::make_unique<const ResourceAccessState>(*access_state_); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 780 | usage_index = usage_index_; |
| 781 | hazard = hazard_; |
| 782 | prior_access = prior_; |
| 783 | tag = tag_; |
| 784 | } |
| 785 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 786 | void HazardResult::AddRecordedAccess(const ResourceFirstAccess &first_access) { |
| 787 | recorded_access = layer_data::make_unique<const ResourceFirstAccess>(first_access); |
| 788 | } |
| 789 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 790 | AccessContext::AccessContext(uint32_t subpass, VkQueueFlags queue_flags, |
| 791 | const std::vector<SubpassDependencyGraphNode> &dependencies, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 792 | const std::vector<AccessContext> &contexts, const AccessContext *external_context) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 793 | Reset(); |
| 794 | const auto &subpass_dep = dependencies[subpass]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 795 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 796 | prev_.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 797 | 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] | 798 | for (const auto &prev_dep : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 799 | const auto prev_pass = prev_dep.first->pass; |
| 800 | const auto &prev_barriers = prev_dep.second; |
| 801 | assert(prev_dep.second.size()); |
| 802 | prev_.emplace_back(&contexts[prev_pass], queue_flags, prev_barriers); |
| 803 | prev_by_subpass_[prev_pass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 804 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 805 | |
| 806 | async_.reserve(subpass_dep.async.size()); |
| 807 | for (const auto async_subpass : subpass_dep.async) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 808 | async_.emplace_back(&contexts[async_subpass]); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 809 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 810 | if (has_barrier_from_external) { |
| 811 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 812 | prev_.emplace_back(external_context, queue_flags, subpass_dep.barrier_from_external); |
| 813 | src_external_ = &prev_.back(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 814 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 815 | if (subpass_dep.barrier_to_external.size()) { |
| 816 | dst_external_ = TrackBack(this, queue_flags, subpass_dep.barrier_to_external); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 817 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 818 | } |
| 819 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 820 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 821 | HazardResult AccessContext::DetectPreviousHazard(AccessAddressType type, const Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 822 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 823 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 824 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 825 | |
| 826 | HazardResult hazard; |
| 827 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 828 | hazard = detector.Detect(prev); |
| 829 | } |
| 830 | return hazard; |
| 831 | } |
| 832 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 833 | template <typename Action> |
| 834 | void AccessContext::ForAll(Action &&action) { |
| 835 | for (const auto address_type : kAddressTypes) { |
| 836 | auto &accesses = GetAccessStateMap(address_type); |
| 837 | for (const auto &access : accesses) { |
| 838 | action(address_type, access); |
| 839 | } |
| 840 | } |
| 841 | } |
| 842 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 843 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 844 | // the DAG of the contexts (for example subpasses) |
| 845 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 846 | HazardResult AccessContext::DetectHazard(AccessAddressType type, const Detector &detector, const ResourceAccessRange &range, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 847 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 848 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 849 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 850 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 851 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 852 | // so we'll check these first |
| 853 | for (const auto &async_context : async_) { |
| 854 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 855 | if (hazard.hazard) return hazard; |
| 856 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 857 | } |
| 858 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 859 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 860 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 861 | const auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 862 | const auto the_end = accesses.cend(); // End is not invalidated |
| 863 | auto pos = accesses.lower_bound(range); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 864 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 865 | |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 866 | while (pos != the_end && pos->first.begin < range.end) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 867 | // Cover any leading gap, or gap between entries |
| 868 | if (detect_prev) { |
| 869 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 870 | // Cover any leading gap, or gap between entries |
| 871 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 872 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 873 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 874 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 875 | if (hazard.hazard) return hazard; |
| 876 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 877 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 878 | gap.begin = pos->first.end; |
| 879 | } |
| 880 | |
| 881 | hazard = detector.Detect(pos); |
| 882 | if (hazard.hazard) return hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 883 | ++pos; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | if (detect_prev) { |
| 887 | // Detect in the trailing empty as needed |
| 888 | gap.end = range.end; |
| 889 | if (gap.non_empty()) { |
| 890 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 891 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | return hazard; |
| 895 | } |
| 896 | |
| 897 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 898 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 899 | HazardResult AccessContext::DetectAsyncHazard(AccessAddressType type, const Detector &detector, |
| 900 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 901 | auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 902 | auto pos = accesses.lower_bound(range); |
| 903 | const auto the_end = accesses.end(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 904 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 905 | HazardResult hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 906 | while (pos != the_end && pos->first.begin < range.end) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 907 | hazard = detector.DetectAsync(pos, start_tag_); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 908 | if (hazard.hazard) break; |
| 909 | ++pos; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 910 | } |
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 | return hazard; |
| 913 | } |
| 914 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 915 | struct ApplySubpassTransitionBarriersAction { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 916 | explicit ApplySubpassTransitionBarriersAction(const std::vector<SyncBarrier> &barriers_) : barriers(barriers_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 917 | void operator()(ResourceAccessState *access) const { |
| 918 | assert(access); |
| 919 | access->ApplyBarriers(barriers, true); |
| 920 | } |
| 921 | const std::vector<SyncBarrier> &barriers; |
| 922 | }; |
| 923 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 924 | struct ApplyTrackbackStackAction { |
| 925 | explicit ApplyTrackbackStackAction(const std::vector<SyncBarrier> &barriers_, |
| 926 | const ResourceAccessStateFunction *previous_barrier_ = nullptr) |
| 927 | : barriers(barriers_), previous_barrier(previous_barrier_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 928 | void operator()(ResourceAccessState *access) const { |
| 929 | assert(access); |
| 930 | assert(!access->HasPendingState()); |
| 931 | access->ApplyBarriers(barriers, false); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 932 | // NOTE: We can use invalid tag, as these barriers do no include layout transitions (would assert in SetWrite) |
| 933 | access->ApplyPendingBarriers(kInvalidTag); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 934 | if (previous_barrier) { |
| 935 | assert(bool(*previous_barrier)); |
| 936 | (*previous_barrier)(access); |
| 937 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 938 | } |
| 939 | const std::vector<SyncBarrier> &barriers; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 940 | const ResourceAccessStateFunction *previous_barrier; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 941 | }; |
| 942 | |
| 943 | // Splits a single map entry into piece matching the entries in [first, last) the total range over [first, last) must be |
| 944 | // contained with entry. Entry must be an iterator pointing to dest, first and last must be iterators pointing to a |
| 945 | // *different* map from dest. |
| 946 | // Returns the position past the last resolved range -- the entry covering the remainder of entry->first not included in the |
| 947 | // range [first, last) |
| 948 | template <typename BarrierAction> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 949 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 950 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 951 | BarrierAction &barrier_action) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 952 | auto at = entry; |
| 953 | for (auto pos = first; pos != last; ++pos) { |
| 954 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 955 | assert(at->first.includes(pos->first)); |
| 956 | assert(at != dest->end()); |
| 957 | // Trim up at to the same size as the entry to resolve |
| 958 | at = sparse_container::split(at, *dest, pos->first); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 959 | auto access = pos->second; // intentional copy |
| 960 | barrier_action(&access); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 961 | at->second.Resolve(access); |
| 962 | ++at; // Go to the remaining unused section of entry |
| 963 | } |
| 964 | } |
| 965 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 966 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 967 | SyncBarrier merged = {}; |
| 968 | for (const auto &barrier : barriers) { |
| 969 | merged.Merge(barrier); |
| 970 | } |
| 971 | return merged; |
| 972 | } |
| 973 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 974 | template <typename BarrierAction> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 975 | void AccessContext::ResolveAccessRange(AccessAddressType type, const ResourceAccessRange &range, BarrierAction &barrier_action, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 976 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 977 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 978 | if (!range.non_empty()) return; |
| 979 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 980 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 981 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 982 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 983 | if (current->pos_B->valid) { |
| 984 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 985 | auto access = src_pos->second; // intentional copy |
| 986 | barrier_action(&access); |
| 987 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 988 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 989 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 990 | trimmed->second.Resolve(access); |
| 991 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 992 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 993 | 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] | 994 | 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] | 995 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 996 | } else { |
| 997 | // we have to descend to fill this gap |
| 998 | if (recur_to_infill) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 999 | ResourceAccessRange recurrence_range = current_range; |
| 1000 | // The current context is empty for the current range, so recur to fill the gap. |
| 1001 | // Since we will be recurring back up the DAG, expand the gap descent to cover the full range for which B |
| 1002 | // is not valid, to minimize that recurrence |
| 1003 | if (current->pos_B.at_end()) { |
| 1004 | // Do the remainder here.... |
| 1005 | recurrence_range.end = range.end; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1006 | } else { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1007 | // Recur only over the range until B becomes valid (within the limits of range). |
| 1008 | 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] | 1009 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1010 | ResolvePreviousAccessStack(type, recurrence_range, resolve_map, infill_state, barrier_action); |
| 1011 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1012 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 1013 | // iterator of the outer while. |
| 1014 | |
| 1015 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 1016 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 1017 | // we stepped on the dest map |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1018 | 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] | 1019 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1020 | current.seek(seek_to); |
| 1021 | } else if (!current->pos_A->valid && infill_state) { |
| 1022 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 1023 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 1024 | 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] | 1025 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1026 | } |
ziga-lunarg | f0e27ad | 2022-03-28 00:44:12 +0200 | [diff] [blame] | 1027 | if (current->range.non_empty()) { |
| 1028 | ++current; |
| 1029 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1030 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1031 | |
| 1032 | // Infill if range goes passed both the current and resolve map prior contents |
| 1033 | if (recur_to_infill && (current->range.end < range.end)) { |
| 1034 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1035 | ResolvePreviousAccessStack<BarrierAction>(type, trailing_fill_range, resolve_map, infill_state, barrier_action); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1036 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1037 | } |
| 1038 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1039 | template <typename BarrierAction> |
| 1040 | void AccessContext::ResolvePreviousAccessStack(AccessAddressType type, const ResourceAccessRange &range, |
| 1041 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 1042 | const BarrierAction &previous_barrier) const { |
| 1043 | ResourceAccessStateFunction stacked_barrier(std::ref(previous_barrier)); |
| 1044 | ResolvePreviousAccess(type, range, descent_map, infill_state, &stacked_barrier); |
| 1045 | } |
| 1046 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1047 | void AccessContext::ResolvePreviousAccess(AccessAddressType type, const ResourceAccessRange &range, |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1048 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 1049 | const ResourceAccessStateFunction *previous_barrier) const { |
| 1050 | if (prev_.size() == 0) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1051 | if (range.non_empty() && infill_state) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1052 | // Fill the empty poritions of descent_map with the default_state with the barrier function applied (iff present) |
| 1053 | ResourceAccessState state_copy; |
| 1054 | if (previous_barrier) { |
| 1055 | assert(bool(*previous_barrier)); |
| 1056 | state_copy = *infill_state; |
| 1057 | (*previous_barrier)(&state_copy); |
| 1058 | infill_state = &state_copy; |
| 1059 | } |
| 1060 | sparse_container::update_range_value(*descent_map, range, *infill_state, |
| 1061 | sparse_container::value_precedence::prefer_dest); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1062 | } |
| 1063 | } else { |
| 1064 | // Look for something to fill the gap further along. |
| 1065 | for (const auto &prev_dep : prev_) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1066 | const ApplyTrackbackStackAction barrier_action(prev_dep.barriers, previous_barrier); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1067 | 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] | 1068 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1069 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1070 | } |
| 1071 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1072 | // Non-lazy import of all accesses, WaitEvents needs this. |
| 1073 | void AccessContext::ResolvePreviousAccesses() { |
| 1074 | ResourceAccessState default_state; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1075 | if (!prev_.size()) return; // If no previous contexts, nothing to do |
| 1076 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1077 | for (const auto address_type : kAddressTypes) { |
| 1078 | ResolvePreviousAccess(address_type, kFullRange, &GetAccessStateMap(address_type), &default_state); |
| 1079 | } |
| 1080 | } |
| 1081 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1082 | AccessAddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
| 1083 | return (image.fragment_encoder->IsLinearImage()) ? AccessAddressType::kLinear : AccessAddressType::kIdealized; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1084 | } |
| 1085 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1086 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1087 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_NONE_EXT) |
| 1088 | ? SYNC_ACCESS_INDEX_NONE |
| 1089 | : ((load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 1090 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1091 | return stage_access; |
| 1092 | } |
| 1093 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1094 | const auto stage_access = |
| 1095 | (load_op == VK_ATTACHMENT_LOAD_OP_NONE_EXT) |
| 1096 | ? SYNC_ACCESS_INDEX_NONE |
| 1097 | : ((load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 1098 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1099 | return stage_access; |
| 1100 | } |
| 1101 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1102 | // Caller must manage returned pointer |
| 1103 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1104 | uint32_t subpass, const AttachmentViewGenVector &attachment_views) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1105 | auto *proxy = new AccessContext(context); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1106 | proxy->UpdateAttachmentResolveAccess(rp_state, attachment_views, subpass, kInvalidTag); |
| 1107 | proxy->UpdateAttachmentStoreAccess(rp_state, attachment_views, subpass, kInvalidTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1108 | return proxy; |
| 1109 | } |
| 1110 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1111 | template <typename BarrierAction> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1112 | void AccessContext::ResolveAccessRange(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1113 | BarrierAction &barrier_action, ResourceAccessRangeMap *descent_map, |
| 1114 | const ResourceAccessState *infill_state) const { |
| 1115 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1116 | if (!attachment_gen) return; |
| 1117 | |
| 1118 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1119 | const AccessAddressType address_type = view_gen.GetAddressType(); |
| 1120 | for (; range_gen->non_empty(); ++range_gen) { |
| 1121 | ResolveAccessRange(address_type, *range_gen, barrier_action, descent_map, infill_state); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1122 | } |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 1123 | } |
| 1124 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1125 | // 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] | 1126 | 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] | 1127 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1128 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1129 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1130 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 1131 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 1132 | // those affects have not been recorded yet. |
| 1133 | // |
| 1134 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 1135 | // to apply and only copy then, if this proves a hot spot. |
| 1136 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 1137 | TrackBack proxy_track_back; |
| 1138 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1139 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 1140 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1141 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 1142 | |
| 1143 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1144 | assert(track_back); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1145 | if (prev_needs_proxy) { |
| 1146 | if (!proxy_for_prev) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1147 | proxy_for_prev.reset( |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1148 | CreateStoreResolveProxyContext(*track_back->source_subpass, rp_state, transition.prev_pass, attachment_views)); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1149 | proxy_track_back = *track_back; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1150 | proxy_track_back.source_subpass = proxy_for_prev.get(); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1151 | } |
| 1152 | track_back = &proxy_track_back; |
| 1153 | } |
| 1154 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1155 | if (hazard.hazard) { |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1156 | if (hazard.tag == kInvalidTag) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1157 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1158 | rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1159 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1160 | " image layout transition (old_layout: %s, new_layout: %s) after store/resolve operation in subpass %" PRIu32, |
| 1161 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1162 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), transition.prev_pass); |
| 1163 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1164 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1165 | rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1166 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1167 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 1168 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1169 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1170 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1171 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | return skip; |
| 1175 | } |
| 1176 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1177 | 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] | 1178 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1179 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1180 | bool skip = false; |
| 1181 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1182 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1183 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1184 | if (subpass == rp_state.attachment_first_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1185 | const auto &view_gen = attachment_views[i]; |
| 1186 | if (!view_gen.IsValid()) continue; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1187 | const auto &ci = attachment_ci[i]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1188 | |
| 1189 | // Need check in the following way |
| 1190 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 1191 | // vs. transition |
| 1192 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 1193 | // for each aspect loaded. |
| 1194 | |
| 1195 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1196 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1197 | const bool is_color = !(has_depth || has_stencil); |
| 1198 | |
| 1199 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1200 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1201 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1202 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1203 | const char *aspect = nullptr; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1204 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1205 | bool checked_stencil = false; |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1206 | if (is_color && (load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1207 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, load_index, SyncOrdering::kColorAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1208 | aspect = "color"; |
| 1209 | } else { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1210 | if (has_depth && (load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1211 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_index, |
| 1212 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1213 | aspect = "depth"; |
| 1214 | } |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1215 | if (!hazard.hazard && has_stencil && (stencil_load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1216 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, stencil_load_index, |
| 1217 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1218 | aspect = "stencil"; |
| 1219 | checked_stencil = true; |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | if (hazard.hazard) { |
| 1224 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1225 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1226 | if (hazard.tag == kInvalidTag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1227 | // Hazard vs. ILT |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1228 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1229 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1230 | " aspect %s during load with loadOp %s.", |
| 1231 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string); |
| 1232 | } else { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1233 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1234 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1235 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1236 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1237 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | return skip; |
| 1243 | } |
| 1244 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1245 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 1246 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 1247 | // store is part of the same Next/End operation. |
| 1248 | // The latter is handled in layout transistion validation directly |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1249 | 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] | 1250 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1251 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1252 | bool skip = false; |
| 1253 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1254 | |
| 1255 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1256 | if (subpass == rp_state.attachment_last_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1257 | const AttachmentViewGen &view_gen = attachment_views[i]; |
| 1258 | if (!view_gen.IsValid()) continue; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1259 | const auto &ci = attachment_ci[i]; |
| 1260 | |
| 1261 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1262 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 1263 | // sake, we treat DONT_CARE as writing. |
| 1264 | const bool has_depth = FormatHasDepth(ci.format); |
| 1265 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1266 | const bool is_color = !(has_depth || has_stencil); |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1267 | 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] | 1268 | if (!has_stencil && !store_op_stores) continue; |
| 1269 | |
| 1270 | HazardResult hazard; |
| 1271 | const char *aspect = nullptr; |
| 1272 | bool checked_stencil = false; |
| 1273 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1274 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1275 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1276 | aspect = "color"; |
| 1277 | } else { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1278 | 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] | 1279 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1280 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1281 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1282 | aspect = "depth"; |
| 1283 | } |
| 1284 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1285 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1286 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1287 | aspect = "stencil"; |
| 1288 | checked_stencil = true; |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | if (hazard.hazard) { |
| 1293 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 1294 | 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] | 1295 | skip |= exec_context.GetSyncState().LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1296 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1297 | " %s aspect during store with %s %s. Access info %s", |
| 1298 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, |
| 1299 | op_type_string, store_op_string, |
| 1300 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | } |
| 1304 | return skip; |
| 1305 | } |
| 1306 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1307 | 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] | 1308 | const VkRect2D &render_area, const AttachmentViewGenVector &attachment_views, |
| 1309 | const char *func_name, uint32_t subpass) const { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1310 | ValidateResolveAction validate_action(rp_state.renderPass(), subpass, *this, exec_context, func_name); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1311 | ResolveOperation(validate_action, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1312 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1313 | } |
| 1314 | |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 1315 | AccessContext::TrackBack *AccessContext::AddTrackBack(const AccessContext *context, const SyncBarrier &barrier) { |
| 1316 | prev_.emplace_back(context, barrier); |
| 1317 | return &prev_.back(); |
| 1318 | } |
| 1319 | |
| 1320 | void AccessContext::AddAsyncContext(const AccessContext *context) { async_.emplace_back(context); } |
| 1321 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1322 | class HazardDetector { |
| 1323 | SyncStageAccessIndex usage_index_; |
| 1324 | |
| 1325 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1326 | 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] | 1327 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1328 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1329 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1330 | explicit HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1331 | }; |
| 1332 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1333 | class HazardDetectorWithOrdering { |
| 1334 | const SyncStageAccessIndex usage_index_; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1335 | const SyncOrdering ordering_rule_; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1336 | |
| 1337 | public: |
| 1338 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1339 | return pos->second.DetectHazard(usage_index_, ordering_rule_); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1340 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1341 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1342 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1343 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1344 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, SyncOrdering ordering) : usage_index_(usage), ordering_rule_(ordering) {} |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1345 | }; |
| 1346 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1347 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1348 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1349 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1350 | const auto base_address = ResourceBaseAddress(buffer); |
| 1351 | HazardDetector detector(usage_index); |
| 1352 | return DetectHazard(AccessAddressType::kLinear, detector, (range + base_address), DetectOptions::kDetectAll); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 1353 | } |
| 1354 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1355 | template <typename Detector> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1356 | HazardResult AccessContext::DetectHazard(Detector &detector, const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1357 | DetectOptions options) const { |
| 1358 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1359 | if (!attachment_gen) return HazardResult(); |
| 1360 | |
| 1361 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1362 | const auto address_type = view_gen.GetAddressType(); |
| 1363 | for (; range_gen->non_empty(); ++range_gen) { |
| 1364 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1365 | if (hazard.hazard) return hazard; |
| 1366 | } |
| 1367 | |
| 1368 | return HazardResult(); |
| 1369 | } |
| 1370 | |
| 1371 | template <typename Detector> |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1372 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1373 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1374 | const VkExtent3D &extent, DetectOptions options) const { |
| 1375 | if (!SimpleBinding(image)) return HazardResult(); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1376 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1377 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1378 | base_address); |
| 1379 | const auto address_type = ImageAddressType(image); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1380 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1381 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1382 | if (hazard.hazard) return hazard; |
| 1383 | } |
| 1384 | return HazardResult(); |
| 1385 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1386 | template <typename Detector> |
| 1387 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1388 | const VkImageSubresourceRange &subresource_range, DetectOptions options) const { |
| 1389 | if (!SimpleBinding(image)) return HazardResult(); |
| 1390 | const auto base_address = ResourceBaseAddress(image); |
| 1391 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
| 1392 | const auto address_type = ImageAddressType(image); |
| 1393 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1394 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1395 | if (hazard.hazard) return hazard; |
| 1396 | } |
| 1397 | return HazardResult(); |
| 1398 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1399 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1400 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1401 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1402 | const VkExtent3D &extent) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1403 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1404 | subresource.layerCount}; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1405 | HazardDetector detector(current_usage); |
| 1406 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1410 | const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1411 | HazardDetector detector(current_usage); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1412 | return DetectHazard(detector, image, subresource_range, DetectOptions::kDetectAll); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1413 | } |
| 1414 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1415 | HazardResult AccessContext::DetectHazard(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1416 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) const { |
| 1417 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
| 1418 | return DetectHazard(detector, view_gen, gen_type, DetectOptions::kDetectAll); |
| 1419 | } |
| 1420 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1421 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1422 | const VkImageSubresourceRange &subresource_range, SyncOrdering ordering_rule, |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1423 | const VkOffset3D &offset, const VkExtent3D &extent) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1424 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1425 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1426 | } |
| 1427 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1428 | class BarrierHazardDetector { |
| 1429 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1430 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1431 | SyncStageAccessFlags src_access_scope) |
| 1432 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1433 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1434 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1435 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1436 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1437 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1438 | // 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] | 1439 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | private: |
| 1443 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1444 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1445 | SyncStageAccessFlags src_access_scope_; |
| 1446 | }; |
| 1447 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1448 | class EventBarrierHazardDetector { |
| 1449 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1450 | EventBarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1451 | SyncStageAccessFlags src_access_scope, const SyncEventState::ScopeMap &event_scope, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1452 | ResourceUsageTag scope_tag) |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1453 | : usage_index_(usage_index), |
| 1454 | src_exec_scope_(src_exec_scope), |
| 1455 | src_access_scope_(src_access_scope), |
| 1456 | event_scope_(event_scope), |
| 1457 | scope_pos_(event_scope.cbegin()), |
| 1458 | scope_end_(event_scope.cend()), |
| 1459 | scope_tag_(scope_tag) {} |
| 1460 | |
| 1461 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1462 | // TODO NOTE: This is almost the slowest way to do this... need to intelligently walk this... |
| 1463 | // Need to find a more efficient sync, since we know pos->first is strictly increasing call to call |
| 1464 | // NOTE: "cached_lower_bound_impl" with upgrades could do this. |
| 1465 | if (scope_pos_ == scope_end_) return HazardResult(); |
| 1466 | if (!scope_pos_->first.intersects(pos->first)) { |
| 1467 | event_scope_.lower_bound(pos->first); |
| 1468 | if ((scope_pos_ == scope_end_) || !scope_pos_->first.intersects(pos->first)) return HazardResult(); |
| 1469 | } |
| 1470 | |
| 1471 | // Some portion of this pos is in the event_scope, so check for a barrier hazard |
| 1472 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_, scope_tag_); |
| 1473 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1474 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1475 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1476 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
| 1477 | } |
| 1478 | |
| 1479 | private: |
| 1480 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1481 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1482 | SyncStageAccessFlags src_access_scope_; |
| 1483 | const SyncEventState::ScopeMap &event_scope_; |
| 1484 | SyncEventState::ScopeMap::const_iterator scope_pos_; |
| 1485 | SyncEventState::ScopeMap::const_iterator scope_end_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1486 | const ResourceUsageTag scope_tag_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1487 | }; |
| 1488 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1489 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1490 | const SyncStageAccessFlags &src_access_scope, |
| 1491 | const VkImageSubresourceRange &subresource_range, |
| 1492 | const SyncEventState &sync_event, DetectOptions options) const { |
| 1493 | // It's not particularly DRY to get the address type in this function as well as lower down, but we have to select the |
| 1494 | // first access scope map to use, and there's no easy way to plumb it in below. |
| 1495 | const auto address_type = ImageAddressType(image); |
| 1496 | const auto &event_scope = sync_event.FirstScope(address_type); |
| 1497 | |
| 1498 | EventBarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope, |
| 1499 | event_scope, sync_event.first_scope_tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1500 | return DetectHazard(detector, image, subresource_range, options); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1503 | HazardResult AccessContext::DetectImageBarrierHazard(const AttachmentViewGen &view_gen, const SyncBarrier &barrier, |
| 1504 | DetectOptions options) const { |
| 1505 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, barrier.src_exec_scope.exec_scope, |
| 1506 | barrier.src_access_scope); |
| 1507 | return DetectHazard(detector, view_gen, AttachmentViewGen::Gen::kViewSubresource, options); |
| 1508 | } |
| 1509 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1510 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1511 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1512 | const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1513 | const DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1514 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1515 | return DetectHazard(detector, image, subresource_range, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1518 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1519 | const SyncStageAccessFlags &src_stage_accesses, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1520 | const VkImageMemoryBarrier &barrier) const { |
| 1521 | auto subresource_range = NormalizeSubresourceRange(image.createInfo, barrier.subresourceRange); |
| 1522 | const auto src_access_scope = SyncStageAccess::AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 1523 | return DetectImageBarrierHazard(image, src_exec_scope, src_access_scope, subresource_range, kDetectAll); |
| 1524 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1525 | HazardResult AccessContext::DetectImageBarrierHazard(const SyncImageMemoryBarrier &image_barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1526 | 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] | 1527 | image_barrier.barrier.src_access_scope, image_barrier.range, kDetectAll); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1528 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1529 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1530 | template <typename Flags, typename Map> |
| 1531 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1532 | SyncStageAccessFlags scope = 0; |
| 1533 | for (const auto &bit_scope : map) { |
| 1534 | if (flag_mask < bit_scope.first) break; |
| 1535 | |
| 1536 | if (flag_mask & bit_scope.first) { |
| 1537 | scope |= bit_scope.second; |
| 1538 | } |
| 1539 | } |
| 1540 | return scope; |
| 1541 | } |
| 1542 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1543 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags2KHR stages) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1544 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1545 | } |
| 1546 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1547 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags2KHR accesses) { |
| 1548 | return AccessScopeImpl(sync_utils::ExpandAccessFlags(accesses), syncStageAccessMaskByAccessBit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1549 | } |
| 1550 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1551 | // Getting from stage mask and access mask to stage/access masks is something we need to be good at... |
| 1552 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags2KHR stages, VkAccessFlags2KHR accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1553 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1554 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1555 | // 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] | 1556 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1557 | } |
| 1558 | |
| 1559 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1560 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1561 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1562 | // that do incrementalupdates |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1563 | assert(accesses); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1564 | auto pos = accesses->lower_bound(range); |
| 1565 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1566 | // The range is empty, fill it with a default value. |
| 1567 | pos = action.Infill(accesses, pos, range); |
| 1568 | } else if (range.begin < pos->first.begin) { |
| 1569 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1570 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1571 | } else if (pos->first.begin < range.begin) { |
| 1572 | // Trim the beginning if needed |
| 1573 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1574 | ++pos; |
| 1575 | } |
| 1576 | |
| 1577 | const auto the_end = accesses->end(); |
| 1578 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1579 | if (pos->first.end > range.end) { |
| 1580 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1581 | } |
| 1582 | |
| 1583 | pos = action(accesses, pos); |
| 1584 | if (pos == the_end) break; |
| 1585 | |
| 1586 | auto next = pos; |
| 1587 | ++next; |
| 1588 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1589 | // Need to infill if next is disjoint |
| 1590 | 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] | 1591 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1592 | next = action.Infill(accesses, next, new_range); |
| 1593 | } |
| 1594 | pos = next; |
| 1595 | } |
| 1596 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1597 | |
| 1598 | // Give a comparable interface for range generators and ranges |
| 1599 | template <typename Action> |
| 1600 | inline void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, ResourceAccessRange *range) { |
| 1601 | assert(range); |
| 1602 | UpdateMemoryAccessState(accesses, *range, action); |
| 1603 | } |
| 1604 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1605 | template <typename Action, typename RangeGen> |
| 1606 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, RangeGen *range_gen_arg) { |
| 1607 | assert(range_gen_arg); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1608 | 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] | 1609 | for (; range_gen->non_empty(); ++range_gen) { |
| 1610 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1611 | } |
| 1612 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1613 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1614 | template <typename Action, typename RangeGen> |
| 1615 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, const RangeGen &range_gen_prebuilt) { |
| 1616 | RangeGen range_gen(range_gen_prebuilt); // RangeGenerators can be expensive to create from scratch... initialize from built |
| 1617 | for (; range_gen->non_empty(); ++range_gen) { |
| 1618 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1619 | } |
| 1620 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1621 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1622 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1623 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1624 | // this is only called on gaps, and never returns a gap. |
| 1625 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1626 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1627 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1628 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1629 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1630 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1631 | auto &access_state = pos->second; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1632 | access_state.Update(usage, ordering_rule, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1633 | return pos; |
| 1634 | } |
| 1635 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1636 | UpdateMemoryAccessStateFunctor(AccessAddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1637 | SyncOrdering ordering_rule_, ResourceUsageTag tag_) |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1638 | : type(type_), context(context_), usage(usage_), ordering_rule(ordering_rule_), tag(tag_) {} |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1639 | const AccessAddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1640 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1641 | const SyncStageAccessIndex usage; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1642 | const SyncOrdering ordering_rule; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1643 | const ResourceUsageTag tag; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1644 | }; |
| 1645 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1646 | // The barrier operation for pipeline and subpass dependencies` |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1647 | struct PipelineBarrierOp { |
| 1648 | SyncBarrier barrier; |
| 1649 | bool layout_transition; |
| 1650 | PipelineBarrierOp(const SyncBarrier &barrier_, bool layout_transition_) |
| 1651 | : barrier(barrier_), layout_transition(layout_transition_) {} |
| 1652 | PipelineBarrierOp() = default; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1653 | PipelineBarrierOp(const PipelineBarrierOp &) = default; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1654 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(barrier, layout_transition); } |
| 1655 | }; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1656 | // The barrier operation for wait events |
| 1657 | struct WaitEventBarrierOp { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1658 | ResourceUsageTag scope_tag; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1659 | SyncBarrier barrier; |
| 1660 | bool layout_transition; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1661 | WaitEventBarrierOp(const ResourceUsageTag scope_tag_, const SyncBarrier &barrier_, bool layout_transition_) |
| 1662 | : scope_tag(scope_tag_), barrier(barrier_), layout_transition(layout_transition_) {} |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1663 | WaitEventBarrierOp() = default; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1664 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(scope_tag, barrier, layout_transition); } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1665 | }; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1666 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1667 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1668 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1669 | // of a collection is known/present. |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1670 | template <typename BarrierOp, typename OpVector = std::vector<BarrierOp>> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1671 | class ApplyBarrierOpsFunctor { |
| 1672 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1673 | using Iterator = ResourceAccessRangeMap::iterator; |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1674 | // Only called with a gap, and pos at the lower_bound(range) |
| 1675 | inline Iterator Infill(ResourceAccessRangeMap *accesses, const Iterator &pos, const ResourceAccessRange &range) const { |
| 1676 | if (!infill_default_) { |
| 1677 | return pos; |
| 1678 | } |
| 1679 | ResourceAccessState default_state; |
| 1680 | auto inserted = accesses->insert(pos, std::make_pair(range, default_state)); |
| 1681 | return inserted; |
| 1682 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1683 | |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1684 | Iterator operator()(ResourceAccessRangeMap *accesses, const Iterator &pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1685 | auto &access_state = pos->second; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1686 | for (const auto &op : barrier_ops_) { |
| 1687 | op(&access_state); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1688 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1689 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1690 | if (resolve_) { |
| 1691 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1692 | // another walk |
| 1693 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1694 | } |
| 1695 | return pos; |
| 1696 | } |
| 1697 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1698 | // 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] | 1699 | ApplyBarrierOpsFunctor(bool resolve, typename OpVector::size_type size_hint, ResourceUsageTag tag) |
| 1700 | : resolve_(resolve), infill_default_(false), barrier_ops_(), tag_(tag) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1701 | barrier_ops_.reserve(size_hint); |
| 1702 | } |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1703 | void EmplaceBack(const BarrierOp &op) { |
| 1704 | barrier_ops_.emplace_back(op); |
| 1705 | infill_default_ |= op.layout_transition; |
| 1706 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1707 | |
| 1708 | private: |
| 1709 | bool resolve_; |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1710 | bool infill_default_; |
| 1711 | OpVector barrier_ops_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1712 | const ResourceUsageTag tag_; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1713 | }; |
| 1714 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1715 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1716 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1717 | template <typename BarrierOp> |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1718 | class ApplyBarrierFunctor : public ApplyBarrierOpsFunctor<BarrierOp, small_vector<BarrierOp, 1>> { |
| 1719 | using Base = ApplyBarrierOpsFunctor<BarrierOp, small_vector<BarrierOp, 1>>; |
| 1720 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1721 | public: |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1722 | 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] | 1723 | }; |
| 1724 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1725 | // This functor resolves the pendinging state. |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1726 | class ResolvePendingBarrierFunctor : public ApplyBarrierOpsFunctor<NoopBarrierAction, small_vector<NoopBarrierAction, 1>> { |
| 1727 | using Base = ApplyBarrierOpsFunctor<NoopBarrierAction, small_vector<NoopBarrierAction, 1>>; |
| 1728 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1729 | public: |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1730 | ResolvePendingBarrierFunctor(ResourceUsageTag tag) : Base(true, 0, tag) {} |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1731 | }; |
| 1732 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1733 | void AccessContext::UpdateAccessState(AccessAddressType type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1734 | const ResourceAccessRange &range, const ResourceUsageTag tag) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1735 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1736 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1737 | } |
| 1738 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1739 | 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] | 1740 | const ResourceAccessRange &range, const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1741 | if (!SimpleBinding(buffer)) return; |
| 1742 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1743 | UpdateAccessState(AccessAddressType::kLinear, current_usage, ordering_rule, range + base_address, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1744 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1745 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1746 | 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] | 1747 | const VkImageSubresourceRange &subresource_range, const ResourceUsageTag &tag) { |
| 1748 | if (!SimpleBinding(image)) return; |
| 1749 | const auto base_address = ResourceBaseAddress(image); |
| 1750 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
| 1751 | const auto address_type = ImageAddressType(image); |
| 1752 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1753 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
| 1754 | } |
| 1755 | 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] | 1756 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1757 | const VkExtent3D &extent, const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1758 | if (!SimpleBinding(image)) return; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1759 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1760 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1761 | base_address); |
| 1762 | const auto address_type = ImageAddressType(image); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1763 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1764 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1765 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1766 | |
| 1767 | void AccessContext::UpdateAccessState(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1768 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, const ResourceUsageTag tag) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1769 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1770 | if (!gen) return; |
| 1771 | subresource_adapter::ImageRangeGenerator range_gen(*gen); |
| 1772 | const auto address_type = view_gen.GetAddressType(); |
| 1773 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1774 | ApplyUpdateAction(address_type, action, &range_gen); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1775 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1776 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1777 | 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] | 1778 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1779 | const VkExtent3D &extent, const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1780 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1781 | subresource.layerCount}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1782 | UpdateAccessState(image, current_usage, ordering_rule, subresource_range, offset, extent, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1783 | } |
| 1784 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1785 | template <typename Action, typename RangeGen> |
| 1786 | void AccessContext::ApplyUpdateAction(AccessAddressType address_type, const Action &action, RangeGen *range_gen_arg) { |
| 1787 | assert(range_gen_arg); // Old Google C++ styleguide require non-const object pass by * not &, but this isn't an optional arg. |
| 1788 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, range_gen_arg); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1792 | void AccessContext::ApplyUpdateAction(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, const Action &action) { |
| 1793 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1794 | if (!gen) return; |
| 1795 | UpdateMemoryAccessState(&GetAccessStateMap(view_gen.GetAddressType()), action, *gen); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1796 | } |
| 1797 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1798 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, |
| 1799 | const AttachmentViewGenVector &attachment_views, uint32_t subpass, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1800 | const ResourceUsageTag tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1801 | UpdateStateResolveAction update(*this, tag); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1802 | ResolveOperation(update, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1803 | } |
| 1804 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1805 | 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] | 1806 | uint32_t subpass, const ResourceUsageTag tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1807 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1808 | |
| 1809 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1810 | if (rp_state.attachment_last_subpass[i] == subpass) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1811 | const auto &view_gen = attachment_views[i]; |
| 1812 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1813 | |
| 1814 | const auto &ci = attachment_ci[i]; |
| 1815 | const bool has_depth = FormatHasDepth(ci.format); |
| 1816 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1817 | const bool is_color = !(has_depth || has_stencil); |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1818 | 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] | 1819 | |
| 1820 | if (is_color && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1821 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1822 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1823 | } else { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1824 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1825 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1826 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1827 | } |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1828 | 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] | 1829 | if (has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1830 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1831 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | } |
| 1837 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1838 | template <typename Action> |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1839 | void AccessContext::ApplyToContext(const Action &barrier_action) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1840 | // 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] | 1841 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1842 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), kFullRange, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1847 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1848 | auto &context = contexts[subpass_index]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1849 | ApplyTrackbackStackAction barrier_action(context.GetDstExternalTrackBack().barriers); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1850 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1851 | context.ResolveAccessRange(address_type, kFullRange, barrier_action, &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | } |
| 1855 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 1856 | // Caller must ensure that lifespan of this is less than from |
| 1857 | void AccessContext::ImportAsyncContexts(const AccessContext &from) { async_ = from.async_; } |
| 1858 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1859 | // Suitable only for *subpass* access contexts |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1860 | HazardResult AccessContext::DetectSubpassTransitionHazard(const TrackBack &track_back, const AttachmentViewGen &attach_view) const { |
| 1861 | if (!attach_view.IsValid()) return HazardResult(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1862 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1863 | // 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] | 1864 | assert(track_back.source_subpass); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1865 | |
| 1866 | // 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] | 1867 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1868 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1869 | HazardResult hazard = track_back.source_subpass->DetectImageBarrierHazard(attach_view, merged_barrier, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1870 | if (!hazard.hazard) { |
| 1871 | // The Async hazard check is against the current context's async set. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1872 | hazard = DetectImageBarrierHazard(attach_view, merged_barrier, kDetectAsync); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1873 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1874 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1875 | return hazard; |
| 1876 | } |
| 1877 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1878 | void AccessContext::RecordLayoutTransitions(const RENDER_PASS_STATE &rp_state, uint32_t subpass, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1879 | const AttachmentViewGenVector &attachment_views, const ResourceUsageTag tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1880 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1881 | const ResourceAccessState empty_infill; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1882 | for (const auto &transition : transitions) { |
| 1883 | const auto prev_pass = transition.prev_pass; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1884 | const auto &view_gen = attachment_views[transition.attachment]; |
| 1885 | if (!view_gen.IsValid()) continue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1886 | |
| 1887 | const auto *trackback = GetTrackBackFromSubpass(prev_pass); |
| 1888 | assert(trackback); |
| 1889 | |
| 1890 | // Import the attachments into the current context |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1891 | const auto *prev_context = trackback->source_subpass; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1892 | assert(prev_context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1893 | const auto address_type = view_gen.GetAddressType(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1894 | auto &target_map = GetAccessStateMap(address_type); |
| 1895 | ApplySubpassTransitionBarriersAction barrier_action(trackback->barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1896 | prev_context->ResolveAccessRange(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action, &target_map, |
| 1897 | &empty_infill); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1898 | } |
| 1899 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1900 | // If there were no transitions skip this global map walk |
| 1901 | if (transitions.size()) { |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1902 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1903 | ApplyToContext(apply_pending_action); |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1904 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1905 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1906 | |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1907 | void CommandBufferAccessContext::ApplyGlobalBarriersToEvents(const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 1908 | auto *events_context = GetCurrentEventsContext(); |
| 1909 | assert(events_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 1910 | events_context->ApplyBarrier(src, dst); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1913 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1914 | const char *func_name) const { |
| 1915 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1916 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1917 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 1918 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1919 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1920 | return skip; |
| 1921 | } |
| 1922 | |
| 1923 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1924 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1925 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1926 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1927 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1928 | for (const auto &stage_state : pipe->stage_state) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 1929 | const auto raster_state = pipe->RasterizationState(); |
| 1930 | 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] | 1931 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1932 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1933 | for (const auto &set_binding : stage_state.descriptor_uses) { |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 1934 | const auto *descriptor_set = (*per_sets)[set_binding.first.set].bound_descriptor_set.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1935 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1936 | set_binding.first.binding); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1937 | const auto descriptor_type = binding_it.GetType(); |
| 1938 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1939 | auto array_idx = 0; |
| 1940 | |
| 1941 | if (binding_it.IsVariableDescriptorCount()) { |
| 1942 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1943 | } |
| 1944 | SyncStageAccessIndex sync_index = |
| 1945 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1946 | |
| 1947 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1948 | uint32_t index = i - index_range.start; |
| 1949 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1950 | switch (descriptor->GetClass()) { |
| 1951 | case DescriptorClass::ImageSampler: |
| 1952 | case DescriptorClass::Image: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1953 | if (descriptor->Invalid()) { |
| 1954 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1955 | } |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1956 | |
| 1957 | // NOTE: ImageSamplerDescriptor inherits from ImageDescriptor, so this cast works for both types. |
| 1958 | const auto *image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 1959 | const auto *img_view_state = image_descriptor->GetImageViewState(); |
| 1960 | VkImageLayout image_layout = image_descriptor->GetImageLayout(); |
| 1961 | |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1962 | HazardResult hazard; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 1963 | // NOTE: 2D ImageViews of VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT Images are not allowed in |
| 1964 | // Descriptors, so we do not have to worry about depth slicing here. |
| 1965 | // See: VUID 00343 |
| 1966 | assert(!img_view_state->IsDepthSliced()); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1967 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1968 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1969 | |
| 1970 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1971 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1972 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1973 | // Input attachments are subject to raster ordering rules |
| 1974 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1975 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1976 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1977 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1978 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1979 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1980 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1981 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1982 | img_view_state->image_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1983 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 1984 | ", index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1985 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1986 | sync_state_->report_data->FormatHandle(img_view_state->image_view()).c_str(), |
| 1987 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 1988 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1989 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1990 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1991 | set_binding.first.binding, index, FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1992 | } |
| 1993 | break; |
| 1994 | } |
| 1995 | case DescriptorClass::TexelBuffer: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1996 | const auto *texel_descriptor = static_cast<const TexelDescriptor *>(descriptor); |
| 1997 | if (texel_descriptor->Invalid()) { |
| 1998 | continue; |
| 1999 | } |
| 2000 | const auto *buf_view_state = texel_descriptor->GetBufferViewState(); |
| 2001 | const auto *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2002 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2003 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 2004 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2005 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2006 | buf_view_state->buffer_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2007 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 2008 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2009 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view()).c_str(), |
| 2010 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 2011 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2012 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2013 | string_VkDescriptorType(descriptor_type), set_binding.first.binding, index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2014 | FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2015 | } |
| 2016 | break; |
| 2017 | } |
| 2018 | case DescriptorClass::GeneralBuffer: { |
| 2019 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2020 | if (buffer_descriptor->Invalid()) { |
| 2021 | continue; |
| 2022 | } |
| 2023 | const auto *buf_state = buffer_descriptor->GetBufferState(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2024 | const ResourceAccessRange range = |
| 2025 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2026 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 2027 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2028 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2029 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2030 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 2031 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2032 | sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 2033 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 2034 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2035 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2036 | string_VkDescriptorType(descriptor_type), set_binding.first.binding, index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2037 | FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2038 | } |
| 2039 | break; |
| 2040 | } |
| 2041 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2042 | default: |
| 2043 | break; |
| 2044 | } |
| 2045 | } |
| 2046 | } |
| 2047 | } |
| 2048 | return skip; |
| 2049 | } |
| 2050 | |
| 2051 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2052 | const ResourceUsageTag tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2053 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2054 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2055 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2056 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2057 | return; |
| 2058 | } |
| 2059 | |
| 2060 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 2061 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 2062 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2063 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 2064 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2065 | for (const auto &stage_state : pipe->stage_state) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2066 | const auto raster_state = pipe->RasterizationState(); |
| 2067 | 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] | 2068 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2069 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2070 | for (const auto &set_binding : stage_state.descriptor_uses) { |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 2071 | const auto *descriptor_set = (*per_sets)[set_binding.first.set].bound_descriptor_set.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2072 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2073 | set_binding.first.binding); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2074 | const auto descriptor_type = binding_it.GetType(); |
| 2075 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 2076 | auto array_idx = 0; |
| 2077 | |
| 2078 | if (binding_it.IsVariableDescriptorCount()) { |
| 2079 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 2080 | } |
| 2081 | SyncStageAccessIndex sync_index = |
| 2082 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 2083 | |
| 2084 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 2085 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 2086 | switch (descriptor->GetClass()) { |
| 2087 | case DescriptorClass::ImageSampler: |
| 2088 | case DescriptorClass::Image: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2089 | // NOTE: ImageSamplerDescriptor inherits from ImageDescriptor, so this cast works for both types. |
| 2090 | const auto *image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 2091 | if (image_descriptor->Invalid()) { |
| 2092 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2093 | } |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2094 | const auto *img_view_state = image_descriptor->GetImageViewState(); |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 2095 | // NOTE: 2D ImageViews of VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT Images are not allowed in |
| 2096 | // Descriptors, so we do not have to worry about depth slicing here. |
| 2097 | // See: VUID 00343 |
| 2098 | assert(!img_view_state->IsDepthSliced()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2099 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2100 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2101 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 2102 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 2103 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kRaster, |
| 2104 | img_view_state->normalized_subresource_range, offset, extent, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2105 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2106 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kNonAttachment, |
| 2107 | img_view_state->normalized_subresource_range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2108 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2109 | break; |
| 2110 | } |
| 2111 | case DescriptorClass::TexelBuffer: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2112 | const auto *texel_descriptor = static_cast<const TexelDescriptor *>(descriptor); |
| 2113 | if (texel_descriptor->Invalid()) { |
| 2114 | continue; |
| 2115 | } |
| 2116 | const auto *buf_view_state = texel_descriptor->GetBufferViewState(); |
| 2117 | const auto *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2118 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2119 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2120 | break; |
| 2121 | } |
| 2122 | case DescriptorClass::GeneralBuffer: { |
| 2123 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2124 | if (buffer_descriptor->Invalid()) { |
| 2125 | continue; |
| 2126 | } |
| 2127 | const auto *buf_state = buffer_descriptor->GetBufferState(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2128 | const ResourceAccessRange range = |
| 2129 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2130 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2131 | break; |
| 2132 | } |
| 2133 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2134 | default: |
| 2135 | break; |
| 2136 | } |
| 2137 | } |
| 2138 | } |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const char *func_name) const { |
| 2143 | bool skip = false; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2144 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2145 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2146 | return skip; |
| 2147 | } |
| 2148 | |
| 2149 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2150 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2151 | const auto &binding_descriptions_size = pipe->vertex_input_state->binding_descriptions.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2152 | |
| 2153 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2154 | const auto &binding_description = pipe->vertex_input_state->binding_descriptions[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2155 | if (binding_description.binding < binding_buffers_size) { |
| 2156 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2157 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2158 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2159 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2160 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2161 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2162 | 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] | 2163 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2164 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2165 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for vertex %s in %s. Access info %s.", |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2166 | func_name, string_SyncHazard(hazard.hazard), |
| 2167 | sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 2168 | 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] | 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | return skip; |
| 2173 | } |
| 2174 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2175 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag tag) { |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2176 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2177 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2178 | return; |
| 2179 | } |
| 2180 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2181 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2182 | const auto &binding_descriptions_size = pipe->vertex_input_state->binding_descriptions.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2183 | |
| 2184 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2185 | const auto &binding_description = pipe->vertex_input_state->binding_descriptions[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2186 | if (binding_description.binding < binding_buffers_size) { |
| 2187 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2188 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2189 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2190 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2191 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2192 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2193 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ, |
| 2194 | SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const char *func_name) const { |
| 2200 | bool skip = false; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2201 | 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] | 2202 | return skip; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2203 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2204 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2205 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2206 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2207 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2208 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2209 | 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] | 2210 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2211 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2212 | index_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for index %s in %s. Access info %s.", |
| 2213 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(index_buf_state->buffer()).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2214 | 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] | 2215 | } |
| 2216 | |
| 2217 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2218 | // We will detect more accurate range in the future. |
| 2219 | skip |= ValidateDrawVertex(UINT32_MAX, 0, func_name); |
| 2220 | return skip; |
| 2221 | } |
| 2222 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2223 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag tag) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2224 | 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] | 2225 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2226 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2227 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2228 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2229 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2230 | 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] | 2231 | |
| 2232 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2233 | // We will detect more accurate range in the future. |
| 2234 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 2235 | } |
| 2236 | |
| 2237 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(const char *func_name) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2238 | bool skip = false; |
| 2239 | if (!current_renderpass_context_) return skip; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2240 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(GetExecutionContext(), *cb_state_.get(), func_name); |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2241 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2242 | } |
| 2243 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2244 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2245 | if (current_renderpass_context_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2246 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), tag); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2247 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2248 | } |
| 2249 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2250 | ResourceUsageTag CommandBufferAccessContext::RecordBeginRenderPass(CMD_TYPE cmd, const RENDER_PASS_STATE &rp_state, |
| 2251 | const VkRect2D &render_area, |
| 2252 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2253 | // Create an access context the current renderpass. |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2254 | const auto barrier_tag = NextCommandTag(cmd, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
| 2255 | const auto load_tag = NextSubcommandTag(cmd, ResourceUsageRecord::SubcommandType::kLoadOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2256 | 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] | 2257 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2258 | current_renderpass_context_->RecordBeginRenderPass(barrier_tag, load_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2259 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2260 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2261 | } |
| 2262 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2263 | ResourceUsageTag CommandBufferAccessContext::RecordNextSubpass(const CMD_TYPE cmd) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2264 | assert(current_renderpass_context_); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2265 | if (!current_renderpass_context_) return NextCommandTag(cmd); |
| 2266 | |
| 2267 | auto store_tag = NextCommandTag(cmd, ResourceUsageRecord::SubcommandType::kStoreOp); |
| 2268 | auto barrier_tag = NextSubcommandTag(cmd, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
| 2269 | auto load_tag = NextSubcommandTag(cmd, ResourceUsageRecord::SubcommandType::kLoadOp); |
| 2270 | |
| 2271 | current_renderpass_context_->RecordNextSubpass(store_tag, barrier_tag, load_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2272 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2273 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2274 | } |
| 2275 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2276 | ResourceUsageTag CommandBufferAccessContext::RecordEndRenderPass(const CMD_TYPE cmd) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2277 | assert(current_renderpass_context_); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2278 | if (!current_renderpass_context_) return NextCommandTag(cmd); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2279 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2280 | auto store_tag = NextCommandTag(cmd, ResourceUsageRecord::SubcommandType::kStoreOp); |
| 2281 | auto barrier_tag = NextSubcommandTag(cmd, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
| 2282 | |
| 2283 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, store_tag, barrier_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2284 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2285 | current_renderpass_context_ = nullptr; |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2286 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2287 | } |
| 2288 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2289 | void CommandBufferAccessContext::RecordDestroyEvent(VkEvent event) { |
| 2290 | // Erase is okay with the key not being |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 2291 | auto event_state = sync_state_->Get<EVENT_STATE>(event); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2292 | if (event_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 2293 | GetCurrentEventsContext()->Destroy(event_state.get()); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2294 | } |
| 2295 | } |
| 2296 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2297 | // The is the recorded cb context |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2298 | bool CommandBufferAccessContext::ValidateFirstUse(CommandExecutionContext *proxy_context, const char *func_name, |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2299 | uint32_t index) const { |
| 2300 | assert(proxy_context); |
| 2301 | auto *events_context = proxy_context->GetCurrentEventsContext(); |
| 2302 | auto *access_context = proxy_context->GetCurrentAccessContext(); |
| 2303 | const ResourceUsageTag base_tag = proxy_context->GetTagLimit(); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2304 | bool skip = false; |
| 2305 | ResourceUsageRange tag_range = {0, 0}; |
| 2306 | const AccessContext *recorded_context = GetCurrentAccessContext(); |
| 2307 | assert(recorded_context); |
| 2308 | HazardResult hazard; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2309 | 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] | 2310 | uint32_t index) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2311 | const auto handle = exec_context.Handle(); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2312 | const auto recorded_handle = cb_state_->commandBuffer(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2313 | const auto *report_data = sync_state_->report_data; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2314 | return sync_state_->LogError(handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2315 | "%s: Hazard %s for entry %" PRIu32 ", %s, Recorded access info %s. Access info %s.", func_name, |
| 2316 | string_SyncHazard(hazard.hazard), index, report_data->FormatHandle(recorded_handle).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2317 | FormatUsage(*hazard.recorded_access).c_str(), exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2318 | }; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2319 | const ReplayTrackbackBarriersAction *replay_context = nullptr; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2320 | for (const auto &sync_op : sync_ops_) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2321 | // we update the range to any include layout transition first use writes, |
| 2322 | // as they are stored along with the source scope (as effective barrier) when recorded |
| 2323 | tag_range.end = sync_op.tag + 1; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 2324 | skip |= sync_op.sync_op->ReplayValidate(sync_op.tag, *this, base_tag, proxy_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2325 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2326 | hazard = recorded_context->DetectFirstUseHazard(tag_range, *access_context, replay_context); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2327 | if (hazard.hazard) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2328 | skip |= log_msg(hazard, *proxy_context, func_name, index); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2329 | } |
| 2330 | // 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] | 2331 | // Record the barrier into the proxy context. |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2332 | sync_op.sync_op->ReplayRecord(base_tag + sync_op.tag, access_context, events_context); |
| 2333 | replay_context = sync_op.sync_op->GetReplayTrackback(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2334 | tag_range.begin = tag_range.end; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2335 | } |
| 2336 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2337 | // Renderpasses may not cross command buffer boundaries |
| 2338 | assert(replay_context == nullptr); |
| 2339 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2340 | // and anything after the last syncop |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2341 | tag_range.end = ResourceUsageRecord::kMaxIndex; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2342 | hazard = recorded_context->DetectFirstUseHazard(tag_range, *access_context, replay_context); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2343 | if (hazard.hazard) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2344 | skip |= log_msg(hazard, *proxy_context, func_name, index); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | return skip; |
| 2348 | } |
| 2349 | |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2350 | void CommandExecutionContext::RecordExecutedCommandBuffer(const CommandBufferAccessContext &recorded_cb_context, CMD_TYPE cmd) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2351 | auto *events_context = GetCurrentEventsContext(); |
| 2352 | auto *access_context = GetCurrentAccessContext(); |
| 2353 | const AccessContext *recorded_context = recorded_cb_context.GetCurrentAccessContext(); |
| 2354 | assert(recorded_context); |
| 2355 | |
| 2356 | // Just run through the barriers ignoring the usage from the recorded context, as Resolve will overwrite outdated state |
| 2357 | const ResourceUsageTag base_tag = GetTagLimit(); |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2358 | for (const auto &sync_op : recorded_cb_context.GetSyncOps()) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2359 | // we update the range to any include layout transition first use writes, |
| 2360 | // as they are stored along with the source scope (as effective barrier) when recorded |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2361 | sync_op.sync_op->ReplayRecord(base_tag + sync_op.tag, access_context, events_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | ResourceUsageRange tag_range = ImportRecordedAccessLog(recorded_cb_context); |
| 2365 | assert(base_tag == tag_range.begin); // to ensure the to offset calculation agree |
| 2366 | ResolveRecordedContext(*recorded_context, tag_range.begin); |
| 2367 | } |
| 2368 | |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2369 | void CommandExecutionContext::ResolveRecordedContext(const AccessContext &recorded_context, ResourceUsageTag offset) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2370 | auto tag_offset = [offset](ResourceAccessState *access) { access->OffsetTag(offset); }; |
| 2371 | |
| 2372 | auto *access_context = GetCurrentAccessContext(); |
| 2373 | for (auto address_type : kAddressTypes) { |
| 2374 | recorded_context.ResolveAccessRange(address_type, kFullRange, tag_offset, &access_context->GetAccessStateMap(address_type), |
| 2375 | nullptr, false); |
| 2376 | } |
| 2377 | } |
| 2378 | |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2379 | ResourceUsageRange CommandExecutionContext::ImportRecordedAccessLog(const CommandBufferAccessContext &recorded_context) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2380 | // The execution references ensure lifespan for the referenced child CB's... |
| 2381 | ResourceUsageRange tag_range(GetTagLimit(), 0); |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2382 | InsertRecordedAccessLogEntries(recorded_context); |
| 2383 | tag_range.end = GetTagLimit(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2384 | return tag_range; |
| 2385 | } |
| 2386 | |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2387 | void CommandBufferAccessContext::InsertRecordedAccessLogEntries(const CommandBufferAccessContext &recorded_context) { |
| 2388 | cbs_referenced_.emplace(recorded_context.GetCBStateShared()); |
| 2389 | access_log_.insert(access_log_.end(), recorded_context.access_log_.cbegin(), recorded_context.access_log_.end()); |
| 2390 | } |
| 2391 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2392 | ResourceUsageTag CommandBufferAccessContext::NextSubcommandTag(CMD_TYPE command, ResourceUsageRecord::SubcommandType subcommand) { |
| 2393 | ResourceUsageTag next = access_log_.size(); |
| 2394 | access_log_.emplace_back(command, command_number_, subcommand, ++subcommand_number_, cb_state_.get(), reset_count_); |
| 2395 | return next; |
| 2396 | } |
| 2397 | |
| 2398 | ResourceUsageTag CommandBufferAccessContext::NextCommandTag(CMD_TYPE command, ResourceUsageRecord::SubcommandType subcommand) { |
| 2399 | command_number_++; |
| 2400 | subcommand_number_ = 0; |
| 2401 | ResourceUsageTag next = access_log_.size(); |
| 2402 | access_log_.emplace_back(command, command_number_, subcommand, subcommand_number_, cb_state_.get(), reset_count_); |
| 2403 | return next; |
| 2404 | } |
| 2405 | |
| 2406 | ResourceUsageTag CommandBufferAccessContext::NextIndexedCommandTag(CMD_TYPE command, uint32_t index) { |
| 2407 | if (index == 0) { |
| 2408 | return NextCommandTag(command, ResourceUsageRecord::SubcommandType::kIndex); |
| 2409 | } |
| 2410 | return NextSubcommandTag(command, ResourceUsageRecord::SubcommandType::kIndex); |
| 2411 | } |
| 2412 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2413 | void CommandBufferAccessContext::RecordSyncOp(SyncOpPointer &&sync_op) { |
| 2414 | auto tag = sync_op->Record(this); |
| 2415 | // As renderpass operations can have side effects on the command buffer access context, |
| 2416 | // update the sync operation to record these if any. |
| 2417 | if (current_renderpass_context_) { |
| 2418 | const auto &rpc = *current_renderpass_context_; |
| 2419 | sync_op->SetReplayContext(rpc.GetCurrentSubpass(), rpc.GetReplayContext()); |
| 2420 | } |
| 2421 | sync_ops_.emplace_back(tag, std::move(sync_op)); |
| 2422 | } |
| 2423 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2424 | class HazardDetectFirstUse { |
| 2425 | public: |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2426 | HazardDetectFirstUse(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range, |
| 2427 | const ReplayTrackbackBarriersAction *replay_barrier) |
| 2428 | : recorded_use_(recorded_use), tag_range_(tag_range), replay_barrier_(replay_barrier) {} |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2429 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2430 | if (replay_barrier_) { |
| 2431 | // Intentional copy to apply the replay barrier |
| 2432 | auto access = pos->second; |
| 2433 | (*replay_barrier_)(&access); |
| 2434 | return access.DetectHazard(recorded_use_, tag_range_); |
| 2435 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2436 | return pos->second.DetectHazard(recorded_use_, tag_range_); |
| 2437 | } |
| 2438 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
| 2439 | return pos->second.DetectAsyncHazard(recorded_use_, tag_range_, start_tag); |
| 2440 | } |
| 2441 | |
| 2442 | private: |
| 2443 | const ResourceAccessState &recorded_use_; |
| 2444 | const ResourceUsageRange &tag_range_; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2445 | const ReplayTrackbackBarriersAction *replay_barrier_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2446 | }; |
| 2447 | |
| 2448 | // This is called with the *recorded* command buffers access context, with the *active* access context pass in, againsts which |
| 2449 | // hazards will be detected |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2450 | HazardResult AccessContext::DetectFirstUseHazard(const ResourceUsageRange &tag_range, const AccessContext &access_context, |
| 2451 | const ReplayTrackbackBarriersAction *replay_barrier) const { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2452 | HazardResult hazard; |
| 2453 | for (const auto address_type : kAddressTypes) { |
| 2454 | const auto &recorded_access_map = GetAccessStateMap(address_type); |
| 2455 | for (const auto &recorded_access : recorded_access_map) { |
| 2456 | // Cull any entries not in the current tag range |
| 2457 | if (!recorded_access.second.FirstAccessInTagRange(tag_range)) continue; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2458 | HazardDetectFirstUse detector(recorded_access.second, tag_range, replay_barrier); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2459 | hazard = access_context.DetectHazard(address_type, detector, recorded_access.first, DetectOptions::kDetectAll); |
| 2460 | if (hazard.hazard) break; |
| 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | return hazard; |
| 2465 | } |
| 2466 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2467 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const CommandExecutionContext &exec_context, |
| 2468 | const CMD_BUFFER_STATE &cmd, const char *func_name) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2469 | bool skip = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2470 | const auto &sync_state = exec_context.GetSyncState(); |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2471 | const auto *pipe = cmd.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2472 | if (!pipe) { |
| 2473 | return skip; |
| 2474 | } |
| 2475 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2476 | const auto raster_state = pipe->RasterizationState(); |
| 2477 | if (raster_state && raster_state->rasterizerDiscardEnable) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2478 | return skip; |
| 2479 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2480 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2481 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2482 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2483 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2484 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2485 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2486 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2487 | if (location >= subpass.colorAttachmentCount || |
| 2488 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2489 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2490 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2491 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2492 | if (!view_gen.IsValid()) continue; |
| 2493 | HazardResult hazard = |
| 2494 | current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2495 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2496 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2497 | const VkImageView view_handle = view_gen.GetViewState()->image_view(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2498 | skip |= sync_state.LogError(view_handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2499 | "%s: Hazard %s for %s in %s, Subpass #%d, and pColorAttachments #%d. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2500 | func_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2501 | sync_state.report_data->FormatHandle(view_handle).c_str(), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2502 | sync_state.report_data->FormatHandle(cmd.commandBuffer()).c_str(), cmd.activeSubpass, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2503 | location, exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2504 | } |
| 2505 | } |
| 2506 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2507 | |
| 2508 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2509 | // 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] | 2510 | const auto ds_state = pipe->DepthStencilState(); |
| 2511 | const uint32_t depth_stencil_attachment = GetSubpassDepthStencilAttachmentIndex(ds_state, subpass.pDepthStencilAttachment); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2512 | |
| 2513 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2514 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2515 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2516 | bool depth_write = false, stencil_write = false; |
| 2517 | |
| 2518 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2519 | 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] | 2520 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2521 | depth_write = true; |
| 2522 | } |
| 2523 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2524 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2525 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2526 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2527 | if (!FormatIsDepthOnly(view_state.create_info.format) && ds_state->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2528 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2529 | stencil_write = true; |
| 2530 | } |
| 2531 | |
| 2532 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2533 | if (depth_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2534 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2535 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2536 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2537 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2538 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2539 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2540 | "%s: Hazard %s for %s in %s, Subpass #%d, and depth part of pDepthStencilAttachment. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2541 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2542 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
| 2543 | sync_state.report_data->FormatHandle(cmd.commandBuffer()).c_str(), cmd.activeSubpass, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2544 | exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2545 | } |
| 2546 | } |
| 2547 | if (stencil_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2548 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2549 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2550 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2551 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2552 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2553 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2554 | "%s: Hazard %s for %s in %s, Subpass #%d, and stencil part of pDepthStencilAttachment. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2555 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2556 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
| 2557 | sync_state.report_data->FormatHandle(cmd.commandBuffer()).c_str(), cmd.activeSubpass, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2558 | exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2559 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | return skip; |
| 2563 | } |
| 2564 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2565 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd, const ResourceUsageTag tag) { |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2566 | const auto *pipe = cmd.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2567 | if (!pipe) { |
| 2568 | return; |
| 2569 | } |
| 2570 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2571 | const auto *raster_state = pipe->RasterizationState(); |
| 2572 | if (raster_state && raster_state->rasterizerDiscardEnable) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2573 | return; |
| 2574 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2575 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2576 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2577 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2578 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2579 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2580 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2581 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2582 | if (location >= subpass.colorAttachmentCount || |
| 2583 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2584 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2585 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2586 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2587 | current_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2588 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment, |
| 2589 | tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2590 | } |
| 2591 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2592 | |
| 2593 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2594 | // 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] | 2595 | const auto *ds_state = pipe->DepthStencilState(); |
| 2596 | const uint32_t depth_stencil_attachment = GetSubpassDepthStencilAttachmentIndex(ds_state, subpass.pDepthStencilAttachment); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2597 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2598 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2599 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2600 | bool depth_write = false, stencil_write = false; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2601 | const bool has_depth = 0 != (view_state.normalized_subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 2602 | 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] | 2603 | |
| 2604 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2605 | if (has_depth && !FormatIsStencilOnly(view_state.create_info.format) && ds_state->depthTestEnable && |
| 2606 | ds_state->depthWriteEnable && IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2607 | depth_write = true; |
| 2608 | } |
| 2609 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2610 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2611 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2612 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2613 | if (has_stencil && !FormatIsDepthOnly(view_state.create_info.format) && ds_state->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2614 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2615 | stencil_write = true; |
| 2616 | } |
| 2617 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2618 | if (depth_write || stencil_write) { |
| 2619 | const auto ds_gentype = view_gen.GetDepthStencilRenderAreaGenType(depth_write, stencil_write); |
| 2620 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2621 | current_context.UpdateAccessState(view_gen, ds_gentype, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2622 | SyncOrdering::kDepthStencilAttachment, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2623 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2624 | } |
| 2625 | } |
| 2626 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2627 | bool RenderPassAccessContext::ValidateNextSubpass(const CommandExecutionContext &exec_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2628 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2629 | bool skip = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2630 | skip |= CurrentContext().ValidateResolveOperations(exec_context, *rp_state_, render_area_, attachment_views_, func_name, |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2631 | current_subpass_); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2632 | skip |= CurrentContext().ValidateStoreOperation(exec_context, *rp_state_, render_area_, current_subpass_, attachment_views_, |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2633 | func_name); |
| 2634 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2635 | const auto next_subpass = current_subpass_ + 1; |
ziga-lunarg | 31a3e77 | 2022-03-22 11:48:46 +0100 | [diff] [blame] | 2636 | if (next_subpass >= subpass_contexts_.size()) { |
| 2637 | return skip; |
| 2638 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2639 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2640 | skip |= |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2641 | next_context.ValidateLayoutTransitions(exec_context, *rp_state_, render_area_, next_subpass, attachment_views_, func_name); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2642 | if (!skip) { |
| 2643 | // To avoid complex (and buggy) duplication of the affect of layout transitions on load operations, we'll record them |
| 2644 | // on a copy of the (empty) next context. |
| 2645 | // Note: The resource access map should be empty so hopefully this copy isn't too horrible from a perf POV. |
| 2646 | AccessContext temp_context(next_context); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2647 | temp_context.RecordLayoutTransitions(*rp_state_, next_subpass, attachment_views_, kInvalidTag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2648 | skip |= |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2649 | temp_context.ValidateLoadOperation(exec_context, *rp_state_, render_area_, next_subpass, attachment_views_, func_name); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2650 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2651 | return skip; |
| 2652 | } |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2653 | bool RenderPassAccessContext::ValidateEndRenderPass(const CommandExecutionContext &exec_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2654 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2655 | bool skip = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2656 | skip |= CurrentContext().ValidateResolveOperations(exec_context, *rp_state_, render_area_, attachment_views_, func_name, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2657 | current_subpass_); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2658 | skip |= CurrentContext().ValidateStoreOperation(exec_context, *rp_state_, render_area_, current_subpass_, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2659 | |
| 2660 | attachment_views_, func_name); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2661 | skip |= ValidateFinalSubpassLayoutTransitions(exec_context, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2662 | return skip; |
| 2663 | } |
| 2664 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2665 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy() const { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2666 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, attachment_views_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2667 | } |
| 2668 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2669 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const CommandExecutionContext &exec_context, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2670 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2671 | bool skip = false; |
| 2672 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2673 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2674 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2675 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2676 | // to apply and only copy then, if this proves a hot spot. |
| 2677 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2678 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2679 | // Validate the "finalLayout" transitions to external |
| 2680 | // Get them from where there we're hidding in the extra entry. |
| 2681 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2682 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2683 | const auto &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2684 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2685 | assert(trackback.source_subpass); // Transitions are given implicit transitions if the StateTracker is working correctly |
| 2686 | auto *context = trackback.source_subpass; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2687 | |
| 2688 | if (transition.prev_pass == current_subpass_) { |
| 2689 | if (!proxy_for_current) { |
| 2690 | // 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] | 2691 | proxy_for_current.reset(CreateStoreResolveProxy()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2692 | } |
| 2693 | context = proxy_for_current.get(); |
| 2694 | } |
| 2695 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2696 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2697 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2698 | auto hazard = context->DetectImageBarrierHazard(view_gen, merged_barrier, AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2699 | if (hazard.hazard) { |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2700 | if (hazard.tag == kInvalidTag) { |
| 2701 | // Hazard vs. ILT |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2702 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2703 | rp_state_->renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 2704 | "%s: Hazard %s vs. store/resolve operations in subpass %" PRIu32 " for attachment %" PRIu32 |
| 2705 | " final image layout transition (old_layout: %s, new_layout: %s).", |
| 2706 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2707 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout)); |
| 2708 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2709 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2710 | rp_state_->renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 2711 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
| 2712 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 2713 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2714 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2715 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2716 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2717 | } |
| 2718 | } |
| 2719 | return skip; |
| 2720 | } |
| 2721 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2722 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2723 | // Add layout transitions... |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2724 | subpass_contexts_[current_subpass_].RecordLayoutTransitions(*rp_state_, current_subpass_, attachment_views_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2725 | } |
| 2726 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2727 | void RenderPassAccessContext::RecordLoadOperations(const ResourceUsageTag tag) { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2728 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2729 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2730 | |
| 2731 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2732 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2733 | const AttachmentViewGen &view_gen = attachment_views_[i]; |
| 2734 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2735 | |
| 2736 | const auto &ci = attachment_ci[i]; |
| 2737 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2738 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2739 | const bool is_color = !(has_depth || has_stencil); |
| 2740 | |
| 2741 | if (is_color) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2742 | const SyncStageAccessIndex load_op = ColorLoadUsage(ci.loadOp); |
| 2743 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2744 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, load_op, |
| 2745 | SyncOrdering::kColorAttachment, tag); |
| 2746 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2747 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2748 | if (has_depth) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2749 | const SyncStageAccessIndex load_op = DepthStencilLoadUsage(ci.loadOp); |
| 2750 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2751 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_op, |
| 2752 | SyncOrdering::kDepthStencilAttachment, tag); |
| 2753 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2754 | } |
| 2755 | if (has_stencil) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2756 | const SyncStageAccessIndex load_op = DepthStencilLoadUsage(ci.stencilLoadOp); |
| 2757 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2758 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, load_op, |
| 2759 | SyncOrdering::kDepthStencilAttachment, tag); |
| 2760 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2761 | } |
| 2762 | } |
| 2763 | } |
| 2764 | } |
| 2765 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2766 | AttachmentViewGenVector RenderPassAccessContext::CreateAttachmentViewGen( |
| 2767 | const VkRect2D &render_area, const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
| 2768 | AttachmentViewGenVector view_gens; |
| 2769 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2770 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2771 | view_gens.reserve(attachment_views.size()); |
| 2772 | for (const auto *view : attachment_views) { |
| 2773 | view_gens.emplace_back(view, offset, extent); |
| 2774 | } |
| 2775 | return view_gens; |
| 2776 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2777 | RenderPassAccessContext::RenderPassAccessContext(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2778 | VkQueueFlags queue_flags, |
| 2779 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2780 | const AccessContext *external_context) |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2781 | : rp_state_(&rp_state), render_area_(render_area), current_subpass_(0U), attachment_views_() { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2782 | // Add this for all subpasses here so that they exsist during next subpass validation |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2783 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2784 | replay_context_ = std::make_shared<ReplayRenderpassContext>(); |
| 2785 | auto &replay_subpass_contexts = replay_context_->subpass_contexts; |
| 2786 | replay_subpass_contexts.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2787 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2788 | subpass_contexts_.emplace_back(pass, queue_flags, rp_state_->subpass_dependencies, subpass_contexts_, external_context); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2789 | replay_subpass_contexts.emplace_back(queue_flags, rp_state_->subpass_dependencies[pass], replay_subpass_contexts); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2790 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2791 | attachment_views_ = CreateAttachmentViewGen(render_area, attachment_views); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2792 | } |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2793 | void RenderPassAccessContext::RecordBeginRenderPass(const ResourceUsageTag barrier_tag, const ResourceUsageTag load_tag) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2794 | assert(0 == current_subpass_); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2795 | subpass_contexts_[current_subpass_].SetStartTag(barrier_tag); |
| 2796 | RecordLayoutTransitions(barrier_tag); |
| 2797 | RecordLoadOperations(load_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2798 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2799 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2800 | void RenderPassAccessContext::RecordNextSubpass(const ResourceUsageTag store_tag, const ResourceUsageTag barrier_tag, |
| 2801 | const ResourceUsageTag load_tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2802 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2803 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
| 2804 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2805 | |
ziga-lunarg | 31a3e77 | 2022-03-22 11:48:46 +0100 | [diff] [blame] | 2806 | if (current_subpass_ + 1 >= subpass_contexts_.size()) { |
| 2807 | return; |
| 2808 | } |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 2809 | // Move to the next sub-command for the new subpass. The resolve and store are logically part of the previous |
| 2810 | // 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] | 2811 | current_subpass_++; |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2812 | subpass_contexts_[current_subpass_].SetStartTag(barrier_tag); |
| 2813 | RecordLayoutTransitions(barrier_tag); |
| 2814 | RecordLoadOperations(load_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2815 | } |
| 2816 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2817 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const ResourceUsageTag store_tag, |
| 2818 | const ResourceUsageTag barrier_tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2819 | // Add the resolve and store accesses |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2820 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
| 2821 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2822 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2823 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2824 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2825 | |
| 2826 | // Add the "finalLayout" transitions to external |
| 2827 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2828 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2829 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2830 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2831 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2832 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2833 | const AttachmentViewGen &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2834 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2835 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.source_subpass); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2836 | ApplyBarrierOpsFunctor<PipelineBarrierOp> barrier_action(true /* resolve */, last_trackback.barriers.size(), barrier_tag); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2837 | for (const auto &barrier : last_trackback.barriers) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2838 | barrier_action.EmplaceBack(PipelineBarrierOp(barrier, true)); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2839 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2840 | external_context->ApplyUpdateAction(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2841 | } |
| 2842 | } |
| 2843 | |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2844 | SyncExecScope SyncExecScope::MakeSrc(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param, |
| 2845 | const VkPipelineStageFlags2KHR disabled_feature_mask) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2846 | SyncExecScope result; |
| 2847 | result.mask_param = mask_param; |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2848 | 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] | 2849 | result.exec_scope = sync_utils::WithEarlierPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2850 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2851 | return result; |
| 2852 | } |
| 2853 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2854 | SyncExecScope SyncExecScope::MakeDst(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2855 | SyncExecScope result; |
| 2856 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2857 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2858 | result.exec_scope = sync_utils::WithLaterPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2859 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2860 | return result; |
| 2861 | } |
| 2862 | |
| 2863 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2864 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2865 | src_access_scope = 0; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2866 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2867 | dst_access_scope = 0; |
| 2868 | } |
| 2869 | |
| 2870 | template <typename Barrier> |
| 2871 | SyncBarrier::SyncBarrier(const Barrier &barrier, const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2872 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2873 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2874 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2875 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
| 2876 | } |
| 2877 | |
| 2878 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &subpass) { |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2879 | const auto barrier = lvl_find_in_chain<VkMemoryBarrier2KHR>(subpass.pNext); |
| 2880 | if (barrier) { |
| 2881 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier->srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2882 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2883 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier->srcAccessMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2884 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2885 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier->dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2886 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2887 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier->dstAccessMask); |
| 2888 | |
| 2889 | } else { |
| 2890 | auto src = SyncExecScope::MakeSrc(queue_flags, subpass.srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2891 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2892 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, subpass.srcAccessMask); |
| 2893 | |
| 2894 | auto dst = SyncExecScope::MakeDst(queue_flags, subpass.dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2895 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2896 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, subpass.dstAccessMask); |
| 2897 | } |
| 2898 | } |
| 2899 | |
| 2900 | template <typename Barrier> |
| 2901 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const Barrier &barrier) { |
| 2902 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 2903 | src_exec_scope = src.exec_scope; |
| 2904 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
| 2905 | |
| 2906 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2907 | dst_exec_scope = dst.exec_scope; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2908 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2909 | } |
| 2910 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2911 | // Apply a list of barriers, without resolving pending state, useful for subpass layout transitions |
| 2912 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
| 2913 | for (const auto &barrier : barriers) { |
| 2914 | ApplyBarrier(barrier, layout_transition); |
| 2915 | } |
| 2916 | } |
| 2917 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2918 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2919 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2920 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2921 | void ResourceAccessState::ApplyBarriersImmediate(const std::vector<SyncBarrier> &barriers) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2922 | 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] | 2923 | assert(pending_write_barriers.none()); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2924 | assert(!pending_write_dep_chain); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2925 | for (const auto &barrier : barriers) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2926 | ApplyBarrier(barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2927 | } |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2928 | ApplyPendingBarriers(kInvalidTag); // There can't be any need for this tag |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2929 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2930 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2931 | HazardResult hazard; |
| 2932 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2933 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2934 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2935 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2936 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2937 | } |
| 2938 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2939 | // Write operation: |
| 2940 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2941 | // If reads exists -- test only against them because either: |
| 2942 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2943 | // * 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 |
| 2944 | // the current write happens after the reads, so just test the write against the reades |
| 2945 | // Otherwise test against last_write |
| 2946 | // |
| 2947 | // Look for casus belli for WAR |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2948 | if (last_reads.size()) { |
| 2949 | for (const auto &read_access : last_reads) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2950 | if (IsReadHazard(usage_stage, read_access)) { |
| 2951 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2952 | break; |
| 2953 | } |
| 2954 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2955 | } else if (last_write.any() && IsWriteHazard(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2956 | // Write-After-Write check -- if we have a previous write to test against |
| 2957 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2958 | } |
| 2959 | } |
| 2960 | return hazard; |
| 2961 | } |
| 2962 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2963 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrdering ordering_rule) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2964 | const auto &ordering = GetOrderingRules(ordering_rule); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2965 | return DetectHazard(usage_index, ordering); |
| 2966 | } |
| 2967 | |
| 2968 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const OrderingBarrier &ordering) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2969 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 2970 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2971 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2972 | const auto usage_stage = PipelineStageBit(usage_index); |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2973 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
| 2974 | const bool last_write_is_ordered = (last_write & ordering.access_scope).any(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2975 | if (IsRead(usage_bit)) { |
| 2976 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 2977 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 2978 | if (is_raw_hazard) { |
| 2979 | // NOTE: we know last_write is non-zero |
| 2980 | // See if the ordering rules save us from the simple RAW check above |
| 2981 | // First check to see if the current usage is covered by the ordering rules |
| 2982 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 2983 | const bool usage_is_ordered = |
| 2984 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 2985 | if (usage_is_ordered) { |
| 2986 | // Now see of the most recent write (or a subsequent read) are ordered |
| 2987 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(ordering)); |
| 2988 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2989 | } |
| 2990 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2991 | if (is_raw_hazard) { |
| 2992 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 2993 | } |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 2994 | } else if (usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION) { |
| 2995 | // For Image layout transitions, the barrier represents the first synchronization/access scope of the layout transition |
| 2996 | return DetectBarrierHazard(usage_index, ordering.exec_scope, ordering.access_scope); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2997 | } else { |
| 2998 | // Only check for WAW if there are no reads since last_write |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2999 | bool usage_write_is_ordered = (usage_bit & ordering.access_scope).any(); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3000 | if (last_reads.size()) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3001 | // Look for any WAR hazards outside the ordered set of stages |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3002 | VkPipelineStageFlags2KHR ordered_stages = 0; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3003 | if (usage_write_is_ordered) { |
| 3004 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
| 3005 | ordered_stages = GetOrderedStages(ordering); |
| 3006 | } |
| 3007 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 3008 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3009 | for (const auto &read_access : last_reads) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3010 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 3011 | if (IsReadHazard(usage_stage, read_access)) { |
| 3012 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3013 | break; |
| 3014 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3015 | } |
| 3016 | } |
John Zulauf | 2a344ca | 2021-09-09 17:07:19 -0600 | [diff] [blame] | 3017 | } else if (last_write.any() && !(last_write_is_ordered && usage_write_is_ordered)) { |
| 3018 | bool ilt_ilt_hazard = false; |
| 3019 | if ((usage_index == SYNC_IMAGE_LAYOUT_TRANSITION) && (usage_bit == last_write)) { |
| 3020 | // ILT after ILT is a special case where we check the 2nd access scope of the first ILT against the first access |
| 3021 | // scope of the second ILT, which has been passed (smuggled?) in the ordering barrier |
| 3022 | ilt_ilt_hazard = !(write_barriers & ordering.access_scope).any(); |
| 3023 | } |
| 3024 | if (ilt_ilt_hazard || IsWriteHazard(usage_bit)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3025 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3026 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 3027 | } |
| 3028 | } |
| 3029 | return hazard; |
| 3030 | } |
| 3031 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3032 | HazardResult ResourceAccessState::DetectHazard(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range) const { |
| 3033 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3034 | using Size = FirstAccesses::size_type; |
| 3035 | const auto &recorded_accesses = recorded_use.first_accesses_; |
| 3036 | Size count = recorded_accesses.size(); |
| 3037 | if (count) { |
| 3038 | const auto &last_access = recorded_accesses.back(); |
| 3039 | bool do_write_last = IsWrite(last_access.usage_index); |
| 3040 | if (do_write_last) --count; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3041 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3042 | for (Size i = 0; i < count; ++count) { |
| 3043 | const auto &first = recorded_accesses[i]; |
| 3044 | // Skip and quit logic |
| 3045 | if (first.tag < tag_range.begin) continue; |
| 3046 | if (first.tag >= tag_range.end) { |
| 3047 | do_write_last = false; // ignore last since we know it can't be in tag_range |
| 3048 | break; |
| 3049 | } |
| 3050 | |
| 3051 | hazard = DetectHazard(first.usage_index, first.ordering_rule); |
| 3052 | if (hazard.hazard) { |
| 3053 | hazard.AddRecordedAccess(first); |
| 3054 | break; |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | if (do_write_last && tag_range.includes(last_access.tag)) { |
| 3059 | // Writes are a bit special... both for the "most recent" access logic, and layout transition specific logic |
| 3060 | OrderingBarrier barrier = GetOrderingRules(last_access.ordering_rule); |
| 3061 | if (last_access.usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION) { |
| 3062 | // Or in the layout first access scope as a barrier... IFF the usage is an ILT |
| 3063 | // this was saved off in the "apply barriers" logic to simplify ILT access checks as they straddle |
| 3064 | // the barrier that applies them |
| 3065 | barrier |= recorded_use.first_write_layout_ordering_; |
| 3066 | } |
| 3067 | // Any read stages present in the recorded context (this) are most recent to the write, and thus mask those stages in |
| 3068 | // the active context |
| 3069 | if (recorded_use.first_read_stages_) { |
| 3070 | // we need to ignore the first use read stage in the active context (so we add them to the ordering rule), |
| 3071 | // reads in the active context are not "most recent" as all recorded context operations are *after* them |
| 3072 | // This supresses only RAW checks for stages present in the recorded context, but not those only present in the |
| 3073 | // active context. |
| 3074 | barrier.exec_scope |= recorded_use.first_read_stages_; |
| 3075 | // if there are any first use reads, we suppress WAW by injecting the active context write in the ordering rule |
| 3076 | barrier.access_scope |= FlagBit(last_access.usage_index); |
| 3077 | } |
| 3078 | hazard = DetectHazard(last_access.usage_index, barrier); |
| 3079 | if (hazard.hazard) { |
| 3080 | hazard.AddRecordedAccess(last_access); |
| 3081 | } |
| 3082 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3083 | } |
| 3084 | return hazard; |
| 3085 | } |
| 3086 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3087 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3088 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index, const ResourceUsageTag start_tag) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3089 | HazardResult hazard; |
| 3090 | auto usage = FlagBit(usage_index); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 3091 | // Async checks need to not go back further than the start of the subpass, as we only want to find hazards between the async |
| 3092 | // subpasses. Anything older than that should have been checked at the start of each subpass, taking into account all of |
| 3093 | // the raster ordering rules. |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3094 | if (IsRead(usage)) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3095 | if (last_write.any() && (write_tag >= start_tag)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3096 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3097 | } |
| 3098 | } else { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3099 | if (last_write.any() && (write_tag >= start_tag)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3100 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3101 | } else if (last_reads.size() > 0) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 3102 | // 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] | 3103 | for (const auto &read_access : last_reads) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3104 | if (read_access.tag >= start_tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3105 | 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] | 3106 | break; |
| 3107 | } |
| 3108 | } |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3109 | } |
| 3110 | } |
| 3111 | return hazard; |
| 3112 | } |
| 3113 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3114 | HazardResult ResourceAccessState::DetectAsyncHazard(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range, |
| 3115 | ResourceUsageTag start_tag) const { |
| 3116 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3117 | for (const auto &first : recorded_use.first_accesses_) { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3118 | // Skip and quit logic |
| 3119 | if (first.tag < tag_range.begin) continue; |
| 3120 | if (first.tag >= tag_range.end) break; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3121 | |
| 3122 | hazard = DetectAsyncHazard(first.usage_index, start_tag); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3123 | if (hazard.hazard) { |
| 3124 | hazard.AddRecordedAccess(first); |
| 3125 | break; |
| 3126 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3127 | } |
| 3128 | return hazard; |
| 3129 | } |
| 3130 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3131 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3132 | const SyncStageAccessFlags &src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3133 | // Only supporting image layout transitions for now |
| 3134 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 3135 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3136 | // only test for WAW if there no intervening read operations. |
| 3137 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3138 | if (last_reads.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3139 | // Look at the reads if any |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3140 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3141 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3142 | 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] | 3143 | break; |
| 3144 | } |
| 3145 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3146 | } else if (last_write.any() && IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 3147 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3148 | } |
| 3149 | |
| 3150 | return hazard; |
| 3151 | } |
| 3152 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3153 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3154 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3155 | const ResourceUsageTag event_tag) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3156 | // Only supporting image layout transitions for now |
| 3157 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 3158 | HazardResult hazard; |
| 3159 | // only test for WAW if there no intervening read operations. |
| 3160 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 3161 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3162 | if (last_reads.size()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3163 | // Look at the reads if any... if reads exist, they are either the resaon the access is in the event |
| 3164 | // first scope, or they are a hazard. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3165 | for (const auto &read_access : last_reads) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3166 | if (read_access.tag < event_tag) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3167 | // The read is in the events first synchronization scope, so we use a barrier hazard check |
| 3168 | // If the read stage is not in the src sync scope |
| 3169 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 3170 | // then the barrier access is unsafe (R/W after R) |
| 3171 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
| 3172 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3173 | break; |
| 3174 | } |
| 3175 | } else { |
| 3176 | // The read not in the event first sync scope and so is a hazard vs. the layout transition |
| 3177 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3178 | } |
| 3179 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3180 | } else if (last_write.any()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3181 | // if there are no reads, the write is either the reason the access is in the event scope... they are a hazard |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3182 | if (write_tag < event_tag) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3183 | // The write is in the first sync scope of the event (sync their aren't any reads to be the reason) |
| 3184 | // So do a normal barrier hazard check |
| 3185 | if (IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 3186 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3187 | } |
| 3188 | } else { |
| 3189 | // The write isn't in scope, and is thus a hazard to the layout transistion for wait |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3190 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3191 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3192 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3193 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3194 | return hazard; |
| 3195 | } |
| 3196 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3197 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 3198 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 3199 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 3200 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3201 | if (write_tag < other.write_tag) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3202 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 3203 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3204 | *this = other; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3205 | } else if (other.write_tag == write_tag) { |
| 3206 | // 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] | 3207 | // dependency chaining logic or any stage expansion) |
| 3208 | write_barriers |= other.write_barriers; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3209 | pending_write_barriers |= other.pending_write_barriers; |
| 3210 | pending_layout_transition |= other.pending_layout_transition; |
| 3211 | pending_write_dep_chain |= other.pending_write_dep_chain; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3212 | pending_layout_ordering_ |= other.pending_layout_ordering_; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3213 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3214 | // Merge the read states |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3215 | const auto pre_merge_count = last_reads.size(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3216 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3217 | 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] | 3218 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3219 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3220 | // 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] | 3221 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 3222 | // but we should wait on profiling data for that. |
| 3223 | 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] | 3224 | auto &my_read = last_reads[my_read_index]; |
| 3225 | if (other_read.stage == my_read.stage) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3226 | if (my_read.tag < other_read.tag) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3227 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3228 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3229 | my_read.tag = other_read.tag; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3230 | my_read.pending_dep_chain = other_read.pending_dep_chain; |
| 3231 | // TODO: Phase 2 -- review the state merge logic to avoid false positive from overwriting the barriers |
| 3232 | // May require tracking more than one access per stage. |
| 3233 | my_read.barriers = other_read.barriers; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3234 | if (my_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3235 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 3236 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3237 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3238 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3239 | } else if (other_read.tag == my_read.tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3240 | // The read tags match so merge the barriers |
| 3241 | my_read.barriers |= other_read.barriers; |
| 3242 | my_read.pending_dep_chain |= other_read.pending_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3243 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3244 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3245 | break; |
| 3246 | } |
| 3247 | } |
| 3248 | } else { |
| 3249 | // The other read stage doesn't exist in this, so add it. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3250 | last_reads.emplace_back(other_read); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3251 | last_read_stages |= other_read.stage; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3252 | if (other_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3253 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3254 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3255 | } |
| 3256 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3257 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3258 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 3259 | // ignore it. |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3260 | |
| 3261 | // Merge first access information by making a copy of this first_access and reconstructing with a shuffle |
| 3262 | // of the copy and other into this using the update first logic. |
| 3263 | // NOTE: All sorts of additional cleverness could be put into short circuts. (for example back is write and is before front |
| 3264 | // of the other first_accesses... ) |
| 3265 | if (!(first_accesses_ == other.first_accesses_) && !other.first_accesses_.empty()) { |
| 3266 | FirstAccesses firsts(std::move(first_accesses_)); |
| 3267 | first_accesses_.clear(); |
| 3268 | first_read_stages_ = 0U; |
| 3269 | auto a = firsts.begin(); |
| 3270 | auto a_end = firsts.end(); |
| 3271 | for (auto &b : other.first_accesses_) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3272 | // TODO: Determine whether some tag offset will be needed for PHASE II |
| 3273 | while ((a != a_end) && (a->tag < b.tag)) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3274 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3275 | ++a; |
| 3276 | } |
| 3277 | UpdateFirst(b.tag, b.usage_index, b.ordering_rule); |
| 3278 | } |
| 3279 | for (; a != a_end; ++a) { |
| 3280 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3281 | } |
| 3282 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3283 | } |
| 3284 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3285 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, SyncOrdering ordering_rule, const ResourceUsageTag tag) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3286 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 3287 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3288 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3289 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 3290 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 3291 | const auto usage_stage = PipelineStageBit(usage_index); |
| 3292 | if (usage_stage & last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3293 | for (auto &read_access : last_reads) { |
| 3294 | if (read_access.stage == usage_stage) { |
| 3295 | read_access.Set(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3296 | break; |
| 3297 | } |
| 3298 | } |
| 3299 | } else { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3300 | last_reads.emplace_back(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3301 | last_read_stages |= usage_stage; |
| 3302 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3303 | |
| 3304 | // 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] | 3305 | if (usage_stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3306 | // TODO Revisit re: multiple reads for a given stage |
| 3307 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3308 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3309 | } else { |
| 3310 | // Assume write |
| 3311 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3312 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3313 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3314 | UpdateFirst(tag, usage_index, ordering_rule); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3315 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3316 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3317 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 3318 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 3319 | // We can overwrite them as *this* write is now after them. |
| 3320 | // |
| 3321 | // 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] | 3322 | void ResourceAccessState::SetWrite(const SyncStageAccessFlags &usage_bit, const ResourceUsageTag tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3323 | last_reads.clear(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3324 | last_read_stages = 0; |
| 3325 | read_execution_barriers = 0; |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3326 | input_attachment_read = false; // Denotes no outstanding input attachment read after the last write. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3327 | |
| 3328 | write_barriers = 0; |
| 3329 | write_dependency_chain = 0; |
| 3330 | write_tag = tag; |
| 3331 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3332 | } |
| 3333 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3334 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 3335 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 3336 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 3337 | // replace the current write barriers or add to them, so accumulate to pending as well. |
| 3338 | void ResourceAccessState::ApplyBarrier(const SyncBarrier &barrier, bool layout_transition) { |
| 3339 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 3340 | // applying the memory barriers |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 3341 | // NOTE: We update the write barrier if the write is in the first access scope or if there is a layout |
| 3342 | // transistion, under the theory of "most recent access". If the read/write *isn't* safe |
| 3343 | // vs. this layout transition DetectBarrierHazard should report it. We treat the layout |
| 3344 | // transistion *as* a write and in scope with the barrier (it's before visibility). |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3345 | if (layout_transition || WriteInSourceScopeOrChain(barrier.src_exec_scope.exec_scope, barrier.src_access_scope)) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3346 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3347 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3348 | if (layout_transition) { |
| 3349 | pending_layout_ordering_ |= OrderingBarrier(barrier.src_exec_scope.exec_scope, barrier.src_access_scope); |
| 3350 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3351 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3352 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 3353 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3354 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3355 | if (!pending_layout_transition) { |
| 3356 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 3357 | // don't need to be tracked as we're just going to zero them. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3358 | for (auto &read_access : last_reads) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3359 | // The | implements the "dependency chain" logic for this access, as the barriers field stores the second sync scope |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3360 | if (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers)) { |
| 3361 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3362 | } |
| 3363 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3364 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3365 | } |
| 3366 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3367 | // Apply the tag scoped memory barrier without updating the existing barriers. The execution barrier |
| 3368 | // changes the "chaining" state, but to keep barriers independent. See discussion above. |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3369 | void ResourceAccessState::ApplyBarrier(const ResourceUsageTag scope_tag, const SyncBarrier &barrier, bool layout_transition) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3370 | // The scope logic for events is, if we're here, the resource usage was flagged as "in the first execution scope" at |
| 3371 | // the time of the SetEvent, thus all we need check is whether the access is the same one (i.e. before the scope tag |
| 3372 | // in order to know if it's in the excecution scope |
| 3373 | // Notice that the layout transition sets the pending barriers *regardless*, as any lack of src_access_scope to |
| 3374 | // guard against the layout transition should be reported in the detect barrier hazard phase, and we only report |
| 3375 | // errors w.r.t. "most recent" accesses. |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3376 | if (layout_transition || ((write_tag < scope_tag) && (barrier.src_access_scope & last_write).any())) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3377 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3378 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3379 | if (layout_transition) { |
| 3380 | pending_layout_ordering_ |= OrderingBarrier(barrier.src_exec_scope.exec_scope, barrier.src_access_scope); |
| 3381 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3382 | } |
| 3383 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 3384 | pending_layout_transition |= layout_transition; |
| 3385 | |
| 3386 | if (!pending_layout_transition) { |
| 3387 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 3388 | // don't need to be tracked as we're just going to zero them. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3389 | for (auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3390 | // If this read is the same one we included in the set event and in scope, then apply the execution barrier... |
| 3391 | // NOTE: That's not really correct... this read stage might *not* have been included in the setevent, and the barriers |
| 3392 | // representing the chain might have changed since then (that would be an odd usage), so as a first approximation |
| 3393 | // we'll assume the barriers *haven't* been changed since (if the tag hasn't), and while this could be a false |
| 3394 | // positive in the case of Set; SomeBarrier; Wait; we'll live with it until we can add more state to the first scope |
| 3395 | // capture (the specific write and read stages that *were* in scope at the moment of SetEvents. |
| 3396 | // TODO: eliminate the false positive by including write/read-stages "in scope" information in SetEvents first_scope |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3397 | if ((read_access.tag < scope_tag) && (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers))) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3398 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3399 | } |
| 3400 | } |
| 3401 | } |
| 3402 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3403 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag tag) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3404 | if (pending_layout_transition) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3405 | // 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] | 3406 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3407 | UpdateFirst(tag, SYNC_IMAGE_LAYOUT_TRANSITION, SyncOrdering::kNonAttachment); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3408 | TouchupFirstForLayoutTransition(tag, pending_layout_ordering_); |
| 3409 | pending_layout_ordering_ = OrderingBarrier(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3410 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3411 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3412 | |
| 3413 | // Apply the accumulate execution barriers (and thus update chaining information) |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3414 | // 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] | 3415 | for (auto &read_access : last_reads) { |
| 3416 | read_access.barriers |= read_access.pending_dep_chain; |
| 3417 | read_execution_barriers |= read_access.barriers; |
| 3418 | read_access.pending_dep_chain = 0; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 3422 | write_dependency_chain |= pending_write_dep_chain; |
| 3423 | write_barriers |= pending_write_barriers; |
| 3424 | pending_write_dep_chain = 0; |
| 3425 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3426 | } |
| 3427 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3428 | bool ResourceAccessState::FirstAccessInTagRange(const ResourceUsageRange &tag_range) const { |
| 3429 | if (!first_accesses_.size()) return false; |
| 3430 | const ResourceUsageRange first_access_range = {first_accesses_.front().tag, first_accesses_.back().tag + 1}; |
| 3431 | return tag_range.intersects(first_access_range); |
| 3432 | } |
| 3433 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3434 | // 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] | 3435 | VkPipelineStageFlags2KHR ResourceAccessState::GetReadBarriers(const SyncStageAccessFlags &usage_bit) const { |
| 3436 | VkPipelineStageFlags2KHR barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3437 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3438 | for (const auto &read_access : last_reads) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3439 | if ((read_access.access & usage_bit).any()) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3440 | barriers = read_access.barriers; |
| 3441 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3442 | } |
| 3443 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3444 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3445 | return barriers; |
| 3446 | } |
| 3447 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3448 | inline bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlags2KHR usage_stage, const SyncStageAccessFlags &usage) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3449 | assert(IsRead(usage)); |
| 3450 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 3451 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 3452 | // any reads that happen after. |
| 3453 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 3454 | // 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] | 3455 | return last_write.any() && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3456 | } |
| 3457 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3458 | VkPipelineStageFlags2KHR ResourceAccessState::GetOrderedStages(const OrderingBarrier &ordering) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3459 | // Whether the stage are in the ordering scope only matters if the current write is ordered |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3460 | VkPipelineStageFlags2KHR ordered_stages = last_read_stages & ordering.exec_scope; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3461 | // Special input attachment handling as always (not encoded in exec_scop) |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3462 | 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] | 3463 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3464 | // 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] | 3465 | ordered_stages |= VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | return ordered_stages; |
| 3469 | } |
| 3470 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3471 | void ResourceAccessState::UpdateFirst(const ResourceUsageTag tag, SyncStageAccessIndex usage_index, SyncOrdering ordering_rule) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3472 | // Only record until we record a write. |
| 3473 | if (first_accesses_.empty() || IsRead(first_accesses_.back().usage_index)) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3474 | const VkPipelineStageFlags2KHR usage_stage = IsRead(usage_index) ? PipelineStageBit(usage_index) : 0U; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3475 | if (0 == (usage_stage & first_read_stages_)) { |
| 3476 | // 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] | 3477 | // We always need to know what stages were found prior to write |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3478 | first_read_stages_ |= usage_stage; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3479 | if (0 == (read_execution_barriers & usage_stage)) { |
| 3480 | // If this stage isn't masked then we add it (since writes map to usage_stage 0, this also records writes) |
| 3481 | first_accesses_.emplace_back(tag, usage_index, ordering_rule); |
| 3482 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3483 | } |
| 3484 | } |
| 3485 | } |
| 3486 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3487 | void ResourceAccessState::TouchupFirstForLayoutTransition(ResourceUsageTag tag, const OrderingBarrier &layout_ordering) { |
| 3488 | // Only call this after recording an image layout transition |
| 3489 | assert(first_accesses_.size()); |
| 3490 | if (first_accesses_.back().tag == tag) { |
| 3491 | // 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] | 3492 | assert(first_accesses_.back().usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3493 | first_write_layout_ordering_ = layout_ordering; |
| 3494 | } |
| 3495 | } |
| 3496 | |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 3497 | void ResourceAccessState::ReadState::Set(VkPipelineStageFlags2KHR stage_, const SyncStageAccessFlags &access_, |
| 3498 | VkPipelineStageFlags2KHR barriers_, ResourceUsageTag tag_) { |
| 3499 | stage = stage_; |
| 3500 | access = access_; |
| 3501 | barriers = barriers_; |
| 3502 | tag = tag_; |
| 3503 | pending_dep_chain = 0; // If this is a new read, we aren't applying a barrier set. |
| 3504 | } |
| 3505 | |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame^] | 3506 | const QueueSyncState *SyncValidator::GetQueueSyncState(VkQueue queue) const { |
| 3507 | return GetMappedPlainFromShared(queue_sync_states_, queue); |
| 3508 | } |
| 3509 | |
| 3510 | QueueSyncState *SyncValidator::GetQueueSyncState(VkQueue queue) { return GetMappedPlainFromShared(queue_sync_states_, queue); } |
| 3511 | |
| 3512 | std::shared_ptr<const QueueSyncState> SyncValidator::GetQueueSyncStateShared(VkQueue queue) const { |
| 3513 | return GetMapped(queue_sync_states_, queue, []() { return std::shared_ptr<QueueSyncState>(); }); |
| 3514 | } |
| 3515 | |
| 3516 | std::shared_ptr<QueueSyncState> SyncValidator::GetQueueSyncStateShared(VkQueue queue) { |
| 3517 | return GetMapped(queue_sync_states_, queue, []() { return std::shared_ptr<QueueSyncState>(); }); |
| 3518 | } |
| 3519 | |
| 3520 | std::shared_ptr<SemaphoreSyncState> SyncValidator::GetSemaphoreSyncState(VkSemaphore sem) { |
| 3521 | return GetMappedInsert(sync_semaphores_, sem, [this, sem]() { |
| 3522 | std::shared_ptr<const SEMAPHORE_STATE> sem_state(this->Get<SEMAPHORE_STATE>(sem)); |
| 3523 | return std::make_shared<SemaphoreSyncState>(sem_state); |
| 3524 | }); |
| 3525 | } |
| 3526 | |
| 3527 | std::shared_ptr<const SemaphoreSyncState> SyncValidator::GetSemaphoreSyncState(VkSemaphore sem) const { |
| 3528 | return GetMapped(sync_semaphores_, sem, []() { return std::shared_ptr<SemaphoreSyncState>(); }); |
| 3529 | } |
| 3530 | |
John Zulauf | ea943c5 | 2022-02-22 11:05:17 -0700 | [diff] [blame] | 3531 | std::shared_ptr<CommandBufferAccessContext> SyncValidator::AccessContextFactory(VkCommandBuffer command_buffer) { |
| 3532 | // If we don't have one, make it. |
| 3533 | auto cb_state = Get<CMD_BUFFER_STATE>(command_buffer); |
| 3534 | assert(cb_state.get()); |
| 3535 | auto queue_flags = cb_state->GetQueueFlags(); |
| 3536 | return std::make_shared<CommandBufferAccessContext>(*this, cb_state, queue_flags); |
| 3537 | } |
| 3538 | |
| 3539 | inline std::shared_ptr<CommandBufferAccessContext> SyncValidator::GetAccessContextShared(VkCommandBuffer command_buffer) { |
| 3540 | return GetMappedInsert(cb_access_state, command_buffer, |
| 3541 | [this, command_buffer]() { return AccessContextFactory(command_buffer); }); |
| 3542 | } |
| 3543 | |
| 3544 | std::shared_ptr<const CommandBufferAccessContext> SyncValidator::GetAccessContextShared(VkCommandBuffer command_buffer) const { |
| 3545 | return GetMapped(cb_access_state, command_buffer, []() { return std::shared_ptr<CommandBufferAccessContext>(); }); |
| 3546 | } |
| 3547 | |
| 3548 | const CommandBufferAccessContext *SyncValidator::GetAccessContext(VkCommandBuffer command_buffer) const { |
| 3549 | return GetMappedPlainFromShared(cb_access_state, command_buffer); |
| 3550 | } |
| 3551 | |
| 3552 | CommandBufferAccessContext *SyncValidator::GetAccessContext(VkCommandBuffer command_buffer) { |
| 3553 | return GetAccessContextShared(command_buffer).get(); |
| 3554 | } |
| 3555 | |
| 3556 | CommandBufferAccessContext *SyncValidator::GetAccessContextNoInsert(VkCommandBuffer command_buffer) { |
| 3557 | return GetMappedPlainFromShared(cb_access_state, command_buffer); |
| 3558 | } |
| 3559 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3560 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3561 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 3562 | if (access_context) { |
| 3563 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3564 | } |
| 3565 | } |
| 3566 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3567 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 3568 | auto access_found = cb_access_state.find(command_buffer); |
| 3569 | if (access_found != cb_access_state.end()) { |
| 3570 | access_found->second->Reset(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3571 | access_found->second->MarkDestroyed(); |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3572 | cb_access_state.erase(access_found); |
| 3573 | } |
| 3574 | } |
| 3575 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3576 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3577 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 3578 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3579 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3580 | assert(cb_context); |
| 3581 | if (!cb_context) return skip; |
| 3582 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3583 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3584 | // If we have no previous accesses, we have no hazards |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3585 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 3586 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3587 | |
| 3588 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3589 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3590 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3591 | 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] | 3592 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3593 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3594 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3595 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3596 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3597 | cb_context->FormatHazard(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3598 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3599 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3600 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3601 | 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] | 3602 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3603 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3604 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3605 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3606 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3607 | cb_context->FormatHazard(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3608 | } |
| 3609 | } |
| 3610 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3611 | } |
| 3612 | return skip; |
| 3613 | } |
| 3614 | |
| 3615 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3616 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3617 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3618 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3619 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3620 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3621 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3622 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 3623 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3624 | |
| 3625 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3626 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3627 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3628 | 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] | 3629 | 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] | 3630 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3631 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3632 | 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] | 3633 | 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] | 3634 | } |
| 3635 | } |
| 3636 | } |
| 3637 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3638 | void SyncValidator::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 3639 | // Clear out events from the command buffer contexts |
| 3640 | for (auto &cb_context : cb_access_state) { |
| 3641 | cb_context.second->RecordDestroyEvent(event); |
| 3642 | } |
| 3643 | } |
| 3644 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3645 | bool SyncValidator::ValidateCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos, |
| 3646 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3647 | bool skip = false; |
| 3648 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3649 | assert(cb_context); |
| 3650 | if (!cb_context) return skip; |
| 3651 | const auto *context = cb_context->GetCurrentAccessContext(); |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3652 | const char *func_name = CommandTypeString(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3653 | |
| 3654 | // If we have no previous accesses, we have no hazards |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3655 | auto src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3656 | auto dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3657 | |
| 3658 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3659 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3660 | if (src_buffer) { |
| 3661 | 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] | 3662 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3663 | if (hazard.hazard) { |
| 3664 | // TODO -- add tag information to log msg when useful. |
| 3665 | skip |= LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3666 | "%s(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3667 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3668 | region, cb_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3669 | } |
| 3670 | } |
| 3671 | if (dst_buffer && !skip) { |
| 3672 | 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] | 3673 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3674 | if (hazard.hazard) { |
| 3675 | skip |= LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3676 | "%s(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3677 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3678 | region, cb_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3679 | } |
| 3680 | } |
| 3681 | if (skip) break; |
| 3682 | } |
| 3683 | return skip; |
| 3684 | } |
| 3685 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3686 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3687 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 3688 | return ValidateCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2KHR); |
| 3689 | } |
| 3690 | |
| 3691 | bool SyncValidator::PreCallValidateCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos) const { |
| 3692 | return ValidateCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2); |
| 3693 | } |
| 3694 | |
| 3695 | void SyncValidator::RecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos, CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3696 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3697 | assert(cb_context); |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3698 | const auto tag = cb_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3699 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3700 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3701 | auto src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3702 | auto dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3703 | |
| 3704 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3705 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3706 | if (src_buffer) { |
| 3707 | 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] | 3708 | 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] | 3709 | } |
| 3710 | if (dst_buffer) { |
| 3711 | 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] | 3712 | 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] | 3713 | } |
| 3714 | } |
| 3715 | } |
| 3716 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3717 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 3718 | RecordCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2KHR); |
| 3719 | } |
| 3720 | |
| 3721 | void SyncValidator::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos) { |
| 3722 | RecordCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2); |
| 3723 | } |
| 3724 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3725 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3726 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3727 | const VkImageCopy *pRegions) const { |
| 3728 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3729 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3730 | assert(cb_access_context); |
| 3731 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3732 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3733 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3734 | assert(context); |
| 3735 | if (!context) return skip; |
| 3736 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3737 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 3738 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3739 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3740 | const auto ©_region = pRegions[region]; |
| 3741 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3742 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.srcSubresource, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3743 | copy_region.srcOffset, copy_region.extent); |
| 3744 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3745 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3746 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3747 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3748 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3749 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3753 | auto hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.dstSubresource, |
ziga-lunarg | 7374651 | 2022-03-23 23:08:17 +0100 | [diff] [blame] | 3754 | copy_region.dstOffset, copy_region.extent); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3755 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3756 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3757 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3758 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3759 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3760 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 3761 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3762 | } |
| 3763 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3764 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3765 | return skip; |
| 3766 | } |
| 3767 | |
| 3768 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3769 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3770 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3771 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3772 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3773 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3774 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3775 | assert(context); |
| 3776 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 3777 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 3778 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3779 | |
| 3780 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3781 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3782 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3783 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3784 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3785 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3786 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3787 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
ziga-lunarg | 7374651 | 2022-03-23 23:08:17 +0100 | [diff] [blame] | 3788 | copy_region.dstSubresource, copy_region.dstOffset, copy_region.extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3789 | } |
| 3790 | } |
| 3791 | } |
| 3792 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 3793 | bool SyncValidator::ValidateCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo, |
| 3794 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3795 | bool skip = false; |
| 3796 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3797 | assert(cb_access_context); |
| 3798 | if (!cb_access_context) return skip; |
| 3799 | |
| 3800 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3801 | assert(context); |
| 3802 | if (!context) return skip; |
| 3803 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 3804 | const char *func_name = CommandTypeString(cmd_type); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3805 | auto src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3806 | auto dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 3807 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3808 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3809 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3810 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3811 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.srcSubresource, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3812 | copy_region.srcOffset, copy_region.extent); |
| 3813 | if (hazard.hazard) { |
| 3814 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 3815 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", func_name, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3816 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3817 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3818 | } |
| 3819 | } |
| 3820 | |
| 3821 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3822 | auto hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.dstSubresource, |
ziga-lunarg | 7374651 | 2022-03-23 23:08:17 +0100 | [diff] [blame] | 3823 | copy_region.dstOffset, copy_region.extent); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3824 | if (hazard.hazard) { |
| 3825 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 3826 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", func_name, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3827 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3828 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3829 | } |
| 3830 | if (skip) break; |
| 3831 | } |
| 3832 | } |
| 3833 | |
| 3834 | return skip; |
| 3835 | } |
| 3836 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 3837 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 3838 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 3839 | return ValidateCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2KHR); |
| 3840 | } |
| 3841 | |
| 3842 | bool SyncValidator::PreCallValidateCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) const { |
| 3843 | return ValidateCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2); |
| 3844 | } |
| 3845 | |
| 3846 | void SyncValidator::RecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo, CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3847 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3848 | assert(cb_access_context); |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 3849 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3850 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3851 | assert(context); |
| 3852 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 3853 | auto src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3854 | auto dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3855 | |
| 3856 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3857 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3858 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3859 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3860 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3861 | } |
| 3862 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3863 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
ziga-lunarg | 7374651 | 2022-03-23 23:08:17 +0100 | [diff] [blame] | 3864 | copy_region.dstSubresource, copy_region.dstOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3865 | } |
| 3866 | } |
| 3867 | } |
| 3868 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 3869 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 3870 | RecordCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2KHR); |
| 3871 | } |
| 3872 | |
| 3873 | void SyncValidator::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) { |
| 3874 | RecordCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2); |
| 3875 | } |
| 3876 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3877 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3878 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3879 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3880 | uint32_t bufferMemoryBarrierCount, |
| 3881 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3882 | uint32_t imageMemoryBarrierCount, |
| 3883 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 3884 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3885 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3886 | assert(cb_access_context); |
| 3887 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3888 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 3889 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 3890 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 3891 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 3892 | pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 3893 | skip = pipeline_barrier.Validate(*cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3894 | return skip; |
| 3895 | } |
| 3896 | |
| 3897 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3898 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3899 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3900 | uint32_t bufferMemoryBarrierCount, |
| 3901 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3902 | uint32_t imageMemoryBarrierCount, |
| 3903 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3904 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3905 | assert(cb_access_context); |
| 3906 | if (!cb_access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3907 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 3908 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), |
| 3909 | srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, |
| 3910 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 3911 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3912 | } |
| 3913 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 3914 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 3915 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 3916 | bool skip = false; |
| 3917 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3918 | assert(cb_access_context); |
| 3919 | if (!cb_access_context) return skip; |
| 3920 | |
| 3921 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3922 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 3923 | return skip; |
| 3924 | } |
| 3925 | |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 3926 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2(VkCommandBuffer commandBuffer, |
| 3927 | const VkDependencyInfo *pDependencyInfo) const { |
| 3928 | bool skip = false; |
| 3929 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3930 | assert(cb_access_context); |
| 3931 | if (!cb_access_context) return skip; |
| 3932 | |
| 3933 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3934 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 3935 | return skip; |
| 3936 | } |
| 3937 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 3938 | void SyncValidator::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) { |
| 3939 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3940 | assert(cb_access_context); |
| 3941 | if (!cb_access_context) return; |
| 3942 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 3943 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), |
| 3944 | *pDependencyInfo); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 3945 | } |
| 3946 | |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 3947 | void SyncValidator::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer, const VkDependencyInfo *pDependencyInfo) { |
| 3948 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3949 | assert(cb_access_context); |
| 3950 | if (!cb_access_context) return; |
| 3951 | |
| 3952 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER2, *this, cb_access_context->GetQueueFlags(), |
| 3953 | *pDependencyInfo); |
| 3954 | } |
| 3955 | |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 3956 | void SyncValidator::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3957 | // The state tracker sets up the device state |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 3958 | StateTracker::CreateDevice(pCreateInfo); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3959 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3960 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 3961 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3962 | // TODO: Find a good way to do this hooklessly. |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 3963 | SetCommandBufferResetCallback([this](VkCommandBuffer command_buffer) -> void { ResetCommandBufferCallback(command_buffer); }); |
| 3964 | SetCommandBufferFreeCallback([this](VkCommandBuffer command_buffer) -> void { FreeCommandBufferCallback(command_buffer); }); |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame^] | 3965 | |
| 3966 | ForEachShared<QUEUE_STATE>([this](const std::shared_ptr<QUEUE_STATE> &queue_state) { |
| 3967 | auto queue_flags = physical_device_state->queue_family_properties[queue_state->queueFamilyIndex].queueFlags; |
| 3968 | std::shared_ptr<QueueSyncState> queue_sync_state = std::make_shared<QueueSyncState>(queue_state, queue_flags); |
| 3969 | queue_sync_states_.emplace(std::make_pair(queue_state->Queue(), std::move(queue_sync_state))); |
| 3970 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3971 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3972 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3973 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3974 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3975 | bool skip = false; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3976 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3977 | if (cb_context) { |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3978 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3979 | skip = sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3980 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3981 | return skip; |
| 3982 | } |
| 3983 | |
| 3984 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3985 | VkSubpassContents contents) const { |
| 3986 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3987 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3988 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3989 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3990 | return skip; |
| 3991 | } |
| 3992 | |
| 3993 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3994 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3995 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3996 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3997 | return skip; |
| 3998 | } |
| 3999 | |
| 4000 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4001 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4002 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4003 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4004 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4005 | return skip; |
| 4006 | } |
| 4007 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4008 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 4009 | VkResult result) { |
| 4010 | // The state tracker sets up the command buffer state |
| 4011 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 4012 | |
| 4013 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 4014 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 4015 | assert(cb_access_context); |
| 4016 | cb_access_context->Reset(); |
| 4017 | } |
| 4018 | |
| 4019 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4020 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4021 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4022 | if (cb_context) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 4023 | cb_context->RecordSyncOp<SyncOpBeginRenderPass>(cmd, *this, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4024 | } |
| 4025 | } |
| 4026 | |
| 4027 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4028 | VkSubpassContents contents) { |
| 4029 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4030 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4031 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4032 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4036 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 4037 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4038 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4042 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4043 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 4044 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4045 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4046 | } |
| 4047 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4048 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4049 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4050 | bool skip = false; |
| 4051 | |
| 4052 | auto cb_context = GetAccessContext(commandBuffer); |
| 4053 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4054 | if (!cb_context) return skip; |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4055 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4056 | return sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 4060 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4061 | // Convert to a NextSubpass2 |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4062 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4063 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4064 | auto subpass_end_info = LvlInitStruct<VkSubpassEndInfo>(); |
| 4065 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, &subpass_end_info, CMD_NEXTSUBPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4066 | return skip; |
| 4067 | } |
| 4068 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4069 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4070 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4071 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4072 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4073 | return skip; |
| 4074 | } |
| 4075 | |
| 4076 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4077 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 4078 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4079 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4080 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4084 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4085 | auto cb_context = GetAccessContext(commandBuffer); |
| 4086 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4087 | if (!cb_context) return; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4088 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 4089 | cb_context->RecordSyncOp<SyncOpNextSubpass>(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 4093 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4094 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4095 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4096 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4100 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 4101 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4102 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4103 | } |
| 4104 | |
| 4105 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4106 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 4107 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4108 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2KHR); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4109 | } |
| 4110 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4111 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
| 4112 | CMD_TYPE cmd) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4113 | bool skip = false; |
| 4114 | |
| 4115 | auto cb_context = GetAccessContext(commandBuffer); |
| 4116 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4117 | if (!cb_context) return skip; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4118 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4119 | SyncOpEndRenderPass sync_op(cmd, *this, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4120 | skip |= sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4121 | return skip; |
| 4122 | } |
| 4123 | |
| 4124 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 4125 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4126 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4127 | return skip; |
| 4128 | } |
| 4129 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4130 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4131 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4132 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4133 | return skip; |
| 4134 | } |
| 4135 | |
| 4136 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4137 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4138 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4139 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4140 | return skip; |
| 4141 | } |
| 4142 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4143 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4144 | // Resolve the all subpass contexts to the command buffer contexts |
| 4145 | auto cb_context = GetAccessContext(commandBuffer); |
| 4146 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4147 | if (!cb_context) return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4148 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 4149 | cb_context->RecordSyncOp<SyncOpEndRenderPass>(cmd, *this, pSubpassEndInfo); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4150 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4151 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 4152 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 4153 | // updates to a resource which do not conflict at the byte level. |
| 4154 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 4155 | // TODO: Add programatic control over suppression heuristics |
| 4156 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 4157 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 4158 | } |
| 4159 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4160 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4161 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4162 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4166 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4167 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4171 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2KHR); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4172 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4173 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4174 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4175 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4176 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4177 | VkImageLayout dstImageLayout, uint32_t regionCount, const RegionType *pRegions, |
| 4178 | CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4179 | bool skip = false; |
| 4180 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4181 | assert(cb_access_context); |
| 4182 | if (!cb_access_context) return skip; |
| 4183 | |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4184 | const char *func_name = CommandTypeString(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4185 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4186 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4187 | assert(context); |
| 4188 | if (!context) return skip; |
| 4189 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4190 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 4191 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4192 | |
| 4193 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4194 | const auto ©_region = pRegions[region]; |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4195 | HazardResult hazard; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4196 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4197 | if (src_buffer) { |
| 4198 | ResourceAccessRange src_range = |
| 4199 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4200 | hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4201 | if (hazard.hazard) { |
| 4202 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 4203 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4204 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 4205 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4206 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4207 | } |
| 4208 | } |
| 4209 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4210 | hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.imageSubresource, |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4211 | copy_region.imageOffset, copy_region.imageExtent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4212 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4213 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4214 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", func_name, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4215 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4216 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4217 | } |
| 4218 | if (skip) break; |
| 4219 | } |
| 4220 | if (skip) break; |
| 4221 | } |
| 4222 | return skip; |
| 4223 | } |
| 4224 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4225 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4226 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4227 | const VkBufferImageCopy *pRegions) const { |
| 4228 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4229 | CMD_COPYBUFFERTOIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 4233 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 4234 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4235 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4236 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2KHR); |
| 4237 | } |
| 4238 | |
| 4239 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, |
| 4240 | const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) const { |
| 4241 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4242 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 4243 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4244 | } |
| 4245 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4246 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4247 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4248 | VkImageLayout dstImageLayout, uint32_t regionCount, const RegionType *pRegions, |
| 4249 | CMD_TYPE cmd_type) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4250 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4251 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4252 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4253 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4254 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4255 | assert(context); |
| 4256 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4257 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 4258 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4259 | |
| 4260 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4261 | const auto ©_region = pRegions[region]; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4262 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4263 | if (src_buffer) { |
| 4264 | ResourceAccessRange src_range = |
| 4265 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4266 | 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] | 4267 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4268 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4269 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4270 | } |
| 4271 | } |
| 4272 | } |
| 4273 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4274 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4275 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4276 | const VkBufferImageCopy *pRegions) { |
| 4277 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4278 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, CMD_COPYBUFFERTOIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4279 | } |
| 4280 | |
| 4281 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 4282 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 4283 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 4284 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4285 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4286 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2KHR); |
| 4287 | } |
| 4288 | |
| 4289 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, |
| 4290 | const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) { |
| 4291 | StateTracker::PreCallRecordCmdCopyBufferToImage2(commandBuffer, pCopyBufferToImageInfo); |
| 4292 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4293 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 4294 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4295 | } |
| 4296 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4297 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4298 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4299 | VkBuffer dstBuffer, uint32_t regionCount, const RegionType *pRegions, |
| 4300 | CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4301 | bool skip = false; |
| 4302 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4303 | assert(cb_access_context); |
| 4304 | if (!cb_access_context) return skip; |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4305 | const char *func_name = CommandTypeString(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4306 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4307 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4308 | assert(context); |
| 4309 | if (!context) return skip; |
| 4310 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4311 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4312 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 4313 | 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] | 4314 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4315 | const auto ©_region = pRegions[region]; |
| 4316 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4317 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.imageSubresource, |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4318 | copy_region.imageOffset, copy_region.imageExtent); |
| 4319 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4320 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4321 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", func_name, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4322 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4323 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4324 | } |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4325 | if (dst_mem) { |
| 4326 | ResourceAccessRange dst_range = |
| 4327 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4328 | hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4329 | if (hazard.hazard) { |
| 4330 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4331 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 4332 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4333 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4334 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4335 | } |
| 4336 | } |
| 4337 | if (skip) break; |
| 4338 | } |
| 4339 | return skip; |
| 4340 | } |
| 4341 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4342 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 4343 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 4344 | const VkBufferImageCopy *pRegions) const { |
| 4345 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4346 | CMD_COPYIMAGETOBUFFER); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4347 | } |
| 4348 | |
| 4349 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4350 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 4351 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4352 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4353 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2KHR); |
| 4354 | } |
| 4355 | |
| 4356 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, |
| 4357 | const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) const { |
| 4358 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4359 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 4360 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4361 | } |
| 4362 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4363 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4364 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4365 | VkBuffer dstBuffer, uint32_t regionCount, const RegionType *pRegions, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4366 | CMD_TYPE cmd_type) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4367 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4368 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4369 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4370 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4371 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4372 | assert(context); |
| 4373 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4374 | auto src_image = Get<IMAGE_STATE>(srcImage); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4375 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 4376 | 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] | 4377 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4378 | |
| 4379 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4380 | const auto ©_region = pRegions[region]; |
| 4381 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4382 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4383 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4384 | if (dst_buffer) { |
| 4385 | ResourceAccessRange dst_range = |
| 4386 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4387 | 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] | 4388 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4389 | } |
| 4390 | } |
| 4391 | } |
| 4392 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4393 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4394 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 4395 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4396 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, CMD_COPYIMAGETOBUFFER); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4397 | } |
| 4398 | |
| 4399 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4400 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 4401 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 4402 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4403 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4404 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2KHR); |
| 4405 | } |
| 4406 | |
| 4407 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, |
| 4408 | const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) { |
| 4409 | StateTracker::PreCallRecordCmdCopyImageToBuffer2(commandBuffer, pCopyImageToBufferInfo); |
| 4410 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4411 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 4412 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4413 | } |
| 4414 | |
| 4415 | template <typename RegionType> |
| 4416 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4417 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4418 | const RegionType *pRegions, VkFilter filter, const char *apiName) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4419 | bool skip = false; |
| 4420 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4421 | assert(cb_access_context); |
| 4422 | if (!cb_access_context) return skip; |
| 4423 | |
| 4424 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4425 | assert(context); |
| 4426 | if (!context) return skip; |
| 4427 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4428 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4429 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4430 | |
| 4431 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4432 | const auto &blit_region = pRegions[region]; |
| 4433 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4434 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4435 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4436 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4437 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4438 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4439 | 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] | 4440 | auto hazard = context->DetectHazard(*src_image, SYNC_BLIT_TRANSFER_READ, blit_region.srcSubresource, offset, extent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4441 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4442 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4443 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4444 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4445 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4446 | } |
| 4447 | } |
| 4448 | |
| 4449 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4450 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4451 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4452 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4453 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4454 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4455 | 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] | 4456 | auto hazard = context->DetectHazard(*dst_image, SYNC_BLIT_TRANSFER_WRITE, blit_region.dstSubresource, offset, extent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4457 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4458 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4459 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4460 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4461 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4462 | } |
| 4463 | if (skip) break; |
| 4464 | } |
| 4465 | } |
| 4466 | |
| 4467 | return skip; |
| 4468 | } |
| 4469 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4470 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4471 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4472 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 4473 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
| 4474 | "vkCmdBlitImage"); |
| 4475 | } |
| 4476 | |
| 4477 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 4478 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 4479 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4480 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4481 | pBlitImageInfo->filter, "vkCmdBlitImage2KHR"); |
| 4482 | } |
| 4483 | |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4484 | bool SyncValidator::PreCallValidateCmdBlitImage2(VkCommandBuffer commandBuffer, |
| 4485 | const VkBlitImageInfo2 *pBlitImageInfo) const { |
| 4486 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4487 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4488 | pBlitImageInfo->filter, "vkCmdBlitImage2"); |
| 4489 | } |
| 4490 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4491 | template <typename RegionType> |
| 4492 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4493 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4494 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4495 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4496 | assert(cb_access_context); |
| 4497 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4498 | assert(context); |
| 4499 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4500 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4501 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4502 | |
| 4503 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4504 | const auto &blit_region = pRegions[region]; |
| 4505 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4506 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4507 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4508 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4509 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4510 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4511 | 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] | 4512 | context->UpdateAccessState(*src_image, SYNC_BLIT_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4513 | blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4514 | } |
| 4515 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4516 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4517 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4518 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4519 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4520 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4521 | 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] | 4522 | context->UpdateAccessState(*dst_image, SYNC_BLIT_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4523 | blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4524 | } |
| 4525 | } |
| 4526 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4527 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4528 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4529 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4530 | const VkImageBlit *pRegions, VkFilter filter) { |
| 4531 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4532 | assert(cb_access_context); |
| 4533 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 4534 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4535 | pRegions, filter); |
| 4536 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 4537 | } |
| 4538 | |
| 4539 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 4540 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 4541 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4542 | assert(cb_access_context); |
| 4543 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 4544 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4545 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4546 | pBlitImageInfo->filter, tag); |
| 4547 | } |
| 4548 | |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4549 | void SyncValidator::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) { |
| 4550 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 4551 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4552 | assert(cb_access_context); |
| 4553 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2); |
| 4554 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4555 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4556 | pBlitImageInfo->filter, tag); |
| 4557 | } |
| 4558 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4559 | bool SyncValidator::ValidateIndirectBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4560 | VkCommandBuffer commandBuffer, const VkDeviceSize struct_size, const VkBuffer buffer, |
| 4561 | const VkDeviceSize offset, const uint32_t drawCount, const uint32_t stride, |
| 4562 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4563 | bool skip = false; |
| 4564 | if (drawCount == 0) return skip; |
| 4565 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4566 | auto buf_state = Get<BUFFER_STATE>(buffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4567 | VkDeviceSize size = struct_size; |
| 4568 | if (drawCount == 1 || stride == size) { |
| 4569 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4570 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4571 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4572 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4573 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4574 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4575 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4576 | cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4577 | } |
| 4578 | } else { |
| 4579 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4580 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4581 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4582 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4583 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4584 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
| 4585 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4586 | cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4587 | break; |
| 4588 | } |
| 4589 | } |
| 4590 | } |
| 4591 | return skip; |
| 4592 | } |
| 4593 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 4594 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag tag, const VkDeviceSize struct_size, |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4595 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 4596 | uint32_t stride) { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4597 | auto buf_state = Get<BUFFER_STATE>(buffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4598 | VkDeviceSize size = struct_size; |
| 4599 | if (drawCount == 1 || stride == size) { |
| 4600 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4601 | const ResourceAccessRange range = MakeRange(offset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4602 | 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] | 4603 | } else { |
| 4604 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4605 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4606 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, |
| 4607 | tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4608 | } |
| 4609 | } |
| 4610 | } |
| 4611 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4612 | bool SyncValidator::ValidateCountBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4613 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4614 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4615 | bool skip = false; |
| 4616 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4617 | auto count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4618 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4619 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4620 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4621 | skip |= LogError(count_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4622 | "%s: Hazard %s for countBuffer %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4623 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4624 | cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4625 | } |
| 4626 | return skip; |
| 4627 | } |
| 4628 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 4629 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag tag, VkBuffer buffer, VkDeviceSize offset) { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4630 | auto count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4631 | const ResourceAccessRange range = MakeRange(offset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4632 | 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] | 4633 | } |
| 4634 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4635 | 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] | 4636 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4637 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4638 | assert(cb_access_context); |
| 4639 | if (!cb_access_context) return skip; |
| 4640 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4641 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4642 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | 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] | 4646 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4647 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4648 | assert(cb_access_context); |
| 4649 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4650 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4651 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4652 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4653 | |
| 4654 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4655 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4656 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4657 | assert(cb_access_context); |
| 4658 | if (!cb_access_context) return skip; |
| 4659 | |
| 4660 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4661 | assert(context); |
| 4662 | if (!context) return skip; |
| 4663 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4664 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4665 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, |
| 4666 | 1, sizeof(VkDispatchIndirectCommand), "vkCmdDispatchIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4667 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4671 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4672 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4673 | assert(cb_access_context); |
| 4674 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 4675 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4676 | assert(context); |
| 4677 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4678 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 4679 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4680 | } |
| 4681 | |
| 4682 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4683 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4684 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4685 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4686 | assert(cb_access_context); |
| 4687 | if (!cb_access_context) return skip; |
| 4688 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4689 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw"); |
| 4690 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, "vkCmdDraw"); |
| 4691 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDraw"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4692 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4693 | } |
| 4694 | |
| 4695 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4696 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4697 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4698 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4699 | assert(cb_access_context); |
| 4700 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4701 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4702 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4703 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 4704 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4705 | } |
| 4706 | |
| 4707 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4708 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4709 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4710 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4711 | assert(cb_access_context); |
| 4712 | if (!cb_access_context) return skip; |
| 4713 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4714 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed"); |
| 4715 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, "vkCmdDrawIndexed"); |
| 4716 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexed"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4717 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4721 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4722 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4723 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4724 | assert(cb_access_context); |
| 4725 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4726 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4727 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4728 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 4729 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4733 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4734 | bool skip = false; |
| 4735 | if (drawCount == 0) return skip; |
| 4736 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4737 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4738 | assert(cb_access_context); |
| 4739 | if (!cb_access_context) return skip; |
| 4740 | |
| 4741 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4742 | assert(context); |
| 4743 | if (!context) return skip; |
| 4744 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4745 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect"); |
| 4746 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4747 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4748 | drawCount, stride, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4749 | |
| 4750 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4751 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4752 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4753 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4754 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4758 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4759 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4760 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4761 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4762 | assert(cb_access_context); |
| 4763 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 4764 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4765 | assert(context); |
| 4766 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4767 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4768 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4769 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4770 | |
| 4771 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4772 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4773 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4774 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4778 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4779 | bool skip = false; |
| 4780 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4781 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4782 | assert(cb_access_context); |
| 4783 | if (!cb_access_context) return skip; |
| 4784 | |
| 4785 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4786 | assert(context); |
| 4787 | if (!context) return skip; |
| 4788 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4789 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect"); |
| 4790 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexedIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4791 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4792 | offset, drawCount, stride, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4793 | |
| 4794 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4795 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4796 | // We will validate the index and vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4797 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4798 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4802 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4803 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4804 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4805 | assert(cb_access_context); |
| 4806 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 4807 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4808 | assert(context); |
| 4809 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4810 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4811 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4812 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4813 | |
| 4814 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4815 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4816 | // 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] | 4817 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4821 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4822 | uint32_t stride, const char *function) const { |
| 4823 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4824 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4825 | assert(cb_access_context); |
| 4826 | if (!cb_access_context) return skip; |
| 4827 | |
| 4828 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4829 | assert(context); |
| 4830 | if (!context) return skip; |
| 4831 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4832 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4833 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4834 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4835 | maxDrawCount, stride, function); |
| 4836 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4837 | |
| 4838 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4839 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4840 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4841 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4842 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4846 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4847 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4848 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4849 | "vkCmdDrawIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4850 | } |
| 4851 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4852 | void SyncValidator::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4853 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4854 | uint32_t stride, CMD_TYPE cmd_type) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4855 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4856 | assert(cb_access_context); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4857 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4858 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4859 | assert(context); |
| 4860 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4861 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4862 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4863 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 4864 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4865 | |
| 4866 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4867 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4868 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4869 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4870 | } |
| 4871 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4872 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4873 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4874 | uint32_t stride) { |
| 4875 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4876 | stride); |
| 4877 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4878 | CMD_DRAWINDIRECTCOUNT); |
| 4879 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4880 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4881 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4882 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4883 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4884 | "vkCmdDrawIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4885 | } |
| 4886 | |
| 4887 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4888 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4889 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4890 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4891 | stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4892 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4893 | CMD_DRAWINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4894 | } |
| 4895 | |
| 4896 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4897 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4898 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4899 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4900 | "vkCmdDrawIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4901 | } |
| 4902 | |
| 4903 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4904 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4905 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4906 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4907 | stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4908 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4909 | CMD_DRAWINDIRECTCOUNTAMD); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4913 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4914 | uint32_t stride, const char *function) const { |
| 4915 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4916 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4917 | assert(cb_access_context); |
| 4918 | if (!cb_access_context) return skip; |
| 4919 | |
| 4920 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4921 | assert(context); |
| 4922 | if (!context) return skip; |
| 4923 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4924 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4925 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4926 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4927 | offset, maxDrawCount, stride, function); |
| 4928 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4929 | |
| 4930 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4931 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4932 | // We will validate the index and vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4933 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4934 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4935 | } |
| 4936 | |
| 4937 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4938 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4939 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4940 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4941 | "vkCmdDrawIndexedIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4942 | } |
| 4943 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4944 | void SyncValidator::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4945 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4946 | uint32_t stride, CMD_TYPE cmd_type) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4947 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4948 | assert(cb_access_context); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4949 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4950 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4951 | assert(context); |
| 4952 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4953 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4954 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4955 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 4956 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4957 | |
| 4958 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4959 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4960 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 4961 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4962 | } |
| 4963 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4964 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4965 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4966 | uint32_t maxDrawCount, uint32_t stride) { |
| 4967 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4968 | maxDrawCount, stride); |
| 4969 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4970 | CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 4971 | } |
| 4972 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4973 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4974 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4975 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4976 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4977 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4978 | "vkCmdDrawIndexedIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4982 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4983 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4984 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4985 | maxDrawCount, stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4986 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4987 | CMD_DRAWINDEXEDINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4991 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4992 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4993 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4994 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4995 | "vkCmdDrawIndexedIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4999 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5000 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5001 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 5002 | maxDrawCount, stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5003 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5004 | CMD_DRAWINDEXEDINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5008 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 5009 | const VkImageSubresourceRange *pRanges) const { |
| 5010 | bool skip = false; |
| 5011 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5012 | assert(cb_access_context); |
| 5013 | if (!cb_access_context) return skip; |
| 5014 | |
| 5015 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5016 | assert(context); |
| 5017 | if (!context) return skip; |
| 5018 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5019 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5020 | |
| 5021 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5022 | const auto &range = pRanges[index]; |
| 5023 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5024 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5025 | if (hazard.hazard) { |
| 5026 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5027 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5028 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5029 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5030 | } |
| 5031 | } |
| 5032 | } |
| 5033 | return skip; |
| 5034 | } |
| 5035 | |
| 5036 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5037 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 5038 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5039 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5040 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5041 | assert(cb_access_context); |
| 5042 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 5043 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5044 | assert(context); |
| 5045 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5046 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5047 | |
| 5048 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5049 | const auto &range = pRanges[index]; |
| 5050 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5051 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5052 | } |
| 5053 | } |
| 5054 | } |
| 5055 | |
| 5056 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 5057 | VkImageLayout imageLayout, |
| 5058 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 5059 | const VkImageSubresourceRange *pRanges) const { |
| 5060 | bool skip = false; |
| 5061 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5062 | assert(cb_access_context); |
| 5063 | if (!cb_access_context) return skip; |
| 5064 | |
| 5065 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5066 | assert(context); |
| 5067 | if (!context) return skip; |
| 5068 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5069 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5070 | |
| 5071 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5072 | const auto &range = pRanges[index]; |
| 5073 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5074 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5075 | if (hazard.hazard) { |
| 5076 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5077 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5078 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5079 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5080 | } |
| 5081 | } |
| 5082 | } |
| 5083 | return skip; |
| 5084 | } |
| 5085 | |
| 5086 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5087 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 5088 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5089 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5090 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5091 | assert(cb_access_context); |
| 5092 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 5093 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5094 | assert(context); |
| 5095 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5096 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5097 | |
| 5098 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5099 | const auto &range = pRanges[index]; |
| 5100 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5101 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5102 | } |
| 5103 | } |
| 5104 | } |
| 5105 | |
| 5106 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 5107 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 5108 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 5109 | VkQueryResultFlags flags) const { |
| 5110 | bool skip = false; |
| 5111 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5112 | assert(cb_access_context); |
| 5113 | if (!cb_access_context) return skip; |
| 5114 | |
| 5115 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5116 | assert(context); |
| 5117 | if (!context) return skip; |
| 5118 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5119 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5120 | |
| 5121 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5122 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5123 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5124 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5125 | skip |= |
| 5126 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5127 | "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] | 5128 | 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] | 5129 | } |
| 5130 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5131 | |
| 5132 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5133 | return skip; |
| 5134 | } |
| 5135 | |
| 5136 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 5137 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5138 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5139 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 5140 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5141 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5142 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5143 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5144 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5145 | assert(context); |
| 5146 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5147 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5148 | |
| 5149 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5150 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5151 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5152 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5153 | |
| 5154 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5155 | } |
| 5156 | |
| 5157 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5158 | VkDeviceSize size, uint32_t data) const { |
| 5159 | bool skip = false; |
| 5160 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5161 | assert(cb_access_context); |
| 5162 | if (!cb_access_context) return skip; |
| 5163 | |
| 5164 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5165 | assert(context); |
| 5166 | if (!context) return skip; |
| 5167 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5168 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5169 | |
| 5170 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5171 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5172 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5173 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5174 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5175 | "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] | 5176 | 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] | 5177 | } |
| 5178 | } |
| 5179 | return skip; |
| 5180 | } |
| 5181 | |
| 5182 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5183 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5184 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5185 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5186 | assert(cb_access_context); |
| 5187 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 5188 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5189 | assert(context); |
| 5190 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5191 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5192 | |
| 5193 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5194 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5195 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5196 | } |
| 5197 | } |
| 5198 | |
| 5199 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 5200 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 5201 | const VkImageResolve *pRegions) const { |
| 5202 | bool skip = false; |
| 5203 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5204 | assert(cb_access_context); |
| 5205 | if (!cb_access_context) return skip; |
| 5206 | |
| 5207 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5208 | assert(context); |
| 5209 | if (!context) return skip; |
| 5210 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5211 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 5212 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5213 | |
| 5214 | for (uint32_t region = 0; region < regionCount; region++) { |
| 5215 | const auto &resolve_region = pRegions[region]; |
| 5216 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5217 | auto hazard = context->DetectHazard(*src_image, SYNC_RESOLVE_TRANSFER_READ, resolve_region.srcSubresource, |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5218 | resolve_region.srcOffset, resolve_region.extent); |
| 5219 | if (hazard.hazard) { |
| 5220 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5221 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5222 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5223 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5224 | } |
| 5225 | } |
| 5226 | |
| 5227 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5228 | auto hazard = context->DetectHazard(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, resolve_region.dstSubresource, |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5229 | resolve_region.dstOffset, resolve_region.extent); |
| 5230 | if (hazard.hazard) { |
| 5231 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5232 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5233 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5234 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5235 | } |
| 5236 | if (skip) break; |
| 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | return skip; |
| 5241 | } |
| 5242 | |
| 5243 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 5244 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 5245 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5246 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 5247 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5248 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5249 | assert(cb_access_context); |
| 5250 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 5251 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5252 | assert(context); |
| 5253 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 5254 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 5255 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5256 | |
| 5257 | for (uint32_t region = 0; region < regionCount; region++) { |
| 5258 | const auto &resolve_region = pRegions[region]; |
| 5259 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5260 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5261 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5262 | } |
| 5263 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5264 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5265 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5266 | } |
| 5267 | } |
| 5268 | } |
| 5269 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5270 | bool SyncValidator::ValidateCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2KHR *pResolveImageInfo, |
| 5271 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5272 | bool skip = false; |
| 5273 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5274 | assert(cb_access_context); |
| 5275 | if (!cb_access_context) return skip; |
| 5276 | |
| 5277 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5278 | assert(context); |
| 5279 | if (!context) return skip; |
| 5280 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5281 | const char *func_name = CommandTypeString(cmd_type); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5282 | auto src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 5283 | auto dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5284 | |
| 5285 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 5286 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 5287 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5288 | auto hazard = context->DetectHazard(*src_image, SYNC_RESOLVE_TRANSFER_READ, resolve_region.srcSubresource, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5289 | resolve_region.srcOffset, resolve_region.extent); |
| 5290 | if (hazard.hazard) { |
| 5291 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5292 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", func_name, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5293 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5294 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5295 | } |
| 5296 | } |
| 5297 | |
| 5298 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5299 | auto hazard = context->DetectHazard(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, resolve_region.dstSubresource, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5300 | resolve_region.dstOffset, resolve_region.extent); |
| 5301 | if (hazard.hazard) { |
| 5302 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5303 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", func_name, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5304 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5305 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5306 | } |
| 5307 | if (skip) break; |
| 5308 | } |
| 5309 | } |
| 5310 | |
| 5311 | return skip; |
| 5312 | } |
| 5313 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5314 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 5315 | const VkResolveImageInfo2KHR *pResolveImageInfo) const { |
| 5316 | return ValidateCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2KHR); |
| 5317 | } |
| 5318 | |
| 5319 | bool SyncValidator::PreCallValidateCmdResolveImage2(VkCommandBuffer commandBuffer, |
| 5320 | const VkResolveImageInfo2 *pResolveImageInfo) const { |
| 5321 | return ValidateCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2); |
| 5322 | } |
| 5323 | |
| 5324 | void SyncValidator::RecordCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2KHR *pResolveImageInfo, |
| 5325 | CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5326 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 5327 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5328 | assert(cb_access_context); |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5329 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5330 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5331 | assert(context); |
| 5332 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 5333 | auto src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 5334 | auto dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5335 | |
| 5336 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 5337 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 5338 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5339 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5340 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5341 | } |
| 5342 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5343 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5344 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5345 | } |
| 5346 | } |
| 5347 | } |
| 5348 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5349 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 5350 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 5351 | RecordCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2KHR); |
| 5352 | } |
| 5353 | |
| 5354 | void SyncValidator::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2 *pResolveImageInfo) { |
| 5355 | RecordCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2); |
| 5356 | } |
| 5357 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5358 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5359 | VkDeviceSize dataSize, const void *pData) const { |
| 5360 | bool skip = false; |
| 5361 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5362 | assert(cb_access_context); |
| 5363 | if (!cb_access_context) return skip; |
| 5364 | |
| 5365 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5366 | assert(context); |
| 5367 | if (!context) return skip; |
| 5368 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5369 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5370 | |
| 5371 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5372 | // VK_WHOLE_SIZE not allowed |
| 5373 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5374 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5375 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5376 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5377 | "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] | 5378 | 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] | 5379 | } |
| 5380 | } |
| 5381 | return skip; |
| 5382 | } |
| 5383 | |
| 5384 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5385 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5386 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5387 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5388 | assert(cb_access_context); |
| 5389 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 5390 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5391 | assert(context); |
| 5392 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5393 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5394 | |
| 5395 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5396 | // VK_WHOLE_SIZE not allowed |
| 5397 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5398 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5399 | } |
| 5400 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5401 | |
| 5402 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 5403 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 5404 | bool skip = false; |
| 5405 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5406 | assert(cb_access_context); |
| 5407 | if (!cb_access_context) return skip; |
| 5408 | |
| 5409 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5410 | assert(context); |
| 5411 | if (!context) return skip; |
| 5412 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5413 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5414 | |
| 5415 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5416 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5417 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5418 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5419 | skip |= |
| 5420 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5421 | "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] | 5422 | 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] | 5423 | } |
| 5424 | } |
| 5425 | return skip; |
| 5426 | } |
| 5427 | |
| 5428 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 5429 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5430 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5431 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5432 | assert(cb_access_context); |
| 5433 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 5434 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5435 | assert(context); |
| 5436 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5437 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5438 | |
| 5439 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5440 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5441 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5442 | } |
| 5443 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5444 | |
| 5445 | bool SyncValidator::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
| 5446 | bool skip = false; |
| 5447 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5448 | assert(cb_context); |
| 5449 | if (!cb_context) return skip; |
| 5450 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5451 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5452 | return set_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5453 | } |
| 5454 | |
| 5455 | void SyncValidator::PostCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 5456 | StateTracker::PostCallRecordCmdSetEvent(commandBuffer, event, stageMask); |
| 5457 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5458 | assert(cb_context); |
| 5459 | if (!cb_context) return; |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5460 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5461 | } |
| 5462 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5463 | bool SyncValidator::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5464 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 5465 | bool skip = false; |
| 5466 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5467 | assert(cb_context); |
| 5468 | if (!cb_context || !pDependencyInfo) return skip; |
| 5469 | |
| 5470 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 5471 | return set_event_op.Validate(*cb_context); |
| 5472 | } |
| 5473 | |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5474 | bool SyncValidator::PreCallValidateCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5475 | const VkDependencyInfo *pDependencyInfo) const { |
| 5476 | bool skip = false; |
| 5477 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5478 | assert(cb_context); |
| 5479 | if (!cb_context || !pDependencyInfo) return skip; |
| 5480 | |
| 5481 | SyncOpSetEvent set_event_op(CMD_SETEVENT2, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 5482 | return set_event_op.Validate(*cb_context); |
| 5483 | } |
| 5484 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5485 | void SyncValidator::PostCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5486 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 5487 | StateTracker::PostCallRecordCmdSetEvent2KHR(commandBuffer, event, pDependencyInfo); |
| 5488 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5489 | assert(cb_context); |
| 5490 | if (!cb_context || !pDependencyInfo) return; |
| 5491 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5492 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5495 | void SyncValidator::PostCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5496 | const VkDependencyInfo *pDependencyInfo) { |
| 5497 | StateTracker::PostCallRecordCmdSetEvent2(commandBuffer, event, pDependencyInfo); |
| 5498 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5499 | assert(cb_context); |
| 5500 | if (!cb_context || !pDependencyInfo) return; |
| 5501 | |
| 5502 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT2, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 5503 | } |
| 5504 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5505 | bool SyncValidator::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 5506 | VkPipelineStageFlags stageMask) const { |
| 5507 | bool skip = false; |
| 5508 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5509 | assert(cb_context); |
| 5510 | if (!cb_context) return skip; |
| 5511 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5512 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5513 | return reset_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | void SyncValidator::PostCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 5517 | StateTracker::PostCallRecordCmdResetEvent(commandBuffer, event, stageMask); |
| 5518 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5519 | assert(cb_context); |
| 5520 | if (!cb_context) return; |
| 5521 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5522 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5523 | } |
| 5524 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5525 | bool SyncValidator::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5526 | VkPipelineStageFlags2KHR stageMask) const { |
| 5527 | bool skip = false; |
| 5528 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5529 | assert(cb_context); |
| 5530 | if (!cb_context) return skip; |
| 5531 | |
| 5532 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5533 | return reset_event_op.Validate(*cb_context); |
| 5534 | } |
| 5535 | |
Tony-LunarG | a2662db | 2021-11-16 07:26:24 -0700 | [diff] [blame] | 5536 | bool SyncValidator::PreCallValidateCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5537 | VkPipelineStageFlags2 stageMask) const { |
| 5538 | bool skip = false; |
| 5539 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5540 | assert(cb_context); |
| 5541 | if (!cb_context) return skip; |
| 5542 | |
| 5543 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5544 | return reset_event_op.Validate(*cb_context); |
| 5545 | } |
| 5546 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5547 | void SyncValidator::PostCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5548 | VkPipelineStageFlags2KHR stageMask) { |
| 5549 | StateTracker::PostCallRecordCmdResetEvent2KHR(commandBuffer, event, stageMask); |
| 5550 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5551 | assert(cb_context); |
| 5552 | if (!cb_context) return; |
| 5553 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5554 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5555 | } |
| 5556 | |
Tony-LunarG | a2662db | 2021-11-16 07:26:24 -0700 | [diff] [blame] | 5557 | void SyncValidator::PostCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2 stageMask) { |
| 5558 | StateTracker::PostCallRecordCmdResetEvent2(commandBuffer, event, stageMask); |
| 5559 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5560 | assert(cb_context); |
| 5561 | if (!cb_context) return; |
| 5562 | |
| 5563 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT2, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5564 | } |
| 5565 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5566 | bool SyncValidator::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5567 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5568 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5569 | uint32_t bufferMemoryBarrierCount, |
| 5570 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5571 | uint32_t imageMemoryBarrierCount, |
| 5572 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 5573 | bool skip = false; |
| 5574 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5575 | assert(cb_context); |
| 5576 | if (!cb_context) return skip; |
| 5577 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5578 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 5579 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 5580 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5581 | return wait_events_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5582 | } |
| 5583 | |
| 5584 | void SyncValidator::PostCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5585 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5586 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5587 | uint32_t bufferMemoryBarrierCount, |
| 5588 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5589 | uint32_t imageMemoryBarrierCount, |
| 5590 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 5591 | StateTracker::PostCallRecordCmdWaitEvents(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
| 5592 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 5593 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 5594 | |
| 5595 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5596 | assert(cb_context); |
| 5597 | if (!cb_context) return; |
| 5598 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5599 | cb_context->RecordSyncOp<SyncOpWaitEvents>( |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 5600 | CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5601 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5602 | } |
| 5603 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5604 | bool SyncValidator::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5605 | const VkDependencyInfoKHR *pDependencyInfos) const { |
| 5606 | bool skip = false; |
| 5607 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5608 | assert(cb_context); |
| 5609 | if (!cb_context) return skip; |
| 5610 | |
| 5611 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 5612 | skip |= wait_events_op.Validate(*cb_context); |
| 5613 | return skip; |
| 5614 | } |
| 5615 | |
| 5616 | void SyncValidator::PostCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5617 | const VkDependencyInfoKHR *pDependencyInfos) { |
| 5618 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 5619 | |
| 5620 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5621 | assert(cb_context); |
| 5622 | if (!cb_context) return; |
| 5623 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5624 | cb_context->RecordSyncOp<SyncOpWaitEvents>(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, |
| 5625 | pDependencyInfos); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5626 | } |
| 5627 | |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 5628 | bool SyncValidator::PreCallValidateCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5629 | const VkDependencyInfo *pDependencyInfos) const { |
| 5630 | bool skip = false; |
| 5631 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5632 | assert(cb_context); |
| 5633 | if (!cb_context) return skip; |
| 5634 | |
| 5635 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 5636 | skip |= wait_events_op.Validate(*cb_context); |
| 5637 | return skip; |
| 5638 | } |
| 5639 | |
| 5640 | void SyncValidator::PostCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5641 | const VkDependencyInfo *pDependencyInfos) { |
| 5642 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 5643 | |
| 5644 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5645 | assert(cb_context); |
| 5646 | if (!cb_context) return; |
| 5647 | |
| 5648 | cb_context->RecordSyncOp<SyncOpWaitEvents>(CMD_WAITEVENTS2, *this, cb_context->GetQueueFlags(), eventCount, pEvents, |
| 5649 | pDependencyInfos); |
| 5650 | } |
| 5651 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5652 | void SyncEventState::ResetFirstScope() { |
| 5653 | for (const auto address_type : kAddressTypes) { |
| 5654 | first_scope[static_cast<size_t>(address_type)].clear(); |
| 5655 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 5656 | scope = SyncExecScope(); |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 5657 | first_scope_set = false; |
| 5658 | first_scope_tag = 0; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | // Keep the "ignore this event" logic in same place for ValidateWait and RecordWait to use |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5662 | SyncEventState::IgnoreReason SyncEventState::IsIgnoredByWait(CMD_TYPE cmd, VkPipelineStageFlags2KHR srcStageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5663 | IgnoreReason reason = NotIgnored; |
| 5664 | |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 5665 | if ((CMD_WAITEVENTS2KHR == cmd || CMD_WAITEVENTS2 == cmd) && (CMD_SETEVENT == last_command)) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5666 | reason = SetVsWait2; |
| 5667 | } else if ((last_command == CMD_RESETEVENT || last_command == CMD_RESETEVENT2KHR) && !HasBarrier(0U, 0U)) { |
| 5668 | reason = (last_command == CMD_RESETEVENT) ? ResetWaitRace : Reset2WaitRace; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5669 | } else if (unsynchronized_set) { |
| 5670 | reason = SetRace; |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 5671 | } else if (first_scope_set) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5672 | const VkPipelineStageFlags2KHR missing_bits = scope.mask_param & ~srcStageMask; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5673 | if (missing_bits) reason = MissingStageBits; |
| 5674 | } |
| 5675 | |
| 5676 | return reason; |
| 5677 | } |
| 5678 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5679 | bool SyncEventState::HasBarrier(VkPipelineStageFlags2KHR stageMask, VkPipelineStageFlags2KHR exec_scope_arg) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5680 | bool has_barrier = (last_command == CMD_NONE) || (stageMask & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) || |
| 5681 | (barriers & exec_scope_arg) || (barriers & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 5682 | return has_barrier; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5683 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5684 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 5685 | void SyncOpBase::SetReplayContext(uint32_t subpass, ReplayContextPtr &&replay) { |
| 5686 | subpass_ = subpass; |
| 5687 | replay_context_ = std::move(replay); |
| 5688 | } |
| 5689 | |
| 5690 | const ReplayTrackbackBarriersAction *SyncOpBase::GetReplayTrackback() const { |
| 5691 | if (replay_context_) { |
| 5692 | assert(subpass_ < replay_context_->subpass_contexts.size()); |
| 5693 | return &replay_context_->subpass_contexts[subpass_]; |
| 5694 | } |
| 5695 | return nullptr; |
| 5696 | } |
| 5697 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5698 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5699 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5700 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5701 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5702 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5703 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5704 | : SyncOpBase(cmd), barriers_(1) { |
| 5705 | auto &barrier_set = barriers_[0]; |
| 5706 | barrier_set.dependency_flags = dependencyFlags; |
| 5707 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, srcStageMask); |
| 5708 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, dstStageMask); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5709 | // 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] | 5710 | barrier_set.MakeMemoryBarriers(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, memoryBarrierCount, |
| 5711 | pMemoryBarriers); |
| 5712 | barrier_set.MakeBufferMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 5713 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
| 5714 | barrier_set.MakeImageMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 5715 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5716 | } |
| 5717 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5718 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t event_count, |
| 5719 | const VkDependencyInfoKHR *dep_infos) |
| 5720 | : SyncOpBase(cmd), barriers_(event_count) { |
| 5721 | for (uint32_t i = 0; i < event_count; i++) { |
| 5722 | const auto &dep_info = dep_infos[i]; |
| 5723 | auto &barrier_set = barriers_[i]; |
| 5724 | barrier_set.dependency_flags = dep_info.dependencyFlags; |
| 5725 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 5726 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, stage_masks.src); |
| 5727 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, stage_masks.dst); |
| 5728 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
| 5729 | barrier_set.MakeMemoryBarriers(queue_flags, dep_info.dependencyFlags, dep_info.memoryBarrierCount, |
| 5730 | dep_info.pMemoryBarriers); |
| 5731 | barrier_set.MakeBufferMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.bufferMemoryBarrierCount, |
| 5732 | dep_info.pBufferMemoryBarriers); |
| 5733 | barrier_set.MakeImageMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.imageMemoryBarrierCount, |
| 5734 | dep_info.pImageMemoryBarriers); |
| 5735 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5736 | } |
| 5737 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5738 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5739 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5740 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 5741 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5742 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5743 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5744 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5745 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers) {} |
| 5746 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5747 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5748 | const VkDependencyInfoKHR &dep_info) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5749 | : SyncOpBarriers(cmd, sync_state, queue_flags, 1, &dep_info) {} |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5750 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5751 | bool SyncOpPipelineBarrier::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5752 | bool skip = false; |
| 5753 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5754 | assert(context); |
| 5755 | if (!context) return skip; |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5756 | assert(barriers_.size() == 1); // PipelineBarriers only support a single barrier set. |
| 5757 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5758 | // Validate Image Layout transitions |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5759 | const auto &barrier_set = barriers_[0]; |
| 5760 | for (const auto &image_barrier : barrier_set.image_memory_barriers) { |
| 5761 | if (image_barrier.new_layout == image_barrier.old_layout) continue; // Only interested in layout transitions at this point. |
| 5762 | const auto *image_state = image_barrier.image.get(); |
| 5763 | if (!image_state) continue; |
| 5764 | const auto hazard = context->DetectImageBarrierHazard(image_barrier); |
| 5765 | if (hazard.hazard) { |
| 5766 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 5767 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5768 | const auto image_handle = image_state->image(); |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5769 | skip |= sync_state.LogError(image_handle, string_SyncHazardVUID(hazard.hazard), |
| 5770 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5771 | string_SyncHazard(hazard.hazard), image_barrier.index, |
| 5772 | sync_state.report_data->FormatHandle(image_handle).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5773 | cb_context.FormatHazard(hazard).c_str()); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5774 | } |
| 5775 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5776 | return skip; |
| 5777 | } |
| 5778 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5779 | struct SyncOpPipelineBarrierFunctorFactory { |
| 5780 | using BarrierOpFunctor = PipelineBarrierOp; |
| 5781 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5782 | using GlobalBarrierOpFunctor = PipelineBarrierOp; |
| 5783 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5784 | using BufferRange = ResourceAccessRange; |
| 5785 | using ImageRange = subresource_adapter::ImageRangeGenerator; |
| 5786 | using GlobalRange = ResourceAccessRange; |
| 5787 | |
| 5788 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier, bool layout_transition) const { |
| 5789 | return ApplyFunctor(BarrierOpFunctor(barrier, layout_transition)); |
| 5790 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 5791 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5792 | return GlobalApplyFunctor(true /* resolve */, size_hint, tag); |
| 5793 | } |
| 5794 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier) const { |
| 5795 | return GlobalBarrierOpFunctor(barrier, false); |
| 5796 | } |
| 5797 | |
| 5798 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range) const { |
| 5799 | if (!SimpleBinding(buffer)) return ResourceAccessRange(); |
| 5800 | const auto base_address = ResourceBaseAddress(buffer); |
| 5801 | return (range + base_address); |
| 5802 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5803 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 5804 | if (!SimpleBinding(image)) return subresource_adapter::ImageRangeGenerator(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5805 | |
| 5806 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5807 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5808 | return range_gen; |
| 5809 | } |
| 5810 | GlobalRange MakeGlobalRangeGen(AccessAddressType) const { return kFullRange; } |
| 5811 | }; |
| 5812 | |
| 5813 | template <typename Barriers, typename FunctorFactory> |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 5814 | void SyncOpBarriers::ApplyBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag tag, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5815 | AccessContext *context) { |
| 5816 | for (const auto &barrier : barriers) { |
| 5817 | const auto *state = barrier.GetState(); |
| 5818 | if (state) { |
| 5819 | auto *const accesses = &context->GetAccessStateMap(GetAccessAddressType(*state)); |
| 5820 | auto update_action = factory.MakeApplyFunctor(barrier.barrier, barrier.IsLayoutTransition()); |
| 5821 | auto range_gen = factory.MakeRangeGen(*state, barrier.Range()); |
| 5822 | UpdateMemoryAccessState(accesses, update_action, &range_gen); |
| 5823 | } |
| 5824 | } |
| 5825 | } |
| 5826 | |
| 5827 | template <typename Barriers, typename FunctorFactory> |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 5828 | void SyncOpBarriers::ApplyGlobalBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag tag, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5829 | AccessContext *access_context) { |
| 5830 | auto barriers_functor = factory.MakeGlobalApplyFunctor(barriers.size(), tag); |
| 5831 | for (const auto &barrier : barriers) { |
| 5832 | barriers_functor.EmplaceBack(factory.MakeGlobalBarrierOpFunctor(barrier)); |
| 5833 | } |
| 5834 | for (const auto address_type : kAddressTypes) { |
| 5835 | auto range_gen = factory.MakeGlobalRangeGen(address_type); |
| 5836 | UpdateMemoryAccessState(&(access_context->GetAccessStateMap(address_type)), barriers_functor, &range_gen); |
| 5837 | } |
| 5838 | } |
| 5839 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5840 | ResourceUsageTag SyncOpPipelineBarrier::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5841 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5842 | auto *events_context = cb_context->GetCurrentEventsContext(); |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5843 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 5844 | ReplayRecord(tag, access_context, events_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 5845 | return tag; |
| 5846 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5847 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 5848 | void SyncOpPipelineBarrier::ReplayRecord(const ResourceUsageTag tag, AccessContext *access_context, |
| 5849 | SyncEventsContext *events_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5850 | SyncOpPipelineBarrierFunctorFactory factory; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5851 | // Pipeline barriers only have a single barrier set, unlike WaitEvents2 |
| 5852 | assert(barriers_.size() == 1); |
| 5853 | const auto &barrier_set = barriers_[0]; |
| 5854 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5855 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5856 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5857 | if (barrier_set.single_exec_scope) { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5858 | events_context->ApplyBarrier(barrier_set.src_exec_scope, barrier_set.dst_exec_scope); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5859 | } else { |
| 5860 | for (const auto &barrier : barrier_set.memory_barriers) { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5861 | events_context->ApplyBarrier(barrier.src_exec_scope, barrier.dst_exec_scope); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5862 | } |
| 5863 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5866 | bool SyncOpPipelineBarrier::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 5867 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 5868 | // No Validation for replay, as the layout transition accesses are checked directly, and the src*Mask ordering is captured |
| 5869 | // with first access information. |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5870 | return false; |
| 5871 | } |
| 5872 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5873 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(const SyncExecScope &src, const SyncExecScope &dst, |
| 5874 | VkDependencyFlags dependency_flags, uint32_t memory_barrier_count, |
| 5875 | const VkMemoryBarrier *barriers) { |
| 5876 | memory_barriers.reserve(std::max<uint32_t>(1, memory_barrier_count)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5877 | 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] | 5878 | const auto &barrier = barriers[barrier_index]; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5879 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5880 | memory_barriers.emplace_back(sync_barrier); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5881 | } |
| 5882 | if (0 == memory_barrier_count) { |
| 5883 | // If there are no global memory barriers, force an exec barrier |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5884 | memory_barriers.emplace_back(SyncBarrier(src, dst)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5885 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5886 | single_exec_scope = true; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5887 | } |
| 5888 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5889 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5890 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5891 | uint32_t barrier_count, const VkBufferMemoryBarrier *barriers) { |
| 5892 | buffer_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5893 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5894 | const auto &barrier = barriers[index]; |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 5895 | auto buffer = sync_state.Get<BUFFER_STATE>(barrier.buffer); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5896 | if (buffer) { |
| 5897 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5898 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5899 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5900 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5901 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5902 | buffer_memory_barriers.emplace_back(); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5903 | } |
| 5904 | } |
| 5905 | } |
| 5906 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5907 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(VkQueueFlags queue_flags, VkDependencyFlags dependency_flags, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 5908 | uint32_t memory_barrier_count, const VkMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5909 | memory_barriers.reserve(memory_barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5910 | 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] | 5911 | const auto &barrier = barriers[barrier_index]; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5912 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5913 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5914 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5915 | memory_barriers.emplace_back(sync_barrier); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5916 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5917 | single_exec_scope = false; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5920 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5921 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 5922 | const VkBufferMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5923 | buffer_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5924 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5925 | const auto &barrier = barriers[index]; |
| 5926 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5927 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 5928 | auto buffer = sync_state.Get<BUFFER_STATE>(barrier.buffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5929 | if (buffer) { |
| 5930 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5931 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5932 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5933 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5934 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5935 | buffer_memory_barriers.emplace_back(); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5936 | } |
| 5937 | } |
| 5938 | } |
| 5939 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5940 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5941 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5942 | uint32_t barrier_count, const VkImageMemoryBarrier *barriers) { |
| 5943 | image_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5944 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5945 | const auto &barrier = barriers[index]; |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5946 | auto image = sync_state.Get<IMAGE_STATE>(barrier.image); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5947 | if (image) { |
| 5948 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5949 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5950 | 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] | 5951 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5952 | image_memory_barriers.emplace_back(); |
| 5953 | 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] | 5954 | } |
| 5955 | } |
| 5956 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5957 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5958 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5959 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 5960 | const VkImageMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5961 | image_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5962 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5963 | const auto &barrier = barriers[index]; |
| 5964 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5965 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5966 | auto image = sync_state.Get<IMAGE_STATE>(barrier.image); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5967 | if (image) { |
| 5968 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5969 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5970 | 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] | 5971 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5972 | image_memory_barriers.emplace_back(); |
| 5973 | 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] | 5974 | } |
| 5975 | } |
| 5976 | } |
| 5977 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5978 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t eventCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5979 | const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5980 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5981 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5982 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5983 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, VkDependencyFlags(0U), memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5984 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 5985 | pImageMemoryBarriers) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5986 | MakeEventsList(sync_state, eventCount, pEvents); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5987 | } |
| 5988 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5989 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t eventCount, |
| 5990 | const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfo) |
| 5991 | : SyncOpBarriers(cmd, sync_state, queue_flags, eventCount, pDependencyInfo) { |
| 5992 | MakeEventsList(sync_state, eventCount, pEvents); |
| 5993 | assert(events_.size() == barriers_.size()); // Just so nobody gets clever and decides to cull the event or barrier arrays |
| 5994 | } |
| 5995 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 5996 | const char *const SyncOpWaitEvents::kIgnored = "Wait operation is ignored for this event."; |
| 5997 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5998 | bool SyncOpWaitEvents::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5999 | bool skip = false; |
| 6000 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6001 | const auto command_buffer_handle = cb_context.GetCBState().commandBuffer(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6002 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6003 | // This is only interesting at record and not replay (Execute/Submit) time. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6004 | for (size_t barrier_set_index = 0; barrier_set_index < barriers_.size(); barrier_set_index++) { |
| 6005 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6006 | if (barrier_set.single_exec_scope) { |
| 6007 | if (barrier_set.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 6008 | const std::string vuid = std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 6009 | skip = sync_state.LogInfo(command_buffer_handle, vuid, |
| 6010 | "%s, srcStageMask includes %s, unsupported by synchronization validation.", CmdName(), |
| 6011 | string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT)); |
| 6012 | } else { |
| 6013 | const auto &barriers = barrier_set.memory_barriers; |
| 6014 | for (size_t barrier_index = 0; barrier_index < barriers.size(); barrier_index++) { |
| 6015 | const auto &barrier = barriers[barrier_index]; |
| 6016 | if (barrier.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 6017 | const std::string vuid = |
| 6018 | std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 6019 | skip = |
| 6020 | sync_state.LogInfo(command_buffer_handle, vuid, |
| 6021 | "%s, srcStageMask %s of %s %zu, %s %zu, unsupported by synchronization validation.", |
| 6022 | CmdName(), string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT), |
| 6023 | "pDependencyInfo", barrier_set_index, "pMemoryBarriers", barrier_index); |
| 6024 | } |
| 6025 | } |
| 6026 | } |
| 6027 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6028 | } |
| 6029 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6030 | // The rest is common to record time and replay time. |
| 6031 | skip |= DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6032 | return skip; |
| 6033 | } |
| 6034 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6035 | bool SyncOpWaitEvents::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6036 | bool skip = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6037 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6038 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6039 | VkPipelineStageFlags2KHR event_stage_masks = 0U; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6040 | VkPipelineStageFlags2KHR barrier_mask_params = 0U; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6041 | bool events_not_found = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6042 | const auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6043 | assert(events_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6044 | size_t barrier_set_index = 0; |
| 6045 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6046 | for (const auto &event : events_) { |
| 6047 | const auto *sync_event = events_context->Get(event.get()); |
| 6048 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6049 | if (!sync_event) { |
| 6050 | // NOTE PHASE2: This is where we'll need queue submit time validation to come back and check the srcStageMask bits |
| 6051 | // or solve this with replay creating the SyncEventState in the queue context... also this will be a |
| 6052 | // new validation error... wait without previously submitted set event... |
| 6053 | 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] | 6054 | barrier_set_index += barrier_set_incr; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6055 | continue; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6056 | } |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6057 | |
| 6058 | // For replay calls, don't revalidate "same command buffer" events |
| 6059 | if (sync_event->last_command_tag > base_tag) continue; |
| 6060 | |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6061 | const auto event_handle = sync_event->event->event(); |
| 6062 | // TODO add "destroyed" checks |
| 6063 | |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6064 | if (sync_event->first_scope_set) { |
| 6065 | // Only accumulate barrier and event stages if there is a pending set in the current context |
| 6066 | barrier_mask_params |= barrier_set.src_exec_scope.mask_param; |
| 6067 | event_stage_masks |= sync_event->scope.mask_param; |
| 6068 | } |
| 6069 | |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6070 | const auto &src_exec_scope = barrier_set.src_exec_scope; |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6071 | |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6072 | const auto ignore_reason = sync_event->IsIgnoredByWait(cmd_, src_exec_scope.mask_param); |
| 6073 | if (ignore_reason) { |
| 6074 | switch (ignore_reason) { |
| 6075 | case SyncEventState::ResetWaitRace: |
| 6076 | case SyncEventState::Reset2WaitRace: { |
| 6077 | // Four permuations of Reset and Wait calls... |
| 6078 | const char *vuid = |
| 6079 | (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent-event-03834" : "VUID-vkCmdResetEvent-event-03835"; |
| 6080 | if (ignore_reason == SyncEventState::Reset2WaitRace) { |
Tony-LunarG | 279601c | 2021-11-16 10:50:51 -0700 | [diff] [blame] | 6081 | vuid = (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent2-event-03831" |
| 6082 | : "VUID-vkCmdResetEvent2-event-03832"; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6083 | } |
| 6084 | const char *const message = |
| 6085 | "%s: %s %s operation following %s without intervening execution barrier, may cause race condition. %s"; |
| 6086 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6087 | sync_state.report_data->FormatHandle(event_handle).c_str(), CmdName(), |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6088 | CommandTypeString(sync_event->last_command), kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6089 | break; |
| 6090 | } |
| 6091 | case SyncEventState::SetRace: { |
| 6092 | // Issue error message that Wait is waiting on an signal subject to race condition, and is thus ignored for |
| 6093 | // this event |
| 6094 | const char *const vuid = "SYNC-vkCmdWaitEvents-unsynchronized-setops"; |
| 6095 | const char *const message = |
| 6096 | "%s: %s Unsychronized %s calls result in race conditions w.r.t. event signalling, %s %s"; |
| 6097 | const char *const reason = "First synchronization scope is undefined."; |
| 6098 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6099 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6100 | CommandTypeString(sync_event->last_command), reason, kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6101 | break; |
| 6102 | } |
| 6103 | case SyncEventState::MissingStageBits: { |
| 6104 | const auto missing_bits = sync_event->scope.mask_param & ~src_exec_scope.mask_param; |
| 6105 | // Issue error message that event waited for is not in wait events scope |
| 6106 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 6107 | const char *const message = "%s: %s stageMask %" PRIx64 " includes bits not present in srcStageMask 0x%" PRIx64 |
| 6108 | ". Bits missing from srcStageMask %s. %s"; |
| 6109 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6110 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 6111 | sync_event->scope.mask_param, src_exec_scope.mask_param, |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6112 | sync_utils::StringPipelineStageFlags(missing_bits).c_str(), kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6113 | break; |
| 6114 | } |
| 6115 | case SyncEventState::SetVsWait2: { |
Tony-LunarG | 279601c | 2021-11-16 10:50:51 -0700 | [diff] [blame] | 6116 | skip |= sync_state.LogError(event_handle, "VUID-vkCmdWaitEvents2-pEvents-03837", |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6117 | "%s: Follows set of %s by %s. Disallowed.", CmdName(), |
| 6118 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 6119 | CommandTypeString(sync_event->last_command)); |
| 6120 | break; |
| 6121 | } |
| 6122 | default: |
| 6123 | assert(ignore_reason == SyncEventState::NotIgnored); |
| 6124 | } |
| 6125 | } else if (barrier_set.image_memory_barriers.size()) { |
| 6126 | const auto &image_memory_barriers = barrier_set.image_memory_barriers; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6127 | const auto *context = exec_context.GetCurrentAccessContext(); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6128 | assert(context); |
| 6129 | for (const auto &image_memory_barrier : image_memory_barriers) { |
| 6130 | if (image_memory_barrier.old_layout == image_memory_barrier.new_layout) continue; |
| 6131 | const auto *image_state = image_memory_barrier.image.get(); |
| 6132 | if (!image_state) continue; |
| 6133 | const auto &subresource_range = image_memory_barrier.range; |
| 6134 | const auto &src_access_scope = image_memory_barrier.barrier.src_access_scope; |
| 6135 | const auto hazard = |
| 6136 | context->DetectImageBarrierHazard(*image_state, sync_event->scope.exec_scope, src_access_scope, |
| 6137 | subresource_range, *sync_event, AccessContext::DetectOptions::kDetectAll); |
| 6138 | if (hazard.hazard) { |
| 6139 | skip |= sync_state.LogError(image_state->image(), string_SyncHazardVUID(hazard.hazard), |
| 6140 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 6141 | string_SyncHazard(hazard.hazard), image_memory_barrier.index, |
| 6142 | sync_state.report_data->FormatHandle(image_state->image()).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6143 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6144 | break; |
| 6145 | } |
| 6146 | } |
| 6147 | } |
| 6148 | // TODO: Add infrastructure for checking pDependencyInfo's vs. CmdSetEvent2 VUID - vkCmdWaitEvents2KHR - pEvents - |
| 6149 | // 03839 |
| 6150 | barrier_set_index += barrier_set_incr; |
| 6151 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6152 | |
| 6153 | // 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] | 6154 | 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] | 6155 | if (extra_stage_bits) { |
| 6156 | // 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] | 6157 | // NOTE: This isn't exactly the right VUID for WaitEvents2, but it's as close as we currently have support for |
| 6158 | const char *const vuid = |
Tony-LunarG | 279601c | 2021-11-16 10:50:51 -0700 | [diff] [blame] | 6159 | (CMD_WAITEVENTS == cmd_) ? "VUID-vkCmdWaitEvents-srcStageMask-01158" : "VUID-vkCmdWaitEvents2-pEvents-03838"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6160 | const char *const message = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6161 | "%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] | 6162 | const auto handle = exec_context.Handle(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6163 | if (events_not_found) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6164 | skip |= sync_state.LogInfo(handle, vuid, message, CmdName(), barrier_mask_params, |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6165 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6166 | " vkCmdSetEvent may be in previously submitted command buffer."); |
| 6167 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6168 | skip |= sync_state.LogError(handle, vuid, message, CmdName(), barrier_mask_params, |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6169 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), ""); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6170 | } |
| 6171 | } |
| 6172 | return skip; |
| 6173 | } |
| 6174 | |
| 6175 | struct SyncOpWaitEventsFunctorFactory { |
| 6176 | using BarrierOpFunctor = WaitEventBarrierOp; |
| 6177 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 6178 | using GlobalBarrierOpFunctor = WaitEventBarrierOp; |
| 6179 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 6180 | using BufferRange = EventSimpleRangeGenerator; |
| 6181 | using ImageRange = EventImageRangeGenerator; |
| 6182 | using GlobalRange = EventSimpleRangeGenerator; |
| 6183 | |
| 6184 | // Need to restrict to only valid exec and access scope for this event |
| 6185 | // Pass by value is intentional to get a copy we can change without modifying the passed barrier |
| 6186 | SyncBarrier RestrictToEvent(SyncBarrier barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 6187 | 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] | 6188 | barrier.src_access_scope = sync_event->scope.valid_accesses & barrier.src_access_scope; |
| 6189 | return barrier; |
| 6190 | } |
| 6191 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier_arg, bool layout_transition) const { |
| 6192 | auto barrier = RestrictToEvent(barrier_arg); |
| 6193 | return ApplyFunctor(BarrierOpFunctor(sync_event->first_scope_tag, barrier, layout_transition)); |
| 6194 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 6195 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6196 | return GlobalApplyFunctor(false /* don't resolve */, size_hint, tag); |
| 6197 | } |
| 6198 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier_arg) const { |
| 6199 | auto barrier = RestrictToEvent(barrier_arg); |
| 6200 | return GlobalBarrierOpFunctor(sync_event->first_scope_tag, barrier, false); |
| 6201 | } |
| 6202 | |
| 6203 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range_arg) const { |
| 6204 | const AccessAddressType address_type = GetAccessAddressType(buffer); |
| 6205 | const auto base_address = ResourceBaseAddress(buffer); |
| 6206 | ResourceAccessRange range = SimpleBinding(buffer) ? (range_arg + base_address) : ResourceAccessRange(); |
| 6207 | EventSimpleRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), range); |
| 6208 | return filtered_range_gen; |
| 6209 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 6210 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6211 | if (!SimpleBinding(image)) return ImageRange(); |
| 6212 | const auto address_type = GetAccessAddressType(image); |
| 6213 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 6214 | subresource_adapter::ImageRangeGenerator image_range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6215 | EventImageRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), image_range_gen); |
| 6216 | |
| 6217 | return filtered_range_gen; |
| 6218 | } |
| 6219 | GlobalRange MakeGlobalRangeGen(AccessAddressType address_type) const { |
| 6220 | return EventSimpleRangeGenerator(sync_event->FirstScope(address_type), kFullRange); |
| 6221 | } |
| 6222 | SyncOpWaitEventsFunctorFactory(SyncEventState *sync_event_) : sync_event(sync_event_) { assert(sync_event); } |
| 6223 | SyncEventState *sync_event; |
| 6224 | }; |
| 6225 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6226 | ResourceUsageTag SyncOpWaitEvents::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 6227 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6228 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 6229 | assert(access_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6230 | if (!access_context) return tag; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6231 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 6232 | assert(events_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6233 | if (!events_context) return tag; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6234 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6235 | ReplayRecord(tag, access_context, events_context); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6236 | return tag; |
| 6237 | } |
| 6238 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6239 | void SyncOpWaitEvents::ReplayRecord(ResourceUsageTag tag, AccessContext *access_context, SyncEventsContext *events_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6240 | // Unlike PipelineBarrier, WaitEvent is *not* limited to accesses within the current subpass (if any) and thus needs to import |
| 6241 | // all accesses. Can instead import for all first_scopes, or a union of them, if this becomes a performance/memory issue, |
| 6242 | // but with no idea of the performance of the union, nor of whether it even matters... take the simplest approach here, |
| 6243 | access_context->ResolvePreviousAccesses(); |
| 6244 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6245 | size_t barrier_set_index = 0; |
| 6246 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 6247 | assert(barriers_.size() == 1 || (barriers_.size() == events_.size())); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6248 | for (auto &event_shared : events_) { |
| 6249 | if (!event_shared.get()) continue; |
| 6250 | auto *sync_event = events_context->GetFromShared(event_shared); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6251 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6252 | sync_event->last_command = cmd_; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6253 | sync_event->last_command_tag = tag; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6254 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6255 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6256 | const auto &dst = barrier_set.dst_exec_scope; |
| 6257 | if (!sync_event->IsIgnoredByWait(cmd_, barrier_set.src_exec_scope.mask_param)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6258 | // These apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 6259 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 6260 | // of the barriers is maintained. |
| 6261 | SyncOpWaitEventsFunctorFactory factory(sync_event); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6262 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 6263 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 6264 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6265 | |
| 6266 | // Apply the global barrier to the event itself (for race condition tracking) |
| 6267 | // Events don't happen at a stage, so we need to store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 6268 | sync_event->barriers = dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 6269 | sync_event->barriers |= dst.exec_scope; |
| 6270 | } else { |
| 6271 | // We ignored this wait, so we don't have any effective synchronization barriers for it. |
| 6272 | sync_event->barriers = 0U; |
| 6273 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6274 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6275 | } |
| 6276 | |
| 6277 | // Apply the pending barriers |
| 6278 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
| 6279 | access_context->ApplyToContext(apply_pending_action); |
| 6280 | } |
| 6281 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6282 | bool SyncOpWaitEvents::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6283 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
| 6284 | return DoValidate(*exec_context, base_tag); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6285 | } |
| 6286 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6287 | bool SyncValidator::PreCallValidateCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 6288 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 6289 | bool skip = false; |
| 6290 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 6291 | assert(cb_access_context); |
| 6292 | if (!cb_access_context) return skip; |
| 6293 | |
| 6294 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 6295 | assert(context); |
| 6296 | if (!context) return skip; |
| 6297 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6298 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6299 | |
| 6300 | if (dst_buffer) { |
| 6301 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 6302 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
| 6303 | if (hazard.hazard) { |
| 6304 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 6305 | "vkCmdWriteBufferMarkerAMD2: Hazard %s for dstBuffer %s. Access info %s.", |
| 6306 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6307 | cb_access_context->FormatHazard(hazard).c_str()); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6308 | } |
| 6309 | } |
| 6310 | return skip; |
| 6311 | } |
| 6312 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6313 | 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] | 6314 | events_.reserve(event_count); |
| 6315 | for (uint32_t event_index = 0; event_index < event_count; event_index++) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6316 | events_.emplace_back(sync_state.Get<EVENT_STATE>(events[event_index])); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6317 | } |
| 6318 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6319 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 6320 | SyncOpResetEvent::SyncOpResetEvent(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6321 | VkPipelineStageFlags2KHR stageMask) |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6322 | : SyncOpBase(cmd), event_(sync_state.Get<EVENT_STATE>(event)), exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6323 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6324 | bool SyncOpResetEvent::Validate(const CommandBufferAccessContext& cb_context) const { |
| 6325 | return DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6326 | } |
| 6327 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6328 | bool SyncOpResetEvent::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
| 6329 | auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6330 | assert(events_context); |
| 6331 | bool skip = false; |
| 6332 | if (!events_context) return skip; |
| 6333 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6334 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6335 | const auto *sync_event = events_context->Get(event_); |
| 6336 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 6337 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6338 | if (sync_event->last_command_tag > base_tag) return skip; // if we validated this in recording of the secondary, don't repeat |
| 6339 | |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6340 | const char *const set_wait = |
| 6341 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 6342 | "hazards."; |
| 6343 | const char *message = set_wait; // Only one message this call. |
| 6344 | if (!sync_event->HasBarrier(exec_scope_.mask_param, exec_scope_.exec_scope)) { |
| 6345 | const char *vuid = nullptr; |
| 6346 | switch (sync_event->last_command) { |
| 6347 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6348 | case CMD_SETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6349 | case CMD_SETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6350 | // Needs a barrier between set and reset |
| 6351 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-set"; |
| 6352 | break; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6353 | case CMD_WAITEVENTS: |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 6354 | case CMD_WAITEVENTS2: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6355 | case CMD_WAITEVENTS2KHR: { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6356 | // Needs to be in the barriers chain (either because of a barrier, or because of dstStageMask |
| 6357 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-wait"; |
| 6358 | break; |
| 6359 | } |
| 6360 | default: |
| 6361 | // The only other valid last command that wasn't one. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6362 | assert((sync_event->last_command == CMD_NONE) || (sync_event->last_command == CMD_RESETEVENT) || |
| 6363 | (sync_event->last_command == CMD_RESETEVENT2KHR)); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6364 | break; |
| 6365 | } |
| 6366 | if (vuid) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6367 | skip |= sync_state.LogError(event_->event(), vuid, message, CmdName(), |
| 6368 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6369 | CommandTypeString(sync_event->last_command)); |
| 6370 | } |
| 6371 | } |
| 6372 | return skip; |
| 6373 | } |
| 6374 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6375 | ResourceUsageTag SyncOpResetEvent::Record(CommandBufferAccessContext *cb_context) const { |
| 6376 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6377 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 6378 | assert(events_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6379 | if (!events_context) return tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6380 | |
| 6381 | auto *sync_event = events_context->GetFromShared(event_); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6382 | if (!sync_event) return tag; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6383 | |
| 6384 | // Update the event state |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 6385 | sync_event->last_command = cmd_; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6386 | sync_event->last_command_tag = tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6387 | sync_event->unsynchronized_set = CMD_NONE; |
| 6388 | sync_event->ResetFirstScope(); |
| 6389 | sync_event->barriers = 0U; |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6390 | |
| 6391 | return tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6392 | } |
| 6393 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6394 | bool SyncOpResetEvent::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6395 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
| 6396 | return DoValidate(*exec_context, base_tag); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6397 | } |
| 6398 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6399 | void SyncOpResetEvent::ReplayRecord(ResourceUsageTag tag, AccessContext *access_context, SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6400 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 6401 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6402 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 6403 | : SyncOpBase(cmd), |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6404 | event_(sync_state.Get<EVENT_STATE>(event)), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6405 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)), |
| 6406 | dep_info_() {} |
| 6407 | |
| 6408 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
| 6409 | const VkDependencyInfoKHR &dep_info) |
| 6410 | : SyncOpBase(cmd), |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6411 | event_(sync_state.Get<EVENT_STATE>(event)), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6412 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, sync_utils::GetGlobalStageMasks(dep_info).src)), |
Tony-LunarG | 273f32f | 2021-09-28 08:56:30 -0600 | [diff] [blame] | 6413 | dep_info_(new safe_VkDependencyInfo(&dep_info)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6414 | |
| 6415 | bool SyncOpSetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6416 | return DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6417 | } |
| 6418 | bool SyncOpSetEvent::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6419 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
| 6420 | assert(exec_context); |
| 6421 | return DoValidate(*exec_context, base_tag); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6422 | } |
| 6423 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6424 | bool SyncOpSetEvent::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6425 | bool skip = false; |
| 6426 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6427 | const auto &sync_state = exec_context.GetSyncState(); |
| 6428 | auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6429 | assert(events_context); |
| 6430 | if (!events_context) return skip; |
| 6431 | |
| 6432 | const auto *sync_event = events_context->Get(event_); |
| 6433 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 6434 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6435 | if (sync_event->last_command_tag >= base_tag) return skip; // for replay we don't want to revalidate internal "last commmand" |
| 6436 | |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6437 | const char *const reset_set = |
| 6438 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 6439 | "hazards."; |
| 6440 | const char *const wait = |
| 6441 | "%s: %s %s operation following %s without intervening vkCmdResetEvent, may result in data hazard and is ignored."; |
| 6442 | |
| 6443 | 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] | 6444 | const char *vuid_stem = nullptr; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6445 | const char *message = nullptr; |
| 6446 | switch (sync_event->last_command) { |
| 6447 | case CMD_RESETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6448 | case CMD_RESETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6449 | case CMD_RESETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6450 | // Needs a barrier between reset and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6451 | vuid_stem = "-missingbarrier-reset"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6452 | message = reset_set; |
| 6453 | break; |
| 6454 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6455 | case CMD_SETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6456 | case CMD_SETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6457 | // Needs a barrier between set and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6458 | vuid_stem = "-missingbarrier-set"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6459 | message = reset_set; |
| 6460 | break; |
| 6461 | case CMD_WAITEVENTS: |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 6462 | case CMD_WAITEVENTS2: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6463 | case CMD_WAITEVENTS2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6464 | // Needs a barrier or is in second execution scope |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6465 | vuid_stem = "-missingbarrier-wait"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6466 | message = wait; |
| 6467 | break; |
| 6468 | default: |
| 6469 | // The only other valid last command that wasn't one. |
| 6470 | assert(sync_event->last_command == CMD_NONE); |
| 6471 | break; |
| 6472 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6473 | if (vuid_stem) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6474 | assert(nullptr != message); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6475 | std::string vuid("SYNC-"); |
| 6476 | vuid.append(CmdName()).append(vuid_stem); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6477 | skip |= sync_state.LogError(event_->event(), vuid.c_str(), message, CmdName(), |
| 6478 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6479 | CommandTypeString(sync_event->last_command)); |
| 6480 | } |
| 6481 | } |
| 6482 | |
| 6483 | return skip; |
| 6484 | } |
| 6485 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6486 | ResourceUsageTag SyncOpSetEvent::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 6487 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6488 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 6489 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 6490 | assert(events_context); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6491 | if (access_context && events_context) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6492 | ReplayRecord(tag, access_context, events_context); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6493 | } |
| 6494 | return tag; |
| 6495 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6496 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6497 | void SyncOpSetEvent::ReplayRecord(ResourceUsageTag tag, AccessContext *access_context, SyncEventsContext *events_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6498 | auto *sync_event = events_context->GetFromShared(event_); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6499 | 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] | 6500 | |
| 6501 | // NOTE: We're going to simply record the sync scope here, as anything else would be implementation defined/undefined |
| 6502 | // and we're issuing errors re: missing barriers between event commands, which if the user fixes would fix |
| 6503 | // any issues caused by naive scope setting here. |
| 6504 | |
| 6505 | // What happens with two SetEvent is that one cannot know what group of operations will be waited for. |
| 6506 | // Given: |
| 6507 | // Stuff1; SetEvent; Stuff2; SetEvent; WaitEvents; |
| 6508 | // WaitEvents cannot know which of Stuff1, Stuff2, or both has completed execution. |
| 6509 | |
| 6510 | if (!sync_event->HasBarrier(src_exec_scope_.mask_param, src_exec_scope_.exec_scope)) { |
| 6511 | sync_event->unsynchronized_set = sync_event->last_command; |
| 6512 | sync_event->ResetFirstScope(); |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6513 | } else if (!sync_event->first_scope_set) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6514 | // We only set the scope if there isn't one |
| 6515 | sync_event->scope = src_exec_scope_; |
| 6516 | |
| 6517 | auto set_scope = [&sync_event](AccessAddressType address_type, const ResourceAccessRangeMap::value_type &access) { |
| 6518 | auto &scope_map = sync_event->first_scope[static_cast<size_t>(address_type)]; |
| 6519 | if (access.second.InSourceScopeOrChain(sync_event->scope.exec_scope, sync_event->scope.valid_accesses)) { |
| 6520 | scope_map.insert(scope_map.end(), std::make_pair(access.first, true)); |
| 6521 | } |
| 6522 | }; |
| 6523 | access_context->ForAll(set_scope); |
| 6524 | sync_event->unsynchronized_set = CMD_NONE; |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6525 | sync_event->first_scope_set = true; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6526 | sync_event->first_scope_tag = tag; |
| 6527 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6528 | // TODO: Store dep_info_ shared ptr in sync_state for WaitEvents2 validation |
| 6529 | sync_event->last_command = cmd_; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6530 | sync_event->last_command_tag = tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6531 | sync_event->barriers = 0U; |
| 6532 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6533 | |
| 6534 | SyncOpBeginRenderPass::SyncOpBeginRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, |
| 6535 | const VkRenderPassBeginInfo *pRenderPassBegin, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 6536 | const VkSubpassBeginInfo *pSubpassBeginInfo) |
| 6537 | : SyncOpBase(cmd) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6538 | if (pRenderPassBegin) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6539 | rp_state_ = sync_state.Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6540 | renderpass_begin_info_ = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6541 | auto fb_state = sync_state.Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6542 | if (fb_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6543 | shared_attachments_ = sync_state.GetAttachmentViews(*renderpass_begin_info_.ptr(), *fb_state); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6544 | // TODO: Revisit this when all attachment validation is through SyncOps to see if we can discard the plain pointer copy |
| 6545 | // Note that this a safe to presist as long as shared_attachments is not cleared |
| 6546 | attachments_.reserve(shared_attachments_.size()); |
sfricke-samsung | 01c9ae9 | 2021-02-09 22:30:52 -0800 | [diff] [blame] | 6547 | for (const auto &attachment : shared_attachments_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6548 | attachments_.emplace_back(attachment.get()); |
| 6549 | } |
| 6550 | } |
| 6551 | if (pSubpassBeginInfo) { |
| 6552 | subpass_begin_info_ = safe_VkSubpassBeginInfo(pSubpassBeginInfo); |
| 6553 | } |
| 6554 | } |
| 6555 | } |
| 6556 | |
| 6557 | bool SyncOpBeginRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6558 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 6559 | bool skip = false; |
| 6560 | |
| 6561 | assert(rp_state_.get()); |
| 6562 | if (nullptr == rp_state_.get()) return skip; |
| 6563 | auto &rp_state = *rp_state_.get(); |
| 6564 | |
| 6565 | const uint32_t subpass = 0; |
| 6566 | |
| 6567 | // Construct the state we can use to validate against... (since validation is const and RecordCmdBeginRenderPass |
| 6568 | // hasn't happened yet) |
| 6569 | const std::vector<AccessContext> empty_context_vector; |
| 6570 | AccessContext temp_context(subpass, cb_context.GetQueueFlags(), rp_state.subpass_dependencies, empty_context_vector, |
| 6571 | cb_context.GetCurrentAccessContext()); |
| 6572 | |
| 6573 | // Validate attachment operations |
| 6574 | if (attachments_.size() == 0) return skip; |
| 6575 | const auto &render_area = renderpass_begin_info_.renderArea; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 6576 | |
| 6577 | // Since the isn't a valid RenderPassAccessContext until Record, needs to create the view/generator list... we could limit this |
| 6578 | // by predicating on whether subpass 0 uses the attachment if it is too expensive to create the full list redundantly here. |
| 6579 | // More broadly we could look at thread specific state shared between Validate and Record as is done for other heavyweight |
| 6580 | // operations (though it's currently a messy approach) |
| 6581 | AttachmentViewGenVector view_gens = RenderPassAccessContext::CreateAttachmentViewGen(render_area, attachments_); |
| 6582 | skip |= temp_context.ValidateLayoutTransitions(cb_context, rp_state, render_area, subpass, view_gens, CmdName()); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6583 | |
| 6584 | // Validate load operations if there were no layout transition hazards |
| 6585 | if (!skip) { |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 6586 | temp_context.RecordLayoutTransitions(rp_state, subpass, view_gens, kInvalidTag); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 6587 | skip |= temp_context.ValidateLoadOperation(cb_context, rp_state, render_area, subpass, view_gens, CmdName()); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6588 | } |
| 6589 | |
| 6590 | return skip; |
| 6591 | } |
| 6592 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6593 | ResourceUsageTag SyncOpBeginRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6594 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 6595 | assert(rp_state_.get()); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 6596 | if (nullptr == rp_state_.get()) return cb_context->NextCommandTag(cmd_); |
| 6597 | return cb_context->RecordBeginRenderPass(cmd_, *rp_state_.get(), renderpass_begin_info_.renderArea, attachments_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6598 | } |
| 6599 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6600 | bool SyncOpBeginRenderPass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6601 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6602 | return false; |
| 6603 | } |
| 6604 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6605 | void SyncOpBeginRenderPass::ReplayRecord(ResourceUsageTag tag, AccessContext *access_context, |
| 6606 | SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6607 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6608 | SyncOpNextSubpass::SyncOpNextSubpass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 6609 | const VkSubpassEndInfo *pSubpassEndInfo) |
| 6610 | : SyncOpBase(cmd) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6611 | if (pSubpassBeginInfo) { |
| 6612 | subpass_begin_info_.initialize(pSubpassBeginInfo); |
| 6613 | } |
| 6614 | if (pSubpassEndInfo) { |
| 6615 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 6616 | } |
| 6617 | } |
| 6618 | |
| 6619 | bool SyncOpNextSubpass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6620 | bool skip = false; |
| 6621 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 6622 | if (!renderpass_context) return skip; |
| 6623 | |
| 6624 | skip |= renderpass_context->ValidateNextSubpass(cb_context.GetExecutionContext(), CmdName()); |
| 6625 | return skip; |
| 6626 | } |
| 6627 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6628 | ResourceUsageTag SyncOpNextSubpass::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 6629 | return cb_context->RecordNextSubpass(cmd_); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6630 | } |
| 6631 | |
| 6632 | bool SyncOpNextSubpass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6633 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6634 | return false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6635 | } |
| 6636 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 6637 | SyncOpEndRenderPass::SyncOpEndRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassEndInfo *pSubpassEndInfo) |
| 6638 | : SyncOpBase(cmd) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6639 | if (pSubpassEndInfo) { |
| 6640 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 6641 | } |
| 6642 | } |
| 6643 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6644 | void SyncOpNextSubpass::ReplayRecord(ResourceUsageTag tag, AccessContext *access_context, SyncEventsContext *events_context) const { |
| 6645 | } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6646 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6647 | bool SyncOpEndRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6648 | bool skip = false; |
| 6649 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 6650 | |
| 6651 | if (!renderpass_context) return skip; |
| 6652 | skip |= renderpass_context->ValidateEndRenderPass(cb_context.GetExecutionContext(), CmdName()); |
| 6653 | return skip; |
| 6654 | } |
| 6655 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6656 | ResourceUsageTag SyncOpEndRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 6657 | return cb_context->RecordEndRenderPass(cmd_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6658 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6659 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6660 | bool SyncOpEndRenderPass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6661 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6662 | return false; |
| 6663 | } |
| 6664 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6665 | void SyncOpEndRenderPass::ReplayRecord(ResourceUsageTag tag, AccessContext *access_context, |
| 6666 | SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6667 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6668 | void SyncValidator::PreCallRecordCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 6669 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
| 6670 | StateTracker::PreCallRecordCmdWriteBufferMarker2AMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
| 6671 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 6672 | assert(cb_access_context); |
| 6673 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 6674 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 6675 | assert(context); |
| 6676 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6677 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6678 | |
| 6679 | if (dst_buffer) { |
| 6680 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 6681 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
| 6682 | } |
| 6683 | } |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 6684 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6685 | bool SyncValidator::PreCallValidateCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 6686 | const VkCommandBuffer *pCommandBuffers) const { |
| 6687 | bool skip = StateTracker::PreCallValidateCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
| 6688 | const char *func_name = "vkCmdExecuteCommands"; |
| 6689 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 6690 | assert(cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6691 | |
| 6692 | // Heavyweight, but we need a proxy copy of the active command buffer access context |
| 6693 | CommandBufferAccessContext proxy_cb_context(*cb_context, CommandBufferAccessContext::AsProxyContext()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6694 | |
| 6695 | // Make working copies of the access and events contexts |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6696 | for (uint32_t cb_index = 0; cb_index < commandBufferCount; ++cb_index) { |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 6697 | proxy_cb_context.NextIndexedCommandTag(CMD_EXECUTECOMMANDS, cb_index); |
| 6698 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6699 | const auto *recorded_cb_context = GetAccessContext(pCommandBuffers[cb_index]); |
| 6700 | if (!recorded_cb_context) continue; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6701 | |
| 6702 | const auto *recorded_context = recorded_cb_context->GetCurrentAccessContext(); |
| 6703 | assert(recorded_context); |
| 6704 | skip |= recorded_cb_context->ValidateFirstUse(&proxy_cb_context, func_name, cb_index); |
| 6705 | |
| 6706 | // The barriers have already been applied in ValidatFirstUse |
| 6707 | ResourceUsageRange tag_range = proxy_cb_context.ImportRecordedAccessLog(*recorded_cb_context); |
| 6708 | proxy_cb_context.ResolveRecordedContext(*recorded_context, tag_range.begin); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6709 | } |
| 6710 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6711 | return skip; |
| 6712 | } |
| 6713 | |
| 6714 | void SyncValidator::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 6715 | const VkCommandBuffer *pCommandBuffers) { |
| 6716 | StateTracker::PreCallRecordCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6717 | auto *cb_context = GetAccessContext(commandBuffer); |
| 6718 | assert(cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6719 | for (uint32_t cb_index = 0; cb_index < commandBufferCount; ++cb_index) { |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 6720 | cb_context->NextIndexedCommandTag(CMD_EXECUTECOMMANDS, cb_index); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6721 | const auto *recorded_cb_context = GetAccessContext(pCommandBuffers[cb_index]); |
| 6722 | if (!recorded_cb_context) continue; |
| 6723 | cb_context->RecordExecutedCommandBuffer(*recorded_cb_context, CMD_EXECUTECOMMANDS); |
| 6724 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6725 | } |
| 6726 | |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame^] | 6727 | void SyncValidator::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo, |
| 6728 | const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore, |
| 6729 | VkResult result) { |
| 6730 | StateTracker::PostCallRecordCreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore, result); |
| 6731 | if (VK_SUCCESS != result) return; |
| 6732 | |
| 6733 | // As 'this' is non-const, the get will insert |
| 6734 | GetSemaphoreSyncState(*pSemaphore); |
| 6735 | } |
| 6736 | |
| 6737 | void SyncValidator::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks *pAllocator) { |
| 6738 | sync_semaphores_.erase(semaphore); |
| 6739 | StateTracker::PostCallRecordDestroySemaphore(device, semaphore, pAllocator); |
| 6740 | } |
| 6741 | |
| 6742 | bool SyncValidator::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, |
| 6743 | VkFence fence) const { |
| 6744 | bool skip = false; |
| 6745 | |
| 6746 | return skip; |
| 6747 | } |
| 6748 | |
| 6749 | void SyncValidator::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence, |
| 6750 | VkResult result) { |
| 6751 | StateTracker::PostCallRecordQueueSubmit(queue, submitCount, pSubmits, fence, result); |
| 6752 | } |
| 6753 | |
| 6754 | bool SyncValidator::PreCallValidateQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 6755 | VkFence fence) const { |
| 6756 | return false; |
| 6757 | } |
| 6758 | |
| 6759 | void SyncValidator::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 6760 | VkFence fence, VkResult result) { |
| 6761 | StateTracker::PostCallRecordQueueSubmit2KHR(queue, submitCount, pSubmits, fence, result); |
| 6762 | } |
| 6763 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 6764 | AttachmentViewGen::AttachmentViewGen(const IMAGE_VIEW_STATE *view, const VkOffset3D &offset, const VkExtent3D &extent) |
| 6765 | : view_(view), view_mask_(), gen_store_() { |
| 6766 | if (!view_ || !view_->image_state || !SimpleBinding(*view_->image_state)) return; |
| 6767 | const IMAGE_STATE &image_state = *view_->image_state.get(); |
| 6768 | const auto base_address = ResourceBaseAddress(image_state); |
| 6769 | const auto *encoder = image_state.fragment_encoder.get(); |
| 6770 | if (!encoder) return; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 6771 | // Get offset and extent for the view, accounting for possible depth slicing |
| 6772 | const VkOffset3D zero_offset = view->GetOffset(); |
| 6773 | const VkExtent3D &image_extent = view->GetExtent(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 6774 | // Intentional copy |
| 6775 | VkImageSubresourceRange subres_range = view_->normalized_subresource_range; |
| 6776 | view_mask_ = subres_range.aspectMask; |
| 6777 | gen_store_[Gen::kViewSubresource].emplace(*encoder, subres_range, zero_offset, image_extent, base_address); |
| 6778 | gen_store_[Gen::kRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 6779 | |
| 6780 | const auto depth = view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT; |
| 6781 | if (depth && (depth != view_mask_)) { |
| 6782 | subres_range.aspectMask = depth; |
| 6783 | gen_store_[Gen::kDepthOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 6784 | } |
| 6785 | const auto stencil = view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT; |
| 6786 | if (stencil && (stencil != view_mask_)) { |
| 6787 | subres_range.aspectMask = stencil; |
| 6788 | gen_store_[Gen::kStencilOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 6789 | } |
| 6790 | } |
| 6791 | |
| 6792 | const ImageRangeGen *AttachmentViewGen::GetRangeGen(AttachmentViewGen::Gen gen_type) const { |
| 6793 | const ImageRangeGen *got = nullptr; |
| 6794 | switch (gen_type) { |
| 6795 | case kViewSubresource: |
| 6796 | got = &gen_store_[kViewSubresource]; |
| 6797 | break; |
| 6798 | case kRenderArea: |
| 6799 | got = &gen_store_[kRenderArea]; |
| 6800 | break; |
| 6801 | case kDepthOnlyRenderArea: |
| 6802 | got = |
| 6803 | (view_mask_ == VK_IMAGE_ASPECT_DEPTH_BIT) ? &gen_store_[Gen::kRenderArea] : &gen_store_[Gen::kDepthOnlyRenderArea]; |
| 6804 | break; |
| 6805 | case kStencilOnlyRenderArea: |
| 6806 | got = (view_mask_ == VK_IMAGE_ASPECT_STENCIL_BIT) ? &gen_store_[Gen::kRenderArea] |
| 6807 | : &gen_store_[Gen::kStencilOnlyRenderArea]; |
| 6808 | break; |
| 6809 | default: |
| 6810 | assert(got); |
| 6811 | } |
| 6812 | return got; |
| 6813 | } |
| 6814 | |
| 6815 | AttachmentViewGen::Gen AttachmentViewGen::GetDepthStencilRenderAreaGenType(bool depth_op, bool stencil_op) const { |
| 6816 | assert(IsValid()); |
| 6817 | assert(view_mask_ & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); |
| 6818 | if (depth_op) { |
| 6819 | assert(view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 6820 | if (stencil_op) { |
| 6821 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 6822 | return kRenderArea; |
| 6823 | } |
| 6824 | return kDepthOnlyRenderArea; |
| 6825 | } |
| 6826 | if (stencil_op) { |
| 6827 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 6828 | return kStencilOnlyRenderArea; |
| 6829 | } |
| 6830 | |
| 6831 | assert(depth_op || stencil_op); |
| 6832 | return kRenderArea; |
| 6833 | } |
| 6834 | |
| 6835 | AccessAddressType AttachmentViewGen::GetAddressType() const { return AccessContext::ImageAddressType(*view_->image_state); } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6836 | |
| 6837 | void SyncEventsContext::ApplyBarrier(const SyncExecScope &src, const SyncExecScope &dst) { |
| 6838 | const bool all_commands_bit = 0 != (src.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 6839 | for (auto &event_pair : map_) { |
| 6840 | assert(event_pair.second); // Shouldn't be storing empty |
| 6841 | auto &sync_event = *event_pair.second; |
| 6842 | // Events don't happen at a stage, so we need to check and store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 6843 | if ((sync_event.barriers & src.exec_scope) || all_commands_bit) { |
| 6844 | sync_event.barriers |= dst.exec_scope; |
| 6845 | sync_event.barriers |= dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 6846 | } |
| 6847 | } |
| 6848 | } |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6849 | |
| 6850 | ReplayTrackbackBarriersAction::ReplayTrackbackBarriersAction(VkQueueFlags queue_flags, |
| 6851 | const SubpassDependencyGraphNode &subpass_dep, |
| 6852 | const std::vector<ReplayTrackbackBarriersAction> &replay_contexts) { |
| 6853 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 6854 | trackback_barriers.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
| 6855 | for (const auto &prev_dep : subpass_dep.prev) { |
| 6856 | const auto prev_pass = prev_dep.first->pass; |
| 6857 | const auto &prev_barriers = prev_dep.second; |
| 6858 | trackback_barriers.emplace_back(&replay_contexts[prev_pass], queue_flags, prev_barriers); |
| 6859 | } |
| 6860 | if (has_barrier_from_external) { |
| 6861 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 6862 | trackback_barriers.emplace_back(nullptr, queue_flags, subpass_dep.barrier_from_external); |
| 6863 | } |
| 6864 | } |
| 6865 | |
| 6866 | void ReplayTrackbackBarriersAction::operator()(ResourceAccessState *access) const { |
| 6867 | if (trackback_barriers.size() == 1) { |
| 6868 | trackback_barriers[0](access); |
| 6869 | } else { |
| 6870 | ResourceAccessState resolved; |
| 6871 | for (const auto &trackback : trackback_barriers) { |
| 6872 | ResourceAccessState access_copy = *access; |
| 6873 | trackback(&access_copy); |
| 6874 | resolved.Resolve(access_copy); |
| 6875 | } |
| 6876 | *access = resolved; |
| 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | ReplayTrackbackBarriersAction::TrackbackBarriers::TrackbackBarriers( |
| 6881 | const ReplayTrackbackBarriersAction *source_subpass_, VkQueueFlags queue_flags_, |
| 6882 | const std::vector<const VkSubpassDependency2 *> &subpass_dependencies_) |
| 6883 | : Base(source_subpass_, queue_flags_, subpass_dependencies_) {} |
| 6884 | |
| 6885 | void ReplayTrackbackBarriersAction::TrackbackBarriers::operator()(ResourceAccessState *access) const { |
| 6886 | if (source_subpass) { |
| 6887 | (*source_subpass)(access); |
| 6888 | } |
| 6889 | access->ApplyBarriersImmediate(barriers); |
| 6890 | } |