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 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 358 | VkDeviceSize GetRealWholeSize(VkDeviceSize offset, VkDeviceSize size, VkDeviceSize whole_size) { |
locke-lunarg | 3c03800 | 2020-04-30 23:08:08 -0600 | [diff] [blame] | 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}, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 654 | image_state.createInfo.extent, base_address, false); |
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, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 729 | const CommandExecutionContext &exec_context, CMD_TYPE cmd_type) |
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), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 734 | cmd_type_(cmd_type), |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 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) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 742 | skip_ |= exec_context_.GetSyncState().LogError( |
| 743 | render_pass_, string_SyncHazardVUID(hazard.hazard), |
| 744 | "%s: Hazard %s in subpass %" PRIu32 "during %s %s, from attachment %" PRIu32 " to resolve attachment %" PRIu32 |
| 745 | ". Access info %s.", |
| 746 | CommandTypeString(cmd_type_), string_SyncHazard(hazard.hazard), subpass_, aspect_name, attachment_name, src_at, |
| 747 | 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_; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 758 | CMD_TYPE cmd_type_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 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 | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 790 | void AccessContext::DeleteAccess(const AddressRange &address) { GetAccessStateMap(address.type).erase_range(address.range); } |
| 791 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 792 | AccessContext::AccessContext(uint32_t subpass, VkQueueFlags queue_flags, |
| 793 | const std::vector<SubpassDependencyGraphNode> &dependencies, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 794 | const std::vector<AccessContext> &contexts, const AccessContext *external_context) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 795 | Reset(); |
| 796 | const auto &subpass_dep = dependencies[subpass]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 797 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 798 | prev_.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 799 | 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] | 800 | for (const auto &prev_dep : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 801 | const auto prev_pass = prev_dep.first->pass; |
| 802 | const auto &prev_barriers = prev_dep.second; |
| 803 | assert(prev_dep.second.size()); |
| 804 | prev_.emplace_back(&contexts[prev_pass], queue_flags, prev_barriers); |
| 805 | prev_by_subpass_[prev_pass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 806 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 807 | |
| 808 | async_.reserve(subpass_dep.async.size()); |
| 809 | for (const auto async_subpass : subpass_dep.async) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 810 | async_.emplace_back(&contexts[async_subpass]); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 811 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 812 | if (has_barrier_from_external) { |
| 813 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 814 | prev_.emplace_back(external_context, queue_flags, subpass_dep.barrier_from_external); |
| 815 | src_external_ = &prev_.back(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 816 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 817 | if (subpass_dep.barrier_to_external.size()) { |
| 818 | dst_external_ = TrackBack(this, queue_flags, subpass_dep.barrier_to_external); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 819 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 820 | } |
| 821 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 822 | template <typename Detector> |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 823 | HazardResult AccessContext::DetectPreviousHazard(AccessAddressType type, Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 824 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 825 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 826 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 827 | |
| 828 | HazardResult hazard; |
| 829 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 830 | hazard = detector.Detect(prev); |
| 831 | } |
| 832 | return hazard; |
| 833 | } |
| 834 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 835 | template <typename Action> |
| 836 | void AccessContext::ForAll(Action &&action) { |
| 837 | for (const auto address_type : kAddressTypes) { |
| 838 | auto &accesses = GetAccessStateMap(address_type); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 839 | for (auto &access : accesses) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 840 | action(address_type, access); |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 845 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 846 | // the DAG of the contexts (for example subpasses) |
| 847 | template <typename Detector> |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 848 | HazardResult AccessContext::DetectHazard(AccessAddressType type, Detector &detector, const ResourceAccessRange &range, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 849 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 850 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 851 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 852 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 853 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 854 | // so we'll check these first |
| 855 | for (const auto &async_context : async_) { |
| 856 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 857 | if (hazard.hazard) return hazard; |
| 858 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 859 | } |
| 860 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 861 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 862 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 863 | const auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 864 | const auto the_end = accesses.cend(); // End is not invalidated |
| 865 | auto pos = accesses.lower_bound(range); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 866 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 867 | |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 868 | while (pos != the_end && pos->first.begin < range.end) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 869 | // Cover any leading gap, or gap between entries |
| 870 | if (detect_prev) { |
| 871 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 872 | // Cover any leading gap, or gap between entries |
| 873 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 874 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 875 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 876 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 877 | if (hazard.hazard) return hazard; |
| 878 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 879 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 880 | gap.begin = pos->first.end; |
| 881 | } |
| 882 | |
| 883 | hazard = detector.Detect(pos); |
| 884 | if (hazard.hazard) return hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 885 | ++pos; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | if (detect_prev) { |
| 889 | // Detect in the trailing empty as needed |
| 890 | gap.end = range.end; |
| 891 | if (gap.non_empty()) { |
| 892 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 893 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | return hazard; |
| 897 | } |
| 898 | |
| 899 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 900 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 901 | HazardResult AccessContext::DetectAsyncHazard(AccessAddressType type, const Detector &detector, |
| 902 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 903 | auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 904 | auto pos = accesses.lower_bound(range); |
| 905 | const auto the_end = accesses.end(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 906 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 907 | HazardResult hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 908 | while (pos != the_end && pos->first.begin < range.end) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 909 | hazard = detector.DetectAsync(pos, start_tag_); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 910 | if (hazard.hazard) break; |
| 911 | ++pos; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 912 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 913 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 914 | return hazard; |
| 915 | } |
| 916 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 917 | struct ApplySubpassTransitionBarriersAction { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 918 | explicit ApplySubpassTransitionBarriersAction(const std::vector<SyncBarrier> &barriers_) : barriers(barriers_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 919 | void operator()(ResourceAccessState *access) const { |
| 920 | assert(access); |
| 921 | access->ApplyBarriers(barriers, true); |
| 922 | } |
| 923 | const std::vector<SyncBarrier> &barriers; |
| 924 | }; |
| 925 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 926 | struct QueueTagOffsetBarrierAction { |
| 927 | QueueTagOffsetBarrierAction(QueueId qid, ResourceUsageTag offset) : queue_id(qid), tag_offset(offset) {} |
| 928 | void operator()(ResourceAccessState *access) const { |
| 929 | access->OffsetTag(tag_offset); |
| 930 | access->SetQueueId(queue_id); |
| 931 | }; |
| 932 | QueueId queue_id; |
| 933 | ResourceUsageTag tag_offset; |
| 934 | }; |
| 935 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 936 | struct ApplyTrackbackStackAction { |
| 937 | explicit ApplyTrackbackStackAction(const std::vector<SyncBarrier> &barriers_, |
| 938 | const ResourceAccessStateFunction *previous_barrier_ = nullptr) |
| 939 | : barriers(barriers_), previous_barrier(previous_barrier_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 940 | void operator()(ResourceAccessState *access) const { |
| 941 | assert(access); |
| 942 | assert(!access->HasPendingState()); |
| 943 | access->ApplyBarriers(barriers, false); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 944 | // NOTE: We can use invalid tag, as these barriers do no include layout transitions (would assert in SetWrite) |
| 945 | access->ApplyPendingBarriers(kInvalidTag); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 946 | if (previous_barrier) { |
| 947 | assert(bool(*previous_barrier)); |
| 948 | (*previous_barrier)(access); |
| 949 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 950 | } |
| 951 | const std::vector<SyncBarrier> &barriers; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 952 | const ResourceAccessStateFunction *previous_barrier; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 953 | }; |
| 954 | |
| 955 | // Splits a single map entry into piece matching the entries in [first, last) the total range over [first, last) must be |
| 956 | // contained with entry. Entry must be an iterator pointing to dest, first and last must be iterators pointing to a |
| 957 | // *different* map from dest. |
| 958 | // Returns the position past the last resolved range -- the entry covering the remainder of entry->first not included in the |
| 959 | // range [first, last) |
| 960 | template <typename BarrierAction> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 961 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 962 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 963 | BarrierAction &barrier_action) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 964 | auto at = entry; |
| 965 | for (auto pos = first; pos != last; ++pos) { |
| 966 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 967 | assert(at->first.includes(pos->first)); |
| 968 | assert(at != dest->end()); |
| 969 | // Trim up at to the same size as the entry to resolve |
| 970 | at = sparse_container::split(at, *dest, pos->first); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 971 | auto access = pos->second; // intentional copy |
| 972 | barrier_action(&access); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 973 | at->second.Resolve(access); |
| 974 | ++at; // Go to the remaining unused section of entry |
| 975 | } |
| 976 | } |
| 977 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 978 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 979 | SyncBarrier merged = {}; |
| 980 | for (const auto &barrier : barriers) { |
| 981 | merged.Merge(barrier); |
| 982 | } |
| 983 | return merged; |
| 984 | } |
| 985 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 986 | template <typename BarrierAction> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 987 | void AccessContext::ResolveAccessRange(AccessAddressType type, const ResourceAccessRange &range, BarrierAction &barrier_action, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 988 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 989 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 990 | if (!range.non_empty()) return; |
| 991 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 992 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 993 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 994 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 995 | if (current->pos_B->valid) { |
| 996 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 997 | auto access = src_pos->second; // intentional copy |
| 998 | barrier_action(&access); |
| 999 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1000 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 1001 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 1002 | trimmed->second.Resolve(access); |
| 1003 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1004 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 1005 | 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] | 1006 | 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] | 1007 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1008 | } else { |
| 1009 | // we have to descend to fill this gap |
| 1010 | if (recur_to_infill) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1011 | ResourceAccessRange recurrence_range = current_range; |
| 1012 | // The current context is empty for the current range, so recur to fill the gap. |
| 1013 | // Since we will be recurring back up the DAG, expand the gap descent to cover the full range for which B |
| 1014 | // is not valid, to minimize that recurrence |
| 1015 | if (current->pos_B.at_end()) { |
| 1016 | // Do the remainder here.... |
| 1017 | recurrence_range.end = range.end; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1018 | } else { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1019 | // Recur only over the range until B becomes valid (within the limits of range). |
| 1020 | 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] | 1021 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1022 | ResolvePreviousAccessStack(type, recurrence_range, resolve_map, infill_state, barrier_action); |
| 1023 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1024 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 1025 | // iterator of the outer while. |
| 1026 | |
| 1027 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 1028 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 1029 | // we stepped on the dest map |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1030 | 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] | 1031 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1032 | current.seek(seek_to); |
| 1033 | } else if (!current->pos_A->valid && infill_state) { |
| 1034 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 1035 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 1036 | 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] | 1037 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1038 | } |
ziga-lunarg | f0e27ad | 2022-03-28 00:44:12 +0200 | [diff] [blame] | 1039 | if (current->range.non_empty()) { |
| 1040 | ++current; |
| 1041 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1042 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1043 | |
| 1044 | // Infill if range goes passed both the current and resolve map prior contents |
| 1045 | if (recur_to_infill && (current->range.end < range.end)) { |
| 1046 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1047 | ResolvePreviousAccessStack<BarrierAction>(type, trailing_fill_range, resolve_map, infill_state, barrier_action); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1048 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1049 | } |
| 1050 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1051 | template <typename BarrierAction> |
| 1052 | void AccessContext::ResolvePreviousAccessStack(AccessAddressType type, const ResourceAccessRange &range, |
| 1053 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 1054 | const BarrierAction &previous_barrier) const { |
| 1055 | ResourceAccessStateFunction stacked_barrier(std::ref(previous_barrier)); |
| 1056 | ResolvePreviousAccess(type, range, descent_map, infill_state, &stacked_barrier); |
| 1057 | } |
| 1058 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1059 | void AccessContext::ResolvePreviousAccess(AccessAddressType type, const ResourceAccessRange &range, |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1060 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 1061 | const ResourceAccessStateFunction *previous_barrier) const { |
| 1062 | if (prev_.size() == 0) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1063 | if (range.non_empty() && infill_state) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1064 | // Fill the empty poritions of descent_map with the default_state with the barrier function applied (iff present) |
| 1065 | ResourceAccessState state_copy; |
| 1066 | if (previous_barrier) { |
| 1067 | assert(bool(*previous_barrier)); |
| 1068 | state_copy = *infill_state; |
| 1069 | (*previous_barrier)(&state_copy); |
| 1070 | infill_state = &state_copy; |
| 1071 | } |
| 1072 | sparse_container::update_range_value(*descent_map, range, *infill_state, |
| 1073 | sparse_container::value_precedence::prefer_dest); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1074 | } |
| 1075 | } else { |
| 1076 | // Look for something to fill the gap further along. |
| 1077 | for (const auto &prev_dep : prev_) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1078 | const ApplyTrackbackStackAction barrier_action(prev_dep.barriers, previous_barrier); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1079 | 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] | 1080 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1081 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1082 | } |
| 1083 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1084 | // Non-lazy import of all accesses, WaitEvents needs this. |
| 1085 | void AccessContext::ResolvePreviousAccesses() { |
| 1086 | ResourceAccessState default_state; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1087 | if (!prev_.size()) return; // If no previous contexts, nothing to do |
| 1088 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1089 | for (const auto address_type : kAddressTypes) { |
| 1090 | ResolvePreviousAccess(address_type, kFullRange, &GetAccessStateMap(address_type), &default_state); |
| 1091 | } |
| 1092 | } |
| 1093 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1094 | AccessAddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
| 1095 | return (image.fragment_encoder->IsLinearImage()) ? AccessAddressType::kLinear : AccessAddressType::kIdealized; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1096 | } |
| 1097 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1098 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1099 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_NONE_EXT) |
| 1100 | ? SYNC_ACCESS_INDEX_NONE |
| 1101 | : ((load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 1102 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1103 | return stage_access; |
| 1104 | } |
| 1105 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1106 | const auto stage_access = |
| 1107 | (load_op == VK_ATTACHMENT_LOAD_OP_NONE_EXT) |
| 1108 | ? SYNC_ACCESS_INDEX_NONE |
| 1109 | : ((load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 1110 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1111 | return stage_access; |
| 1112 | } |
| 1113 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1114 | // Caller must manage returned pointer |
| 1115 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1116 | uint32_t subpass, const AttachmentViewGenVector &attachment_views) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1117 | auto *proxy = new AccessContext(context); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1118 | proxy->UpdateAttachmentResolveAccess(rp_state, attachment_views, subpass, kInvalidTag); |
| 1119 | proxy->UpdateAttachmentStoreAccess(rp_state, attachment_views, subpass, kInvalidTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1120 | return proxy; |
| 1121 | } |
| 1122 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1123 | template <typename BarrierAction> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1124 | void AccessContext::ResolveAccessRange(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1125 | BarrierAction &barrier_action, ResourceAccessRangeMap *descent_map, |
| 1126 | const ResourceAccessState *infill_state) const { |
| 1127 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1128 | if (!attachment_gen) return; |
| 1129 | |
| 1130 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1131 | const AccessAddressType address_type = view_gen.GetAddressType(); |
| 1132 | for (; range_gen->non_empty(); ++range_gen) { |
| 1133 | ResolveAccessRange(address_type, *range_gen, barrier_action, descent_map, infill_state); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1134 | } |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 1135 | } |
| 1136 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 1137 | template <typename ResolveOp> |
| 1138 | void AccessContext::ResolveFromContext(ResolveOp &&resolve_op, const AccessContext &from_context, |
| 1139 | const ResourceAccessState *infill_state, bool recur_to_infill) { |
| 1140 | for (auto address_type : kAddressTypes) { |
| 1141 | from_context.ResolveAccessRange(address_type, kFullRange, resolve_op, &GetAccessStateMap(address_type), infill_state, |
| 1142 | recur_to_infill); |
| 1143 | } |
| 1144 | } |
| 1145 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1146 | // 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] | 1147 | 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] | 1148 | const VkRect2D &render_area, uint32_t subpass, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1149 | const AttachmentViewGenVector &attachment_views, CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1150 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1151 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 1152 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 1153 | // those affects have not been recorded yet. |
| 1154 | // |
| 1155 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 1156 | // to apply and only copy then, if this proves a hot spot. |
| 1157 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 1158 | TrackBack proxy_track_back; |
| 1159 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1160 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 1161 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1162 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 1163 | |
| 1164 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1165 | assert(track_back); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1166 | if (prev_needs_proxy) { |
| 1167 | if (!proxy_for_prev) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1168 | proxy_for_prev.reset( |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1169 | CreateStoreResolveProxyContext(*track_back->source_subpass, rp_state, transition.prev_pass, attachment_views)); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1170 | proxy_track_back = *track_back; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1171 | proxy_track_back.source_subpass = proxy_for_prev.get(); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1172 | } |
| 1173 | track_back = &proxy_track_back; |
| 1174 | } |
| 1175 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1176 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1177 | const char *func_name = CommandTypeString(cmd_type); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1178 | if (hazard.tag == kInvalidTag) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1179 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1180 | rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1181 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1182 | " image layout transition (old_layout: %s, new_layout: %s) after store/resolve operation in subpass %" PRIu32, |
| 1183 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1184 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), transition.prev_pass); |
| 1185 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1186 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1187 | rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1188 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1189 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 1190 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1191 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1192 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1193 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | return skip; |
| 1197 | } |
| 1198 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1199 | 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] | 1200 | const VkRect2D &render_area, uint32_t subpass, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1201 | const AttachmentViewGenVector &attachment_views, CMD_TYPE cmd_type) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1202 | bool skip = false; |
| 1203 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1204 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1205 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1206 | if (subpass == rp_state.attachment_first_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1207 | const auto &view_gen = attachment_views[i]; |
| 1208 | if (!view_gen.IsValid()) continue; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1209 | const auto &ci = attachment_ci[i]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1210 | |
| 1211 | // Need check in the following way |
| 1212 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 1213 | // vs. transition |
| 1214 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 1215 | // for each aspect loaded. |
| 1216 | |
| 1217 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1218 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1219 | const bool is_color = !(has_depth || has_stencil); |
| 1220 | |
| 1221 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1222 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1223 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1224 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1225 | const char *aspect = nullptr; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1226 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1227 | bool checked_stencil = false; |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1228 | if (is_color && (load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1229 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, load_index, SyncOrdering::kColorAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1230 | aspect = "color"; |
| 1231 | } else { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1232 | if (has_depth && (load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1233 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_index, |
| 1234 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1235 | aspect = "depth"; |
| 1236 | } |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1237 | if (!hazard.hazard && has_stencil && (stencil_load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1238 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, stencil_load_index, |
| 1239 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1240 | aspect = "stencil"; |
| 1241 | checked_stencil = true; |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1246 | const char *func_name = CommandTypeString(cmd_type); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1247 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1248 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1249 | if (hazard.tag == kInvalidTag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1250 | // Hazard vs. ILT |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1251 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1252 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1253 | " aspect %s during load with loadOp %s.", |
| 1254 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string); |
| 1255 | } else { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1256 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1257 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1258 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1259 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1260 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | return skip; |
| 1266 | } |
| 1267 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1268 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 1269 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 1270 | // store is part of the same Next/End operation. |
| 1271 | // The latter is handled in layout transistion validation directly |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1272 | 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] | 1273 | const VkRect2D &render_area, uint32_t subpass, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1274 | const AttachmentViewGenVector &attachment_views, CMD_TYPE cmd_type) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1275 | bool skip = false; |
| 1276 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1277 | |
| 1278 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1279 | if (subpass == rp_state.attachment_last_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1280 | const AttachmentViewGen &view_gen = attachment_views[i]; |
| 1281 | if (!view_gen.IsValid()) continue; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1282 | const auto &ci = attachment_ci[i]; |
| 1283 | |
| 1284 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1285 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 1286 | // sake, we treat DONT_CARE as writing. |
| 1287 | const bool has_depth = FormatHasDepth(ci.format); |
| 1288 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1289 | const bool is_color = !(has_depth || has_stencil); |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1290 | 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] | 1291 | if (!has_stencil && !store_op_stores) continue; |
| 1292 | |
| 1293 | HazardResult hazard; |
| 1294 | const char *aspect = nullptr; |
| 1295 | bool checked_stencil = false; |
| 1296 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1297 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1298 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1299 | aspect = "color"; |
| 1300 | } else { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1301 | 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] | 1302 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1303 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1304 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1305 | aspect = "depth"; |
| 1306 | } |
| 1307 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1308 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1309 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1310 | aspect = "stencil"; |
| 1311 | checked_stencil = true; |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | if (hazard.hazard) { |
| 1316 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 1317 | 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] | 1318 | skip |= exec_context.GetSyncState().LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1319 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1320 | " %s aspect during store with %s %s. Access info %s", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1321 | CommandTypeString(cmd_type), string_SyncHazard(hazard.hazard), subpass, |
| 1322 | i, aspect, op_type_string, store_op_string, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1323 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | return skip; |
| 1328 | } |
| 1329 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1330 | 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] | 1331 | const VkRect2D &render_area, const AttachmentViewGenVector &attachment_views, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1332 | CMD_TYPE cmd_type, uint32_t subpass) const { |
| 1333 | ValidateResolveAction validate_action(rp_state.renderPass(), subpass, *this, exec_context, cmd_type); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1334 | ResolveOperation(validate_action, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1335 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1336 | } |
| 1337 | |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 1338 | void AccessContext::AddAsyncContext(const AccessContext *context) { async_.emplace_back(context); } |
| 1339 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1340 | class HazardDetector { |
| 1341 | SyncStageAccessIndex usage_index_; |
| 1342 | |
| 1343 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1344 | 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] | 1345 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1346 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1347 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1348 | explicit HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1349 | }; |
| 1350 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1351 | class HazardDetectorWithOrdering { |
| 1352 | const SyncStageAccessIndex usage_index_; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1353 | const SyncOrdering ordering_rule_; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1354 | |
| 1355 | public: |
| 1356 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 1357 | return pos->second.DetectHazard(usage_index_, ordering_rule_, QueueSyncState::kQueueIdInvalid); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1358 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1359 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1360 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1361 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1362 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, SyncOrdering ordering) : usage_index_(usage), ordering_rule_(ordering) {} |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1363 | }; |
| 1364 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1365 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1366 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1367 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1368 | const auto base_address = ResourceBaseAddress(buffer); |
| 1369 | HazardDetector detector(usage_index); |
| 1370 | return DetectHazard(AccessAddressType::kLinear, detector, (range + base_address), DetectOptions::kDetectAll); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 1371 | } |
| 1372 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1373 | template <typename Detector> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1374 | HazardResult AccessContext::DetectHazard(Detector &detector, const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1375 | DetectOptions options) const { |
| 1376 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1377 | if (!attachment_gen) return HazardResult(); |
| 1378 | |
| 1379 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1380 | const auto address_type = view_gen.GetAddressType(); |
| 1381 | for (; range_gen->non_empty(); ++range_gen) { |
| 1382 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1383 | if (hazard.hazard) return hazard; |
| 1384 | } |
| 1385 | |
| 1386 | return HazardResult(); |
| 1387 | } |
| 1388 | |
| 1389 | template <typename Detector> |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1390 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1391 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1392 | const VkExtent3D &extent, bool is_depth_sliced, DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1393 | if (!SimpleBinding(image)) return HazardResult(); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1394 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1395 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1396 | base_address, is_depth_sliced); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1397 | const auto address_type = ImageAddressType(image); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1398 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1399 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1400 | if (hazard.hazard) return hazard; |
| 1401 | } |
| 1402 | return HazardResult(); |
| 1403 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1404 | template <typename Detector> |
| 1405 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1406 | const VkImageSubresourceRange &subresource_range, bool is_depth_sliced, |
| 1407 | DetectOptions options) const { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1408 | if (!SimpleBinding(image)) return HazardResult(); |
| 1409 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1410 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address, |
| 1411 | is_depth_sliced); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1412 | const auto address_type = ImageAddressType(image); |
| 1413 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1414 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1415 | if (hazard.hazard) return hazard; |
| 1416 | } |
| 1417 | return HazardResult(); |
| 1418 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1419 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1420 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1421 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1422 | const VkExtent3D &extent, bool is_depth_sliced) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1423 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1424 | subresource.layerCount}; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1425 | HazardDetector detector(current_usage); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1426 | return DetectHazard(detector, image, subresource_range, offset, extent, is_depth_sliced, DetectOptions::kDetectAll); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1430 | const VkImageSubresourceRange &subresource_range, bool is_depth_sliced) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1431 | HazardDetector detector(current_usage); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1432 | return DetectHazard(detector, image, subresource_range, is_depth_sliced, DetectOptions::kDetectAll); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1433 | } |
| 1434 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1435 | HazardResult AccessContext::DetectHazard(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1436 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) const { |
| 1437 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
| 1438 | return DetectHazard(detector, view_gen, gen_type, DetectOptions::kDetectAll); |
| 1439 | } |
| 1440 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1441 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1442 | const VkImageSubresourceRange &subresource_range, SyncOrdering ordering_rule, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1443 | const VkOffset3D &offset, const VkExtent3D &extent, bool is_depth_sliced) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1444 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1445 | return DetectHazard(detector, image, subresource_range, offset, extent, is_depth_sliced, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1446 | } |
| 1447 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1448 | class BarrierHazardDetector { |
| 1449 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1450 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1451 | SyncStageAccessFlags src_access_scope) |
| 1452 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1453 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1454 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 1455 | return pos->second.DetectBarrierHazard(usage_index_, QueueSyncState::kQueueIdInvalid, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1456 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1457 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1458 | // 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] | 1459 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | private: |
| 1463 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1464 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1465 | SyncStageAccessFlags src_access_scope_; |
| 1466 | }; |
| 1467 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1468 | class EventBarrierHazardDetector { |
| 1469 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1470 | EventBarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1471 | SyncStageAccessFlags src_access_scope, const SyncEventState::ScopeMap &event_scope, QueueId queue_id, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1472 | ResourceUsageTag scope_tag) |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1473 | : usage_index_(usage_index), |
| 1474 | src_exec_scope_(src_exec_scope), |
| 1475 | src_access_scope_(src_access_scope), |
| 1476 | event_scope_(event_scope), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1477 | scope_queue_id_(queue_id), |
| 1478 | scope_tag_(scope_tag), |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1479 | scope_pos_(event_scope.cbegin()), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1480 | scope_end_(event_scope.cend()) {} |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1481 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1482 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) { |
| 1483 | // Need to piece together coverage of pos->first range: |
| 1484 | // Copy the range as we'll be chopping it up as needed |
| 1485 | ResourceAccessRange range = pos->first; |
| 1486 | const ResourceAccessState &access = pos->second; |
| 1487 | HazardResult hazard; |
| 1488 | |
| 1489 | bool in_scope = AdvanceScope(range); |
| 1490 | bool unscoped_tested = false; |
| 1491 | while (in_scope && !hazard.IsHazard()) { |
| 1492 | if (range.begin < ScopeBegin()) { |
| 1493 | if (!unscoped_tested) { |
| 1494 | unscoped_tested = true; |
| 1495 | hazard = access.DetectHazard(usage_index_); |
| 1496 | } |
| 1497 | // Note: don't need to check for in_scope as AdvanceScope true means range and ScopeRange intersect. |
| 1498 | // Thus a [ ScopeBegin, range.end ) will be non-empty. |
| 1499 | range.begin = ScopeBegin(); |
| 1500 | } else { // in_scope implied that ScopeRange and range intersect |
| 1501 | hazard = access.DetectBarrierHazard(usage_index_, ScopeState(), src_exec_scope_, src_access_scope_, scope_queue_id_, |
| 1502 | scope_tag_); |
| 1503 | if (!hazard.IsHazard()) { |
| 1504 | range.begin = ScopeEnd(); |
| 1505 | in_scope = AdvanceScope(range); // contains a non_empty check |
| 1506 | } |
| 1507 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1508 | } |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1509 | if (range.non_empty() && !hazard.IsHazard() && !unscoped_tested) { |
| 1510 | hazard = access.DetectHazard(usage_index_); |
| 1511 | } |
| 1512 | return hazard; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1513 | } |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1514 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1515 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1516 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1517 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
| 1518 | } |
| 1519 | |
| 1520 | private: |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1521 | bool ScopeInvalid() const { return scope_pos_ == scope_end_; } |
| 1522 | bool ScopeValid() const { return !ScopeInvalid(); } |
| 1523 | void ScopeSeek(const ResourceAccessRange &range) { scope_pos_ = event_scope_.lower_bound(range); } |
| 1524 | |
| 1525 | // Hiding away the std::pair grunge... |
| 1526 | ResourceAddress ScopeBegin() const { return scope_pos_->first.begin; } |
| 1527 | ResourceAddress ScopeEnd() const { return scope_pos_->first.end; } |
| 1528 | const ResourceAccessRange &ScopeRange() const { return scope_pos_->first; } |
| 1529 | const ResourceAccessState &ScopeState() const { return scope_pos_->second; } |
| 1530 | |
| 1531 | bool AdvanceScope(const ResourceAccessRange &range) { |
| 1532 | // Note: non_empty is (valid && !empty), so don't change !non_empty to empty... |
| 1533 | if (!range.non_empty()) return false; |
| 1534 | if (ScopeInvalid()) return false; |
| 1535 | |
| 1536 | if (ScopeRange().strictly_less(range)) { |
| 1537 | ScopeSeek(range); |
| 1538 | } |
| 1539 | |
| 1540 | return ScopeValid() && ScopeRange().intersects(range); |
| 1541 | } |
| 1542 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1543 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1544 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1545 | SyncStageAccessFlags src_access_scope_; |
| 1546 | const SyncEventState::ScopeMap &event_scope_; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1547 | QueueId scope_queue_id_; |
| 1548 | const ResourceUsageTag scope_tag_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1549 | SyncEventState::ScopeMap::const_iterator scope_pos_; |
| 1550 | SyncEventState::ScopeMap::const_iterator scope_end_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1551 | }; |
| 1552 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1553 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range, |
| 1554 | VkPipelineStageFlags2KHR src_exec_scope, |
| 1555 | const SyncStageAccessFlags &src_access_scope, QueueId queue_id, |
| 1556 | const SyncEventState &sync_event, AccessContext::DetectOptions options) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1557 | // It's not particularly DRY to get the address type in this function as well as lower down, but we have to select the |
| 1558 | // first access scope map to use, and there's no easy way to plumb it in below. |
| 1559 | const auto address_type = ImageAddressType(image); |
| 1560 | const auto &event_scope = sync_event.FirstScope(address_type); |
| 1561 | |
| 1562 | EventBarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope, |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1563 | event_scope, queue_id, sync_event.first_scope_tag); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1564 | return DetectHazard(detector, image, subresource_range, false, options); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1567 | HazardResult AccessContext::DetectImageBarrierHazard(const AttachmentViewGen &view_gen, const SyncBarrier &barrier, |
| 1568 | DetectOptions options) const { |
| 1569 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, barrier.src_exec_scope.exec_scope, |
| 1570 | barrier.src_access_scope); |
| 1571 | return DetectHazard(detector, view_gen, AttachmentViewGen::Gen::kViewSubresource, options); |
| 1572 | } |
| 1573 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1574 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1575 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1576 | const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1577 | const DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1578 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1579 | return DetectHazard(detector, image, subresource_range, false, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1582 | HazardResult AccessContext::DetectImageBarrierHazard(const SyncImageMemoryBarrier &image_barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1583 | 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] | 1584 | image_barrier.barrier.src_access_scope, image_barrier.range, kDetectAll); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1585 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1586 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1587 | template <typename Flags, typename Map> |
| 1588 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1589 | SyncStageAccessFlags scope = 0; |
| 1590 | for (const auto &bit_scope : map) { |
| 1591 | if (flag_mask < bit_scope.first) break; |
| 1592 | |
| 1593 | if (flag_mask & bit_scope.first) { |
| 1594 | scope |= bit_scope.second; |
| 1595 | } |
| 1596 | } |
| 1597 | return scope; |
| 1598 | } |
| 1599 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1600 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags2KHR stages) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1601 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1602 | } |
| 1603 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1604 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags2KHR accesses) { |
| 1605 | return AccessScopeImpl(sync_utils::ExpandAccessFlags(accesses), syncStageAccessMaskByAccessBit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1606 | } |
| 1607 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1608 | // Getting from stage mask and access mask to stage/access masks is something we need to be good at... |
| 1609 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags2KHR stages, VkAccessFlags2KHR accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1610 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1611 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1612 | // 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] | 1613 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1614 | } |
| 1615 | |
| 1616 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1617 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1618 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1619 | // that do incrementalupdates |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1620 | assert(accesses); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1621 | auto pos = accesses->lower_bound(range); |
| 1622 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1623 | // The range is empty, fill it with a default value. |
| 1624 | pos = action.Infill(accesses, pos, range); |
| 1625 | } else if (range.begin < pos->first.begin) { |
| 1626 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1627 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1628 | } else if (pos->first.begin < range.begin) { |
| 1629 | // Trim the beginning if needed |
| 1630 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1631 | ++pos; |
| 1632 | } |
| 1633 | |
| 1634 | const auto the_end = accesses->end(); |
| 1635 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1636 | if (pos->first.end > range.end) { |
| 1637 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1638 | } |
| 1639 | |
| 1640 | pos = action(accesses, pos); |
| 1641 | if (pos == the_end) break; |
| 1642 | |
| 1643 | auto next = pos; |
| 1644 | ++next; |
| 1645 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1646 | // Need to infill if next is disjoint |
| 1647 | 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] | 1648 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1649 | next = action.Infill(accesses, next, new_range); |
| 1650 | } |
| 1651 | pos = next; |
| 1652 | } |
| 1653 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1654 | |
| 1655 | // Give a comparable interface for range generators and ranges |
| 1656 | template <typename Action> |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 1657 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, ResourceAccessRange *range) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1658 | assert(range); |
| 1659 | UpdateMemoryAccessState(accesses, *range, action); |
| 1660 | } |
| 1661 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1662 | template <typename Action, typename RangeGen> |
| 1663 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, RangeGen *range_gen_arg) { |
| 1664 | assert(range_gen_arg); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1665 | 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] | 1666 | for (; range_gen->non_empty(); ++range_gen) { |
| 1667 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1668 | } |
| 1669 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1670 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1671 | template <typename Action, typename RangeGen> |
| 1672 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, const RangeGen &range_gen_prebuilt) { |
| 1673 | RangeGen range_gen(range_gen_prebuilt); // RangeGenerators can be expensive to create from scratch... initialize from built |
| 1674 | for (; range_gen->non_empty(); ++range_gen) { |
| 1675 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1676 | } |
| 1677 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1678 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1679 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1680 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1681 | // this is only called on gaps, and never returns a gap. |
| 1682 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1683 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1684 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1685 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1686 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1687 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1688 | auto &access_state = pos->second; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1689 | access_state.Update(usage, ordering_rule, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1690 | return pos; |
| 1691 | } |
| 1692 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1693 | UpdateMemoryAccessStateFunctor(AccessAddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1694 | SyncOrdering ordering_rule_, ResourceUsageTag tag_) |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1695 | : type(type_), context(context_), usage(usage_), ordering_rule(ordering_rule_), tag(tag_) {} |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1696 | const AccessAddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1697 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1698 | const SyncStageAccessIndex usage; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1699 | const SyncOrdering ordering_rule; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1700 | const ResourceUsageTag tag; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1701 | }; |
| 1702 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1703 | // The barrier operation for pipeline and subpass dependencies` |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1704 | struct PipelineBarrierOp { |
| 1705 | SyncBarrier barrier; |
| 1706 | bool layout_transition; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1707 | ResourceAccessState::QueueScopeOps scope; |
| 1708 | PipelineBarrierOp(QueueId queue_id, const SyncBarrier &barrier_, bool layout_transition_) |
| 1709 | : barrier(barrier_), layout_transition(layout_transition_), scope(queue_id) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1710 | PipelineBarrierOp(const PipelineBarrierOp &) = default; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1711 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(scope, barrier, layout_transition); } |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1712 | }; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1713 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 1714 | // Batch barrier ops don't modify in place, and thus don't need to hold pending state, and also are *never* layout transitions. |
| 1715 | struct BatchBarrierOp : public PipelineBarrierOp { |
| 1716 | void operator()(ResourceAccessState *access_state) const { |
| 1717 | access_state->ApplyBarrier(scope, barrier, layout_transition); |
| 1718 | access_state->ApplyPendingBarriers(kInvalidTag); // There can't be any need for this tag |
| 1719 | } |
| 1720 | BatchBarrierOp(QueueId queue_id, const SyncBarrier &barrier_) : PipelineBarrierOp(queue_id, barrier_, false) {} |
| 1721 | }; |
| 1722 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1723 | // The barrier operation for wait events |
| 1724 | struct WaitEventBarrierOp { |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 1725 | ResourceAccessState::EventScopeOps scope_ops; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1726 | SyncBarrier barrier; |
| 1727 | bool layout_transition; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1728 | |
| 1729 | WaitEventBarrierOp(const QueueId scope_queue_, const ResourceUsageTag scope_tag_, const SyncBarrier &barrier_, |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1730 | bool layout_transition_) |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 1731 | : scope_ops(scope_queue_, scope_tag_), barrier(barrier_), layout_transition(layout_transition_) {} |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 1732 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(scope_ops, barrier, layout_transition); } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1733 | }; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1734 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1735 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1736 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1737 | // of a collection is known/present. |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1738 | template <typename BarrierOp, typename OpVector = std::vector<BarrierOp>> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1739 | class ApplyBarrierOpsFunctor { |
| 1740 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1741 | using Iterator = ResourceAccessRangeMap::iterator; |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1742 | // Only called with a gap, and pos at the lower_bound(range) |
| 1743 | inline Iterator Infill(ResourceAccessRangeMap *accesses, const Iterator &pos, const ResourceAccessRange &range) const { |
| 1744 | if (!infill_default_) { |
| 1745 | return pos; |
| 1746 | } |
| 1747 | ResourceAccessState default_state; |
| 1748 | auto inserted = accesses->insert(pos, std::make_pair(range, default_state)); |
| 1749 | return inserted; |
| 1750 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1751 | |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1752 | Iterator operator()(ResourceAccessRangeMap *accesses, const Iterator &pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1753 | auto &access_state = pos->second; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1754 | for (const auto &op : barrier_ops_) { |
| 1755 | op(&access_state); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1756 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1757 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1758 | if (resolve_) { |
| 1759 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1760 | // another walk |
| 1761 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1762 | } |
| 1763 | return pos; |
| 1764 | } |
| 1765 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1766 | // 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] | 1767 | ApplyBarrierOpsFunctor(bool resolve, typename OpVector::size_type size_hint, ResourceUsageTag tag) |
| 1768 | : resolve_(resolve), infill_default_(false), barrier_ops_(), tag_(tag) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1769 | barrier_ops_.reserve(size_hint); |
| 1770 | } |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1771 | void EmplaceBack(const BarrierOp &op) { |
| 1772 | barrier_ops_.emplace_back(op); |
| 1773 | infill_default_ |= op.layout_transition; |
| 1774 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1775 | |
| 1776 | private: |
| 1777 | bool resolve_; |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1778 | bool infill_default_; |
| 1779 | OpVector barrier_ops_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1780 | const ResourceUsageTag tag_; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1781 | }; |
| 1782 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1783 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1784 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1785 | template <typename BarrierOp> |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1786 | class ApplyBarrierFunctor : public ApplyBarrierOpsFunctor<BarrierOp, small_vector<BarrierOp, 1>> { |
| 1787 | using Base = ApplyBarrierOpsFunctor<BarrierOp, small_vector<BarrierOp, 1>>; |
| 1788 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1789 | public: |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1790 | 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] | 1791 | }; |
| 1792 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1793 | // This functor resolves the pendinging state. |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1794 | class ResolvePendingBarrierFunctor : public ApplyBarrierOpsFunctor<NoopBarrierAction, small_vector<NoopBarrierAction, 1>> { |
| 1795 | using Base = ApplyBarrierOpsFunctor<NoopBarrierAction, small_vector<NoopBarrierAction, 1>>; |
| 1796 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1797 | public: |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1798 | ResolvePendingBarrierFunctor(ResourceUsageTag tag) : Base(true, 0, tag) {} |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1799 | }; |
| 1800 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1801 | void AccessContext::UpdateAccessState(AccessAddressType type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1802 | const ResourceAccessRange &range, const ResourceUsageTag tag) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1803 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1804 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1805 | } |
| 1806 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1807 | 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] | 1808 | const ResourceAccessRange &range, const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1809 | if (!SimpleBinding(buffer)) return; |
| 1810 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1811 | UpdateAccessState(AccessAddressType::kLinear, current_usage, ordering_rule, range + base_address, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1812 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1813 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1814 | 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] | 1815 | const VkImageSubresourceRange &subresource_range, const ResourceUsageTag &tag) { |
| 1816 | if (!SimpleBinding(image)) return; |
| 1817 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1818 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address, false); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1819 | const auto address_type = ImageAddressType(image); |
| 1820 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1821 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
| 1822 | } |
| 1823 | 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] | 1824 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1825 | const VkExtent3D &extent, const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1826 | if (!SimpleBinding(image)) return; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1827 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1828 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1829 | base_address, false); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1830 | const auto address_type = ImageAddressType(image); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1831 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1832 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1833 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1834 | |
| 1835 | void AccessContext::UpdateAccessState(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1836 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, const ResourceUsageTag tag) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1837 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1838 | if (!gen) return; |
| 1839 | subresource_adapter::ImageRangeGenerator range_gen(*gen); |
| 1840 | const auto address_type = view_gen.GetAddressType(); |
| 1841 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1842 | ApplyUpdateAction(address_type, action, &range_gen); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1843 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1844 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1845 | 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] | 1846 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1847 | const VkExtent3D &extent, const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1848 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1849 | subresource.layerCount}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1850 | UpdateAccessState(image, current_usage, ordering_rule, subresource_range, offset, extent, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1851 | } |
| 1852 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1853 | template <typename Action, typename RangeGen> |
| 1854 | void AccessContext::ApplyUpdateAction(AccessAddressType address_type, const Action &action, RangeGen *range_gen_arg) { |
| 1855 | assert(range_gen_arg); // Old Google C++ styleguide require non-const object pass by * not &, but this isn't an optional arg. |
| 1856 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, range_gen_arg); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1860 | void AccessContext::ApplyUpdateAction(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, const Action &action) { |
| 1861 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1862 | if (!gen) return; |
| 1863 | UpdateMemoryAccessState(&GetAccessStateMap(view_gen.GetAddressType()), action, *gen); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1864 | } |
| 1865 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1866 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, |
| 1867 | const AttachmentViewGenVector &attachment_views, uint32_t subpass, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1868 | const ResourceUsageTag tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1869 | UpdateStateResolveAction update(*this, tag); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1870 | ResolveOperation(update, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1871 | } |
| 1872 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1873 | 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] | 1874 | uint32_t subpass, const ResourceUsageTag tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1875 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1876 | |
| 1877 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1878 | if (rp_state.attachment_last_subpass[i] == subpass) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1879 | const auto &view_gen = attachment_views[i]; |
| 1880 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1881 | |
| 1882 | const auto &ci = attachment_ci[i]; |
| 1883 | const bool has_depth = FormatHasDepth(ci.format); |
| 1884 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1885 | const bool is_color = !(has_depth || has_stencil); |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1886 | 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] | 1887 | |
| 1888 | if (is_color && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1889 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1890 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1891 | } else { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1892 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1893 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1894 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1895 | } |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1896 | 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] | 1897 | if (has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1898 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1899 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | } |
| 1903 | } |
| 1904 | } |
| 1905 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1906 | template <typename Action> |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1907 | void AccessContext::ApplyToContext(const Action &barrier_action) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1908 | // 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] | 1909 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1910 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), kFullRange, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1915 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1916 | auto &context = contexts[subpass_index]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1917 | ApplyTrackbackStackAction barrier_action(context.GetDstExternalTrackBack().barriers); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1918 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1919 | context.ResolveAccessRange(address_type, kFullRange, barrier_action, &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1920 | } |
| 1921 | } |
| 1922 | } |
| 1923 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 1924 | // Caller must ensure that lifespan of this is less than from |
| 1925 | void AccessContext::ImportAsyncContexts(const AccessContext &from) { async_ = from.async_; } |
| 1926 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1927 | // Suitable only for *subpass* access contexts |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1928 | HazardResult AccessContext::DetectSubpassTransitionHazard(const TrackBack &track_back, const AttachmentViewGen &attach_view) const { |
| 1929 | if (!attach_view.IsValid()) return HazardResult(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1930 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1931 | // 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] | 1932 | assert(track_back.source_subpass); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1933 | |
| 1934 | // 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] | 1935 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1936 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1937 | HazardResult hazard = track_back.source_subpass->DetectImageBarrierHazard(attach_view, merged_barrier, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1938 | if (!hazard.hazard) { |
| 1939 | // The Async hazard check is against the current context's async set. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1940 | hazard = DetectImageBarrierHazard(attach_view, merged_barrier, kDetectAsync); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1941 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1942 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1943 | return hazard; |
| 1944 | } |
| 1945 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1946 | void AccessContext::RecordLayoutTransitions(const RENDER_PASS_STATE &rp_state, uint32_t subpass, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1947 | const AttachmentViewGenVector &attachment_views, const ResourceUsageTag tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1948 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1949 | const ResourceAccessState empty_infill; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1950 | for (const auto &transition : transitions) { |
| 1951 | const auto prev_pass = transition.prev_pass; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1952 | const auto &view_gen = attachment_views[transition.attachment]; |
| 1953 | if (!view_gen.IsValid()) continue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1954 | |
| 1955 | const auto *trackback = GetTrackBackFromSubpass(prev_pass); |
| 1956 | assert(trackback); |
| 1957 | |
| 1958 | // Import the attachments into the current context |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1959 | const auto *prev_context = trackback->source_subpass; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1960 | assert(prev_context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1961 | const auto address_type = view_gen.GetAddressType(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1962 | auto &target_map = GetAccessStateMap(address_type); |
| 1963 | ApplySubpassTransitionBarriersAction barrier_action(trackback->barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1964 | prev_context->ResolveAccessRange(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action, &target_map, |
| 1965 | &empty_infill); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1966 | } |
| 1967 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1968 | // If there were no transitions skip this global map walk |
| 1969 | if (transitions.size()) { |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1970 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1971 | ApplyToContext(apply_pending_action); |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1972 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1973 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1974 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1975 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, CMD_TYPE cmd_type) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1976 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1977 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1978 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 1979 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1980 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1981 | return skip; |
| 1982 | } |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1983 | const char *caller_name = CommandTypeString(cmd_type); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1984 | |
| 1985 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1986 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1987 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1988 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1989 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1990 | for (const auto &stage_state : pipe->stage_state) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 1991 | const auto raster_state = pipe->RasterizationState(); |
| 1992 | 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] | 1993 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1994 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1995 | for (const auto &set_binding : stage_state.descriptor_uses) { |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 1996 | 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] | 1997 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1998 | set_binding.first.binding); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1999 | const auto descriptor_type = binding_it.GetType(); |
| 2000 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 2001 | auto array_idx = 0; |
| 2002 | |
| 2003 | if (binding_it.IsVariableDescriptorCount()) { |
| 2004 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 2005 | } |
| 2006 | SyncStageAccessIndex sync_index = |
| 2007 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 2008 | |
| 2009 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 2010 | uint32_t index = i - index_range.start; |
| 2011 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 2012 | switch (descriptor->GetClass()) { |
| 2013 | case DescriptorClass::ImageSampler: |
| 2014 | case DescriptorClass::Image: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2015 | if (descriptor->Invalid()) { |
| 2016 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2017 | } |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2018 | |
| 2019 | // NOTE: ImageSamplerDescriptor inherits from ImageDescriptor, so this cast works for both types. |
| 2020 | const auto *image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 2021 | const auto *img_view_state = image_descriptor->GetImageViewState(); |
| 2022 | VkImageLayout image_layout = image_descriptor->GetImageLayout(); |
| 2023 | |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2024 | HazardResult hazard; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 2025 | // NOTE: 2D ImageViews of VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT Images are not allowed in |
| 2026 | // Descriptors, so we do not have to worry about depth slicing here. |
| 2027 | // See: VUID 00343 |
| 2028 | assert(!img_view_state->IsDepthSliced()); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2029 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2030 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2031 | |
| 2032 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 2033 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 2034 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2035 | // Input attachments are subject to raster ordering rules |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 2036 | hazard = |
| 2037 | current_context_->DetectHazard(*img_state, sync_index, subresource_range, SyncOrdering::kRaster, |
| 2038 | offset, extent, img_view_state->IsDepthSliced()); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2039 | } else { |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 2040 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
| 2041 | img_view_state->IsDepthSliced()); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2042 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2043 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 2044 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2045 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2046 | img_view_state->image_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2047 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 2048 | ", index %" PRIu32 ". Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2049 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2050 | sync_state_->report_data->FormatHandle(img_view_state->image_view()).c_str(), |
| 2051 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 2052 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2053 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 2054 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2055 | set_binding.first.binding, index, FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2056 | } |
| 2057 | break; |
| 2058 | } |
| 2059 | case DescriptorClass::TexelBuffer: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2060 | const auto *texel_descriptor = static_cast<const TexelDescriptor *>(descriptor); |
| 2061 | if (texel_descriptor->Invalid()) { |
| 2062 | continue; |
| 2063 | } |
| 2064 | const auto *buf_view_state = texel_descriptor->GetBufferViewState(); |
| 2065 | const auto *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2066 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2067 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 2068 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2069 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2070 | buf_view_state->buffer_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2071 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2072 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2073 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view()).c_str(), |
| 2074 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 2075 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2076 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2077 | string_VkDescriptorType(descriptor_type), set_binding.first.binding, index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2078 | FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2079 | } |
| 2080 | break; |
| 2081 | } |
| 2082 | case DescriptorClass::GeneralBuffer: { |
| 2083 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2084 | if (buffer_descriptor->Invalid()) { |
| 2085 | continue; |
| 2086 | } |
| 2087 | const auto *buf_state = buffer_descriptor->GetBufferState(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2088 | const ResourceAccessRange range = |
| 2089 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2090 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 2091 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2092 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2093 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2094 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2095 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2096 | sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 2097 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 2098 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2099 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2100 | string_VkDescriptorType(descriptor_type), set_binding.first.binding, index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2101 | FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2102 | } |
| 2103 | break; |
| 2104 | } |
| 2105 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2106 | default: |
| 2107 | break; |
| 2108 | } |
| 2109 | } |
| 2110 | } |
| 2111 | } |
| 2112 | return skip; |
| 2113 | } |
| 2114 | |
| 2115 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2116 | const ResourceUsageTag tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2117 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2118 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2119 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2120 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2121 | return; |
| 2122 | } |
| 2123 | |
| 2124 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 2125 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 2126 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2127 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 2128 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2129 | for (const auto &stage_state : pipe->stage_state) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2130 | const auto raster_state = pipe->RasterizationState(); |
| 2131 | 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] | 2132 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2133 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2134 | for (const auto &set_binding : stage_state.descriptor_uses) { |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 2135 | 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] | 2136 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2137 | set_binding.first.binding); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2138 | const auto descriptor_type = binding_it.GetType(); |
| 2139 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 2140 | auto array_idx = 0; |
| 2141 | |
| 2142 | if (binding_it.IsVariableDescriptorCount()) { |
| 2143 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 2144 | } |
| 2145 | SyncStageAccessIndex sync_index = |
| 2146 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 2147 | |
| 2148 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 2149 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 2150 | switch (descriptor->GetClass()) { |
| 2151 | case DescriptorClass::ImageSampler: |
| 2152 | case DescriptorClass::Image: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2153 | // NOTE: ImageSamplerDescriptor inherits from ImageDescriptor, so this cast works for both types. |
| 2154 | const auto *image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 2155 | if (image_descriptor->Invalid()) { |
| 2156 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2157 | } |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2158 | const auto *img_view_state = image_descriptor->GetImageViewState(); |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 2159 | // NOTE: 2D ImageViews of VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT Images are not allowed in |
| 2160 | // Descriptors, so we do not have to worry about depth slicing here. |
| 2161 | // See: VUID 00343 |
| 2162 | assert(!img_view_state->IsDepthSliced()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2163 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2164 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2165 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 2166 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 2167 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kRaster, |
| 2168 | img_view_state->normalized_subresource_range, offset, extent, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2169 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2170 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kNonAttachment, |
| 2171 | img_view_state->normalized_subresource_range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2172 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2173 | break; |
| 2174 | } |
| 2175 | case DescriptorClass::TexelBuffer: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2176 | const auto *texel_descriptor = static_cast<const TexelDescriptor *>(descriptor); |
| 2177 | if (texel_descriptor->Invalid()) { |
| 2178 | continue; |
| 2179 | } |
| 2180 | const auto *buf_view_state = texel_descriptor->GetBufferViewState(); |
| 2181 | const auto *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2182 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2183 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2184 | break; |
| 2185 | } |
| 2186 | case DescriptorClass::GeneralBuffer: { |
| 2187 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2188 | if (buffer_descriptor->Invalid()) { |
| 2189 | continue; |
| 2190 | } |
| 2191 | const auto *buf_state = buffer_descriptor->GetBufferState(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2192 | const ResourceAccessRange range = |
| 2193 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2194 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2195 | break; |
| 2196 | } |
| 2197 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2198 | default: |
| 2199 | break; |
| 2200 | } |
| 2201 | } |
| 2202 | } |
| 2203 | } |
| 2204 | } |
| 2205 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2206 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, CMD_TYPE cmd_type) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2207 | bool skip = false; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2208 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2209 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2210 | return skip; |
| 2211 | } |
| 2212 | |
| 2213 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2214 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2215 | const auto &binding_descriptions_size = pipe->vertex_input_state->binding_descriptions.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2216 | |
| 2217 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2218 | const auto &binding_description = pipe->vertex_input_state->binding_descriptions[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2219 | if (binding_description.binding < binding_buffers_size) { |
| 2220 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2221 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2222 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2223 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2224 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2225 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2226 | 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] | 2227 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2228 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2229 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for vertex %s in %s. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2230 | CommandTypeString(cmd_type), string_SyncHazard(hazard.hazard), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2231 | sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 2232 | 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] | 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | return skip; |
| 2237 | } |
| 2238 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2239 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag tag) { |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2240 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2241 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2242 | return; |
| 2243 | } |
| 2244 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2245 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2246 | const auto &binding_descriptions_size = pipe->vertex_input_state->binding_descriptions.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2247 | |
| 2248 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2249 | const auto &binding_description = pipe->vertex_input_state->binding_descriptions[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2250 | if (binding_description.binding < binding_buffers_size) { |
| 2251 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2252 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2253 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2254 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2255 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2256 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2257 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ, |
| 2258 | SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2259 | } |
| 2260 | } |
| 2261 | } |
| 2262 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2263 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, CMD_TYPE cmd_type) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2264 | bool skip = false; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2265 | 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] | 2266 | return skip; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2267 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2268 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2269 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2270 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2271 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2272 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2273 | 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] | 2274 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2275 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2276 | index_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for index %s in %s. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2277 | CommandTypeString(cmd_type), string_SyncHazard(hazard.hazard), |
| 2278 | sync_state_->report_data->FormatHandle(index_buf_state->buffer()).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2279 | 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] | 2280 | } |
| 2281 | |
| 2282 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2283 | // We will detect more accurate range in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2284 | skip |= ValidateDrawVertex(UINT32_MAX, 0, cmd_type); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2285 | return skip; |
| 2286 | } |
| 2287 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2288 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag tag) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2289 | 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] | 2290 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2291 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2292 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2293 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2294 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2295 | 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] | 2296 | |
| 2297 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2298 | // We will detect more accurate range in the future. |
| 2299 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 2300 | } |
| 2301 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2302 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(CMD_TYPE cmd_type) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2303 | bool skip = false; |
| 2304 | if (!current_renderpass_context_) return skip; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2305 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(GetExecutionContext(), *cb_state_.get(), cmd_type); |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2306 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2307 | } |
| 2308 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2309 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2310 | if (current_renderpass_context_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2311 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), tag); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2312 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2313 | } |
| 2314 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2315 | QueueId CommandBufferAccessContext::GetQueueId() const { return QueueSyncState::kQueueIdInvalid; } |
| 2316 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2317 | ResourceUsageTag CommandBufferAccessContext::RecordBeginRenderPass(CMD_TYPE cmd_type, const RENDER_PASS_STATE &rp_state, |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2318 | const VkRect2D &render_area, |
| 2319 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2320 | // Create an access context the current renderpass. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2321 | const auto barrier_tag = NextCommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
| 2322 | const auto load_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kLoadOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2323 | 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] | 2324 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2325 | current_renderpass_context_->RecordBeginRenderPass(barrier_tag, load_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2326 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2327 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2328 | } |
| 2329 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2330 | ResourceUsageTag CommandBufferAccessContext::RecordNextSubpass(const CMD_TYPE cmd_type) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2331 | assert(current_renderpass_context_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2332 | if (!current_renderpass_context_) return NextCommandTag(cmd_type); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2333 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2334 | auto store_tag = NextCommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kStoreOp); |
| 2335 | auto barrier_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
| 2336 | auto load_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kLoadOp); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2337 | |
| 2338 | current_renderpass_context_->RecordNextSubpass(store_tag, barrier_tag, load_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2339 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2340 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2341 | } |
| 2342 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2343 | ResourceUsageTag CommandBufferAccessContext::RecordEndRenderPass(const CMD_TYPE cmd_type) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2344 | assert(current_renderpass_context_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2345 | if (!current_renderpass_context_) return NextCommandTag(cmd_type); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2346 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2347 | auto store_tag = NextCommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kStoreOp); |
| 2348 | auto barrier_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2349 | |
| 2350 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, store_tag, barrier_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2351 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2352 | current_renderpass_context_ = nullptr; |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2353 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2354 | } |
| 2355 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2356 | void CommandBufferAccessContext::RecordDestroyEvent(VkEvent event) { |
| 2357 | // Erase is okay with the key not being |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 2358 | auto event_state = sync_state_->Get<EVENT_STATE>(event); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2359 | if (event_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 2360 | GetCurrentEventsContext()->Destroy(event_state.get()); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2361 | } |
| 2362 | } |
| 2363 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2364 | // The is the recorded cb context |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2365 | bool CommandBufferAccessContext::ValidateFirstUse(CommandExecutionContext *proxy_context, const char *func_name, |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2366 | uint32_t index) const { |
| 2367 | assert(proxy_context); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2368 | SyncEventsContext *const events_context = proxy_context->GetCurrentEventsContext(); |
| 2369 | AccessContext *const access_context = proxy_context->GetCurrentAccessContext(); |
| 2370 | const QueueId queue_id = proxy_context->GetQueueId(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2371 | const ResourceUsageTag base_tag = proxy_context->GetTagLimit(); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2372 | bool skip = false; |
| 2373 | ResourceUsageRange tag_range = {0, 0}; |
| 2374 | const AccessContext *recorded_context = GetCurrentAccessContext(); |
| 2375 | assert(recorded_context); |
| 2376 | HazardResult hazard; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2377 | 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] | 2378 | uint32_t index) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2379 | const auto handle = exec_context.Handle(); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2380 | const auto recorded_handle = cb_state_->commandBuffer(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2381 | const auto *report_data = sync_state_->report_data; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2382 | return sync_state_->LogError(handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2383 | "%s: Hazard %s for entry %" PRIu32 ", %s, Recorded access info %s. Access info %s.", func_name, |
| 2384 | string_SyncHazard(hazard.hazard), index, report_data->FormatHandle(recorded_handle).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2385 | FormatUsage(*hazard.recorded_access).c_str(), exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2386 | }; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2387 | const ReplayTrackbackBarriersAction *replay_context = nullptr; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2388 | for (const auto &sync_op : sync_ops_) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2389 | // we update the range to any include layout transition first use writes, |
| 2390 | // as they are stored along with the source scope (as effective barrier) when recorded |
| 2391 | tag_range.end = sync_op.tag + 1; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 2392 | 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] | 2393 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2394 | hazard = recorded_context->DetectFirstUseHazard(queue_id, tag_range, *access_context, replay_context); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2395 | if (hazard.hazard) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2396 | skip |= log_msg(hazard, *proxy_context, func_name, index); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2397 | } |
| 2398 | // 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] | 2399 | // Record the barrier into the proxy context. |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2400 | sync_op.sync_op->ReplayRecord(queue_id, base_tag + sync_op.tag, access_context, events_context); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2401 | replay_context = sync_op.sync_op->GetReplayTrackback(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2402 | tag_range.begin = tag_range.end; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2403 | } |
| 2404 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2405 | // Renderpasses may not cross command buffer boundaries |
| 2406 | assert(replay_context == nullptr); |
| 2407 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2408 | // and anything after the last syncop |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2409 | tag_range.end = ResourceUsageRecord::kMaxIndex; |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2410 | hazard = recorded_context->DetectFirstUseHazard(queue_id, tag_range, *access_context, replay_context); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2411 | if (hazard.hazard) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2412 | skip |= log_msg(hazard, *proxy_context, func_name, index); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | return skip; |
| 2416 | } |
| 2417 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2418 | void CommandBufferAccessContext::RecordExecutedCommandBuffer(const CommandBufferAccessContext &recorded_cb_context) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2419 | SyncEventsContext *const events_context = GetCurrentEventsContext(); |
| 2420 | AccessContext *const access_context = GetCurrentAccessContext(); |
| 2421 | const QueueId queue_id = GetQueueId(); |
| 2422 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2423 | const AccessContext *recorded_context = recorded_cb_context.GetCurrentAccessContext(); |
| 2424 | assert(recorded_context); |
| 2425 | |
| 2426 | // Just run through the barriers ignoring the usage from the recorded context, as Resolve will overwrite outdated state |
| 2427 | const ResourceUsageTag base_tag = GetTagLimit(); |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2428 | for (const auto &sync_op : recorded_cb_context.GetSyncOps()) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2429 | // we update the range to any include layout transition first use writes, |
| 2430 | // as they are stored along with the source scope (as effective barrier) when recorded |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2431 | sync_op.sync_op->ReplayRecord(queue_id, base_tag + sync_op.tag, access_context, events_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | ResourceUsageRange tag_range = ImportRecordedAccessLog(recorded_cb_context); |
| 2435 | assert(base_tag == tag_range.begin); // to ensure the to offset calculation agree |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 2436 | ResolveExecutedCommandBuffer(*recorded_context, tag_range.begin); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2437 | } |
| 2438 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 2439 | void CommandBufferAccessContext::ResolveExecutedCommandBuffer(const AccessContext &recorded_context, ResourceUsageTag offset) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2440 | auto tag_offset = [offset](ResourceAccessState *access) { access->OffsetTag(offset); }; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 2441 | GetCurrentAccessContext()->ResolveFromContext(tag_offset, recorded_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2442 | } |
| 2443 | |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2444 | ResourceUsageRange CommandExecutionContext::ImportRecordedAccessLog(const CommandBufferAccessContext &recorded_context) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2445 | // The execution references ensure lifespan for the referenced child CB's... |
| 2446 | ResourceUsageRange tag_range(GetTagLimit(), 0); |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2447 | InsertRecordedAccessLogEntries(recorded_context); |
| 2448 | tag_range.end = GetTagLimit(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2449 | return tag_range; |
| 2450 | } |
| 2451 | |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2452 | void CommandBufferAccessContext::InsertRecordedAccessLogEntries(const CommandBufferAccessContext &recorded_context) { |
| 2453 | cbs_referenced_.emplace(recorded_context.GetCBStateShared()); |
| 2454 | access_log_.insert(access_log_.end(), recorded_context.access_log_.cbegin(), recorded_context.access_log_.end()); |
| 2455 | } |
| 2456 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2457 | ResourceUsageTag CommandBufferAccessContext::NextSubcommandTag(CMD_TYPE command, ResourceUsageRecord::SubcommandType subcommand) { |
| 2458 | ResourceUsageTag next = access_log_.size(); |
| 2459 | access_log_.emplace_back(command, command_number_, subcommand, ++subcommand_number_, cb_state_.get(), reset_count_); |
| 2460 | return next; |
| 2461 | } |
| 2462 | |
| 2463 | ResourceUsageTag CommandBufferAccessContext::NextCommandTag(CMD_TYPE command, ResourceUsageRecord::SubcommandType subcommand) { |
| 2464 | command_number_++; |
| 2465 | subcommand_number_ = 0; |
| 2466 | ResourceUsageTag next = access_log_.size(); |
| 2467 | access_log_.emplace_back(command, command_number_, subcommand, subcommand_number_, cb_state_.get(), reset_count_); |
| 2468 | return next; |
| 2469 | } |
| 2470 | |
| 2471 | ResourceUsageTag CommandBufferAccessContext::NextIndexedCommandTag(CMD_TYPE command, uint32_t index) { |
| 2472 | if (index == 0) { |
| 2473 | return NextCommandTag(command, ResourceUsageRecord::SubcommandType::kIndex); |
| 2474 | } |
| 2475 | return NextSubcommandTag(command, ResourceUsageRecord::SubcommandType::kIndex); |
| 2476 | } |
| 2477 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2478 | void CommandBufferAccessContext::RecordSyncOp(SyncOpPointer &&sync_op) { |
| 2479 | auto tag = sync_op->Record(this); |
| 2480 | // As renderpass operations can have side effects on the command buffer access context, |
| 2481 | // update the sync operation to record these if any. |
| 2482 | if (current_renderpass_context_) { |
| 2483 | const auto &rpc = *current_renderpass_context_; |
| 2484 | sync_op->SetReplayContext(rpc.GetCurrentSubpass(), rpc.GetReplayContext()); |
| 2485 | } |
| 2486 | sync_ops_.emplace_back(tag, std::move(sync_op)); |
| 2487 | } |
| 2488 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2489 | class HazardDetectFirstUse { |
| 2490 | public: |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2491 | HazardDetectFirstUse(const ResourceAccessState &recorded_use, QueueId queue_id, const ResourceUsageRange &tag_range, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2492 | const ReplayTrackbackBarriersAction *replay_barrier) |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2493 | : recorded_use_(recorded_use), queue_id_(queue_id), tag_range_(tag_range), replay_barrier_(replay_barrier) {} |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2494 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2495 | if (replay_barrier_) { |
| 2496 | // Intentional copy to apply the replay barrier |
| 2497 | auto access = pos->second; |
| 2498 | (*replay_barrier_)(&access); |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2499 | return access.DetectHazard(recorded_use_, queue_id_, tag_range_); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2500 | } |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2501 | return pos->second.DetectHazard(recorded_use_, queue_id_, tag_range_); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2502 | } |
| 2503 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
| 2504 | return pos->second.DetectAsyncHazard(recorded_use_, tag_range_, start_tag); |
| 2505 | } |
| 2506 | |
| 2507 | private: |
| 2508 | const ResourceAccessState &recorded_use_; |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2509 | const QueueId queue_id_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2510 | const ResourceUsageRange &tag_range_; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2511 | const ReplayTrackbackBarriersAction *replay_barrier_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2512 | }; |
| 2513 | |
| 2514 | // This is called with the *recorded* command buffers access context, with the *active* access context pass in, againsts which |
| 2515 | // hazards will be detected |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2516 | HazardResult AccessContext::DetectFirstUseHazard(QueueId queue_id, const ResourceUsageRange &tag_range, |
| 2517 | const AccessContext &access_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2518 | const ReplayTrackbackBarriersAction *replay_barrier) const { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2519 | HazardResult hazard; |
| 2520 | for (const auto address_type : kAddressTypes) { |
| 2521 | const auto &recorded_access_map = GetAccessStateMap(address_type); |
| 2522 | for (const auto &recorded_access : recorded_access_map) { |
| 2523 | // Cull any entries not in the current tag range |
| 2524 | if (!recorded_access.second.FirstAccessInTagRange(tag_range)) continue; |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 2525 | HazardDetectFirstUse detector(recorded_access.second, queue_id, tag_range, replay_barrier); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2526 | hazard = access_context.DetectHazard(address_type, detector, recorded_access.first, DetectOptions::kDetectAll); |
| 2527 | if (hazard.hazard) break; |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | return hazard; |
| 2532 | } |
| 2533 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2534 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const CommandExecutionContext &exec_context, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2535 | const CMD_BUFFER_STATE &cmd_buffer, CMD_TYPE cmd_type) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2536 | bool skip = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2537 | const auto &sync_state = exec_context.GetSyncState(); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2538 | const auto *pipe = cmd_buffer.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2539 | if (!pipe) { |
| 2540 | return skip; |
| 2541 | } |
| 2542 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2543 | const auto raster_state = pipe->RasterizationState(); |
| 2544 | if (raster_state && raster_state->rasterizerDiscardEnable) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2545 | return skip; |
| 2546 | } |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2547 | const char *caller_name = CommandTypeString(cmd_type); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2548 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2549 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2550 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2551 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2552 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2553 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2554 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2555 | if (location >= subpass.colorAttachmentCount || |
| 2556 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2557 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2558 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2559 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2560 | if (!view_gen.IsValid()) continue; |
| 2561 | HazardResult hazard = |
| 2562 | current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2563 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2564 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2565 | const VkImageView view_handle = view_gen.GetViewState()->image_view(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2566 | skip |= sync_state.LogError(view_handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2567 | "%s: Hazard %s for %s in %s, Subpass #%d, and pColorAttachments #%d. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2568 | caller_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2569 | sync_state.report_data->FormatHandle(view_handle).c_str(), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2570 | sync_state.report_data->FormatHandle(cmd_buffer.commandBuffer()).c_str(), |
| 2571 | cmd_buffer.activeSubpass, location, exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2572 | } |
| 2573 | } |
| 2574 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2575 | |
| 2576 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2577 | // 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] | 2578 | const auto ds_state = pipe->DepthStencilState(); |
| 2579 | const uint32_t depth_stencil_attachment = GetSubpassDepthStencilAttachmentIndex(ds_state, subpass.pDepthStencilAttachment); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2580 | |
| 2581 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2582 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2583 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2584 | bool depth_write = false, stencil_write = false; |
| 2585 | |
| 2586 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2587 | 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] | 2588 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2589 | depth_write = true; |
| 2590 | } |
| 2591 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2592 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2593 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2594 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2595 | if (!FormatIsDepthOnly(view_state.create_info.format) && ds_state->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2596 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2597 | stencil_write = true; |
| 2598 | } |
| 2599 | |
| 2600 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2601 | if (depth_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2602 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2603 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2604 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2605 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2606 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2607 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2608 | "%s: Hazard %s for %s in %s, Subpass #%d, and depth part of pDepthStencilAttachment. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2609 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2610 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2611 | sync_state.report_data->FormatHandle(cmd_buffer.commandBuffer()).c_str(), cmd_buffer.activeSubpass, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2612 | exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2613 | } |
| 2614 | } |
| 2615 | if (stencil_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2616 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2617 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2618 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2619 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2620 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2621 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2622 | "%s: Hazard %s for %s in %s, Subpass #%d, and stencil part of pDepthStencilAttachment. Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2623 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2624 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2625 | sync_state.report_data->FormatHandle(cmd_buffer.commandBuffer()).c_str(), cmd_buffer.activeSubpass, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2626 | exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2627 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2628 | } |
| 2629 | } |
| 2630 | return skip; |
| 2631 | } |
| 2632 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2633 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd_buffer, const ResourceUsageTag tag) { |
| 2634 | const auto *pipe = cmd_buffer.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2635 | if (!pipe) { |
| 2636 | return; |
| 2637 | } |
| 2638 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2639 | const auto *raster_state = pipe->RasterizationState(); |
| 2640 | if (raster_state && raster_state->rasterizerDiscardEnable) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2641 | return; |
| 2642 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2643 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2644 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2645 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2646 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2647 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2648 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2649 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2650 | if (location >= subpass.colorAttachmentCount || |
| 2651 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2652 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2653 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2654 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2655 | current_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2656 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment, |
| 2657 | tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2658 | } |
| 2659 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2660 | |
| 2661 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2662 | // 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] | 2663 | const auto *ds_state = pipe->DepthStencilState(); |
| 2664 | const uint32_t depth_stencil_attachment = GetSubpassDepthStencilAttachmentIndex(ds_state, subpass.pDepthStencilAttachment); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2665 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2666 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2667 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2668 | bool depth_write = false, stencil_write = false; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2669 | const bool has_depth = 0 != (view_state.normalized_subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 2670 | 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] | 2671 | |
| 2672 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2673 | if (has_depth && !FormatIsStencilOnly(view_state.create_info.format) && ds_state->depthTestEnable && |
| 2674 | ds_state->depthWriteEnable && IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2675 | depth_write = true; |
| 2676 | } |
| 2677 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2678 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2679 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2680 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2681 | if (has_stencil && !FormatIsDepthOnly(view_state.create_info.format) && ds_state->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2682 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2683 | stencil_write = true; |
| 2684 | } |
| 2685 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2686 | if (depth_write || stencil_write) { |
| 2687 | const auto ds_gentype = view_gen.GetDepthStencilRenderAreaGenType(depth_write, stencil_write); |
| 2688 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2689 | current_context.UpdateAccessState(view_gen, ds_gentype, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2690 | SyncOrdering::kDepthStencilAttachment, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2691 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2692 | } |
| 2693 | } |
| 2694 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2695 | bool RenderPassAccessContext::ValidateNextSubpass(const CommandExecutionContext &exec_context, CMD_TYPE cmd_type) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2696 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2697 | bool skip = false; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2698 | skip |= CurrentContext().ValidateResolveOperations(exec_context, *rp_state_, render_area_, attachment_views_, cmd_type, |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2699 | current_subpass_); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2700 | skip |= CurrentContext().ValidateStoreOperation(exec_context, *rp_state_, render_area_, current_subpass_, attachment_views_, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2701 | cmd_type); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2702 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2703 | const auto next_subpass = current_subpass_ + 1; |
ziga-lunarg | 31a3e77 | 2022-03-22 11:48:46 +0100 | [diff] [blame] | 2704 | if (next_subpass >= subpass_contexts_.size()) { |
| 2705 | return skip; |
| 2706 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2707 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2708 | skip |= |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2709 | next_context.ValidateLayoutTransitions(exec_context, *rp_state_, render_area_, next_subpass, attachment_views_, cmd_type); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2710 | if (!skip) { |
| 2711 | // To avoid complex (and buggy) duplication of the affect of layout transitions on load operations, we'll record them |
| 2712 | // on a copy of the (empty) next context. |
| 2713 | // Note: The resource access map should be empty so hopefully this copy isn't too horrible from a perf POV. |
| 2714 | AccessContext temp_context(next_context); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2715 | temp_context.RecordLayoutTransitions(*rp_state_, next_subpass, attachment_views_, kInvalidTag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2716 | skip |= |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2717 | temp_context.ValidateLoadOperation(exec_context, *rp_state_, render_area_, next_subpass, attachment_views_, cmd_type); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2718 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2719 | return skip; |
| 2720 | } |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2721 | bool RenderPassAccessContext::ValidateEndRenderPass(const CommandExecutionContext &exec_context, CMD_TYPE cmd_type) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2722 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2723 | bool skip = false; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2724 | skip |= CurrentContext().ValidateResolveOperations(exec_context, *rp_state_, render_area_, attachment_views_, cmd_type, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2725 | current_subpass_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2726 | skip |= CurrentContext().ValidateStoreOperation(exec_context, *rp_state_, render_area_, current_subpass_, attachment_views_, |
| 2727 | cmd_type); |
| 2728 | skip |= ValidateFinalSubpassLayoutTransitions(exec_context, cmd_type); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2729 | return skip; |
| 2730 | } |
| 2731 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2732 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy() const { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2733 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, attachment_views_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2734 | } |
| 2735 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2736 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const CommandExecutionContext &exec_context, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2737 | CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2738 | bool skip = false; |
| 2739 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2740 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2741 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2742 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2743 | // to apply and only copy then, if this proves a hot spot. |
| 2744 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2745 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2746 | // Validate the "finalLayout" transitions to external |
| 2747 | // Get them from where there we're hidding in the extra entry. |
| 2748 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2749 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2750 | const auto &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2751 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2752 | assert(trackback.source_subpass); // Transitions are given implicit transitions if the StateTracker is working correctly |
| 2753 | auto *context = trackback.source_subpass; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2754 | |
| 2755 | if (transition.prev_pass == current_subpass_) { |
| 2756 | if (!proxy_for_current) { |
| 2757 | // 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] | 2758 | proxy_for_current.reset(CreateStoreResolveProxy()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2759 | } |
| 2760 | context = proxy_for_current.get(); |
| 2761 | } |
| 2762 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2763 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2764 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2765 | auto hazard = context->DetectImageBarrierHazard(view_gen, merged_barrier, AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2766 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2767 | const char *func_name = CommandTypeString(cmd_type); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2768 | if (hazard.tag == kInvalidTag) { |
| 2769 | // Hazard vs. ILT |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2770 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2771 | rp_state_->renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 2772 | "%s: Hazard %s vs. store/resolve operations in subpass %" PRIu32 " for attachment %" PRIu32 |
| 2773 | " final image layout transition (old_layout: %s, new_layout: %s).", |
| 2774 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2775 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout)); |
| 2776 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2777 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2778 | rp_state_->renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 2779 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
| 2780 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 2781 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2782 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2783 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2784 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2785 | } |
| 2786 | } |
| 2787 | return skip; |
| 2788 | } |
| 2789 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2790 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2791 | // Add layout transitions... |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2792 | subpass_contexts_[current_subpass_].RecordLayoutTransitions(*rp_state_, current_subpass_, attachment_views_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2793 | } |
| 2794 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2795 | void RenderPassAccessContext::RecordLoadOperations(const ResourceUsageTag tag) { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2796 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2797 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2798 | |
| 2799 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2800 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2801 | const AttachmentViewGen &view_gen = attachment_views_[i]; |
| 2802 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2803 | |
| 2804 | const auto &ci = attachment_ci[i]; |
| 2805 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2806 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2807 | const bool is_color = !(has_depth || has_stencil); |
| 2808 | |
| 2809 | if (is_color) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2810 | const SyncStageAccessIndex load_op = ColorLoadUsage(ci.loadOp); |
| 2811 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2812 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, load_op, |
| 2813 | SyncOrdering::kColorAttachment, tag); |
| 2814 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2815 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2816 | if (has_depth) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2817 | const SyncStageAccessIndex load_op = DepthStencilLoadUsage(ci.loadOp); |
| 2818 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2819 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_op, |
| 2820 | SyncOrdering::kDepthStencilAttachment, tag); |
| 2821 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2822 | } |
| 2823 | if (has_stencil) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2824 | const SyncStageAccessIndex load_op = DepthStencilLoadUsage(ci.stencilLoadOp); |
| 2825 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2826 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, load_op, |
| 2827 | SyncOrdering::kDepthStencilAttachment, tag); |
| 2828 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2829 | } |
| 2830 | } |
| 2831 | } |
| 2832 | } |
| 2833 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2834 | AttachmentViewGenVector RenderPassAccessContext::CreateAttachmentViewGen( |
| 2835 | const VkRect2D &render_area, const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
| 2836 | AttachmentViewGenVector view_gens; |
| 2837 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2838 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2839 | view_gens.reserve(attachment_views.size()); |
| 2840 | for (const auto *view : attachment_views) { |
| 2841 | view_gens.emplace_back(view, offset, extent); |
| 2842 | } |
| 2843 | return view_gens; |
| 2844 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2845 | RenderPassAccessContext::RenderPassAccessContext(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2846 | VkQueueFlags queue_flags, |
| 2847 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2848 | const AccessContext *external_context) |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2849 | : 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] | 2850 | // 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] | 2851 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2852 | replay_context_ = std::make_shared<ReplayRenderpassContext>(); |
| 2853 | auto &replay_subpass_contexts = replay_context_->subpass_contexts; |
| 2854 | replay_subpass_contexts.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2855 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2856 | 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] | 2857 | 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] | 2858 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2859 | attachment_views_ = CreateAttachmentViewGen(render_area, attachment_views); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2860 | } |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2861 | void RenderPassAccessContext::RecordBeginRenderPass(const ResourceUsageTag barrier_tag, const ResourceUsageTag load_tag) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2862 | assert(0 == current_subpass_); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2863 | subpass_contexts_[current_subpass_].SetStartTag(barrier_tag); |
| 2864 | RecordLayoutTransitions(barrier_tag); |
| 2865 | RecordLoadOperations(load_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2866 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2867 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2868 | void RenderPassAccessContext::RecordNextSubpass(const ResourceUsageTag store_tag, const ResourceUsageTag barrier_tag, |
| 2869 | const ResourceUsageTag load_tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2870 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2871 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
| 2872 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2873 | |
ziga-lunarg | 31a3e77 | 2022-03-22 11:48:46 +0100 | [diff] [blame] | 2874 | if (current_subpass_ + 1 >= subpass_contexts_.size()) { |
| 2875 | return; |
| 2876 | } |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 2877 | // Move to the next sub-command for the new subpass. The resolve and store are logically part of the previous |
| 2878 | // 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] | 2879 | current_subpass_++; |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2880 | subpass_contexts_[current_subpass_].SetStartTag(barrier_tag); |
| 2881 | RecordLayoutTransitions(barrier_tag); |
| 2882 | RecordLoadOperations(load_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2883 | } |
| 2884 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2885 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const ResourceUsageTag store_tag, |
| 2886 | const ResourceUsageTag barrier_tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2887 | // Add the resolve and store accesses |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2888 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
| 2889 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2890 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2891 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2892 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2893 | |
| 2894 | // Add the "finalLayout" transitions to external |
| 2895 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2896 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2897 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2898 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2899 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2900 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2901 | const AttachmentViewGen &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2902 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2903 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.source_subpass); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2904 | ApplyBarrierOpsFunctor<PipelineBarrierOp> barrier_action(true /* resolve */, last_trackback.barriers.size(), barrier_tag); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2905 | for (const auto &barrier : last_trackback.barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2906 | barrier_action.EmplaceBack(PipelineBarrierOp(QueueSyncState::kQueueIdInvalid, barrier, true)); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2907 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2908 | external_context->ApplyUpdateAction(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2909 | } |
| 2910 | } |
| 2911 | |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2912 | SyncExecScope SyncExecScope::MakeSrc(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param, |
| 2913 | const VkPipelineStageFlags2KHR disabled_feature_mask) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2914 | SyncExecScope result; |
| 2915 | result.mask_param = mask_param; |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2916 | 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] | 2917 | result.exec_scope = sync_utils::WithEarlierPipelineStages(result.expanded_mask); |
Jeremy Gebben | 87fd042 | 2022-06-08 15:43:47 -0600 | [diff] [blame] | 2918 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2919 | return result; |
| 2920 | } |
| 2921 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2922 | SyncExecScope SyncExecScope::MakeDst(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2923 | SyncExecScope result; |
| 2924 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2925 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2926 | result.exec_scope = sync_utils::WithLaterPipelineStages(result.expanded_mask); |
Jeremy Gebben | 87fd042 | 2022-06-08 15:43:47 -0600 | [diff] [blame] | 2927 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2928 | return result; |
| 2929 | } |
| 2930 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 2931 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst) |
| 2932 | : src_exec_scope(src), src_access_scope(0), dst_exec_scope(dst), dst_access_scope(0) {} |
| 2933 | |
| 2934 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst, const SyncBarrier::AllAccess &) |
| 2935 | : src_exec_scope(src), src_access_scope(src.valid_accesses), dst_exec_scope(dst), dst_access_scope(src.valid_accesses) {} |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2936 | |
| 2937 | template <typename Barrier> |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 2938 | SyncBarrier::SyncBarrier(const Barrier &barrier, const SyncExecScope &src, const SyncExecScope &dst) |
| 2939 | : src_exec_scope(src), |
| 2940 | src_access_scope(SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask)), |
| 2941 | dst_exec_scope(dst), |
| 2942 | dst_access_scope(SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask)) {} |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2943 | |
| 2944 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &subpass) { |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2945 | const auto barrier = lvl_find_in_chain<VkMemoryBarrier2KHR>(subpass.pNext); |
| 2946 | if (barrier) { |
| 2947 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier->srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2948 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2949 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier->srcAccessMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2950 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2951 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier->dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2952 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2953 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier->dstAccessMask); |
| 2954 | |
| 2955 | } else { |
| 2956 | auto src = SyncExecScope::MakeSrc(queue_flags, subpass.srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2957 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2958 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, subpass.srcAccessMask); |
| 2959 | |
| 2960 | auto dst = SyncExecScope::MakeDst(queue_flags, subpass.dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2961 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2962 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, subpass.dstAccessMask); |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | template <typename Barrier> |
| 2967 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const Barrier &barrier) { |
| 2968 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 2969 | src_exec_scope = src.exec_scope; |
| 2970 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
| 2971 | |
| 2972 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2973 | dst_exec_scope = dst.exec_scope; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2974 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2975 | } |
| 2976 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2977 | // Apply a list of barriers, without resolving pending state, useful for subpass layout transitions |
| 2978 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2979 | const UntaggedScopeOps scope; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2980 | for (const auto &barrier : barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2981 | ApplyBarrier(scope, barrier, layout_transition); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2982 | } |
| 2983 | } |
| 2984 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2985 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2986 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2987 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2988 | void ResourceAccessState::ApplyBarriersImmediate(const std::vector<SyncBarrier> &barriers) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2989 | 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] | 2990 | assert(pending_write_barriers.none()); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2991 | assert(!pending_write_dep_chain); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2992 | const UntaggedScopeOps scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2993 | for (const auto &barrier : barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2994 | ApplyBarrier(scope, barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2995 | } |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2996 | ApplyPendingBarriers(kInvalidTag); // There can't be any need for this tag |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2997 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2998 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2999 | HazardResult hazard; |
| 3000 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3001 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3002 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3003 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3004 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3005 | } |
| 3006 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3007 | // Write operation: |
| 3008 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 3009 | // If reads exists -- test only against them because either: |
| 3010 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 3011 | // * 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 |
| 3012 | // the current write happens after the reads, so just test the write against the reades |
| 3013 | // Otherwise test against last_write |
| 3014 | // |
| 3015 | // Look for casus belli for WAR |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3016 | if (last_reads.size()) { |
| 3017 | for (const auto &read_access : last_reads) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3018 | if (IsReadHazard(usage_stage, read_access)) { |
| 3019 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3020 | break; |
| 3021 | } |
| 3022 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3023 | } else if (last_write.any() && IsWriteHazard(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3024 | // Write-After-Write check -- if we have a previous write to test against |
| 3025 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3026 | } |
| 3027 | } |
| 3028 | return hazard; |
| 3029 | } |
| 3030 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3031 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrdering ordering_rule, |
| 3032 | QueueId queue_id) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3033 | const auto &ordering = GetOrderingRules(ordering_rule); |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3034 | return DetectHazard(usage_index, ordering, queue_id); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3035 | } |
| 3036 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3037 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const OrderingBarrier &ordering, |
| 3038 | QueueId queue_id) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 3039 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 3040 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3041 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3042 | const auto usage_stage = PipelineStageBit(usage_index); |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3043 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3044 | const bool last_write_is_ordered = (last_write & ordering.access_scope).any() && (write_queue == queue_id); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3045 | if (IsRead(usage_bit)) { |
| 3046 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 3047 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 3048 | if (is_raw_hazard) { |
| 3049 | // NOTE: we know last_write is non-zero |
| 3050 | // See if the ordering rules save us from the simple RAW check above |
| 3051 | // First check to see if the current usage is covered by the ordering rules |
| 3052 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 3053 | const bool usage_is_ordered = |
| 3054 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 3055 | if (usage_is_ordered) { |
| 3056 | // Now see of the most recent write (or a subsequent read) are ordered |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3057 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(queue_id, ordering)); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3058 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3059 | } |
| 3060 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3061 | if (is_raw_hazard) { |
| 3062 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 3063 | } |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 3064 | } else if (usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION) { |
| 3065 | // For Image layout transitions, the barrier represents the first synchronization/access scope of the layout transition |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3066 | return DetectBarrierHazard(usage_index, queue_id, ordering.exec_scope, ordering.access_scope); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3067 | } else { |
| 3068 | // Only check for WAW if there are no reads since last_write |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3069 | bool usage_write_is_ordered = (usage_bit & ordering.access_scope).any(); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3070 | if (last_reads.size()) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3071 | // Look for any WAR hazards outside the ordered set of stages |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3072 | VkPipelineStageFlags2KHR ordered_stages = 0; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3073 | if (usage_write_is_ordered) { |
| 3074 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3075 | ordered_stages = GetOrderedStages(queue_id, ordering); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3076 | } |
| 3077 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 3078 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3079 | for (const auto &read_access : last_reads) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3080 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 3081 | if (IsReadHazard(usage_stage, read_access)) { |
| 3082 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3083 | break; |
| 3084 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3085 | } |
| 3086 | } |
John Zulauf | 2a344ca | 2021-09-09 17:07:19 -0600 | [diff] [blame] | 3087 | } else if (last_write.any() && !(last_write_is_ordered && usage_write_is_ordered)) { |
| 3088 | bool ilt_ilt_hazard = false; |
| 3089 | if ((usage_index == SYNC_IMAGE_LAYOUT_TRANSITION) && (usage_bit == last_write)) { |
| 3090 | // ILT after ILT is a special case where we check the 2nd access scope of the first ILT against the first access |
| 3091 | // scope of the second ILT, which has been passed (smuggled?) in the ordering barrier |
| 3092 | ilt_ilt_hazard = !(write_barriers & ordering.access_scope).any(); |
| 3093 | } |
| 3094 | if (ilt_ilt_hazard || IsWriteHazard(usage_bit)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3095 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3096 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | return hazard; |
| 3100 | } |
| 3101 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3102 | HazardResult ResourceAccessState::DetectHazard(const ResourceAccessState &recorded_use, QueueId queue_id, |
| 3103 | const ResourceUsageRange &tag_range) const { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3104 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3105 | using Size = FirstAccesses::size_type; |
| 3106 | const auto &recorded_accesses = recorded_use.first_accesses_; |
| 3107 | Size count = recorded_accesses.size(); |
| 3108 | if (count) { |
| 3109 | const auto &last_access = recorded_accesses.back(); |
| 3110 | bool do_write_last = IsWrite(last_access.usage_index); |
| 3111 | if (do_write_last) --count; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3112 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3113 | for (Size i = 0; i < count; ++count) { |
| 3114 | const auto &first = recorded_accesses[i]; |
| 3115 | // Skip and quit logic |
| 3116 | if (first.tag < tag_range.begin) continue; |
| 3117 | if (first.tag >= tag_range.end) { |
| 3118 | do_write_last = false; // ignore last since we know it can't be in tag_range |
| 3119 | break; |
| 3120 | } |
| 3121 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3122 | hazard = DetectHazard(first.usage_index, first.ordering_rule, queue_id); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3123 | if (hazard.hazard) { |
| 3124 | hazard.AddRecordedAccess(first); |
| 3125 | break; |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | if (do_write_last && tag_range.includes(last_access.tag)) { |
| 3130 | // Writes are a bit special... both for the "most recent" access logic, and layout transition specific logic |
| 3131 | OrderingBarrier barrier = GetOrderingRules(last_access.ordering_rule); |
| 3132 | if (last_access.usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION) { |
| 3133 | // Or in the layout first access scope as a barrier... IFF the usage is an ILT |
| 3134 | // this was saved off in the "apply barriers" logic to simplify ILT access checks as they straddle |
| 3135 | // the barrier that applies them |
| 3136 | barrier |= recorded_use.first_write_layout_ordering_; |
| 3137 | } |
| 3138 | // Any read stages present in the recorded context (this) are most recent to the write, and thus mask those stages in |
| 3139 | // the active context |
| 3140 | if (recorded_use.first_read_stages_) { |
| 3141 | // we need to ignore the first use read stage in the active context (so we add them to the ordering rule), |
| 3142 | // reads in the active context are not "most recent" as all recorded context operations are *after* them |
| 3143 | // This supresses only RAW checks for stages present in the recorded context, but not those only present in the |
| 3144 | // active context. |
| 3145 | barrier.exec_scope |= recorded_use.first_read_stages_; |
| 3146 | // if there are any first use reads, we suppress WAW by injecting the active context write in the ordering rule |
| 3147 | barrier.access_scope |= FlagBit(last_access.usage_index); |
| 3148 | } |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3149 | hazard = DetectHazard(last_access.usage_index, barrier, queue_id); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3150 | if (hazard.hazard) { |
| 3151 | hazard.AddRecordedAccess(last_access); |
| 3152 | } |
| 3153 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3154 | } |
| 3155 | return hazard; |
| 3156 | } |
| 3157 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3158 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3159 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index, const ResourceUsageTag start_tag) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3160 | HazardResult hazard; |
| 3161 | auto usage = FlagBit(usage_index); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 3162 | // Async checks need to not go back further than the start of the subpass, as we only want to find hazards between the async |
| 3163 | // subpasses. Anything older than that should have been checked at the start of each subpass, taking into account all of |
| 3164 | // the raster ordering rules. |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3165 | if (IsRead(usage)) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3166 | if (last_write.any() && (write_tag >= start_tag)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3167 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3168 | } |
| 3169 | } else { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3170 | if (last_write.any() && (write_tag >= start_tag)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3171 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3172 | } else if (last_reads.size() > 0) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 3173 | // 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] | 3174 | for (const auto &read_access : last_reads) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3175 | if (read_access.tag >= start_tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3176 | 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] | 3177 | break; |
| 3178 | } |
| 3179 | } |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | return hazard; |
| 3183 | } |
| 3184 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3185 | HazardResult ResourceAccessState::DetectAsyncHazard(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range, |
| 3186 | ResourceUsageTag start_tag) const { |
| 3187 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3188 | for (const auto &first : recorded_use.first_accesses_) { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3189 | // Skip and quit logic |
| 3190 | if (first.tag < tag_range.begin) continue; |
| 3191 | if (first.tag >= tag_range.end) break; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3192 | |
| 3193 | hazard = DetectAsyncHazard(first.usage_index, start_tag); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3194 | if (hazard.hazard) { |
| 3195 | hazard.AddRecordedAccess(first); |
| 3196 | break; |
| 3197 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3198 | } |
| 3199 | return hazard; |
| 3200 | } |
| 3201 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3202 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, QueueId queue_id, |
| 3203 | VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3204 | const SyncStageAccessFlags &src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3205 | // Only supporting image layout transitions for now |
| 3206 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 3207 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3208 | // only test for WAW if there no intervening read operations. |
| 3209 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3210 | if (last_reads.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3211 | // Look at the reads if any |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3212 | for (const auto &read_access : last_reads) { |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3213 | if (read_access.IsReadBarrierHazard(queue_id, src_exec_scope)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3214 | 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] | 3215 | break; |
| 3216 | } |
| 3217 | } |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3218 | } else if (last_write.any() && IsWriteBarrierHazard(queue_id, src_exec_scope, src_access_scope)) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3219 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3220 | } |
| 3221 | |
| 3222 | return hazard; |
| 3223 | } |
| 3224 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3225 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, const ResourceAccessState &scope_state, |
| 3226 | VkPipelineStageFlags2KHR src_exec_scope, |
| 3227 | const SyncStageAccessFlags &src_access_scope, QueueId event_queue, |
| 3228 | ResourceUsageTag event_tag) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3229 | // Only supporting image layout transitions for now |
| 3230 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 3231 | HazardResult hazard; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3232 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3233 | if ((write_tag >= event_tag) && last_write.any()) { |
| 3234 | // Any write after the event precludes the possibility of being in the first access scope for the layout transition |
| 3235 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3236 | } else { |
| 3237 | // only test for WAW if there no intervening read operations. |
| 3238 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 3239 | if (last_reads.size()) { |
| 3240 | // Look at the reads if any... if reads exist, they are either the reason the access is in the event |
| 3241 | // first scope, or they are a hazard. |
| 3242 | const ReadStates &scope_reads = scope_state.last_reads; |
| 3243 | const ReadStates::size_type scope_read_count = scope_reads.size(); |
| 3244 | // Since the hasn't been a write: |
| 3245 | // * The current read state is a superset of the scoped one |
| 3246 | // * The stage order is the same. |
| 3247 | assert(last_reads.size() >= scope_read_count); |
| 3248 | for (ReadStates::size_type read_idx = 0; read_idx < scope_read_count; ++read_idx) { |
| 3249 | const ReadState &scope_read = scope_reads[read_idx]; |
| 3250 | const ReadState ¤t_read = last_reads[read_idx]; |
| 3251 | assert(scope_read.stage == current_read.stage); |
| 3252 | if (current_read.tag > event_tag) { |
| 3253 | // The read is more recent than the set event scope, thus no barrier from the wait/ILT. |
| 3254 | hazard.Set(this, usage_index, WRITE_AFTER_READ, current_read.access, current_read.tag); |
| 3255 | } else { |
| 3256 | // The read is in the events first synchronization scope, so we use a barrier hazard check |
| 3257 | // If the read stage is not in the src sync scope |
| 3258 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 3259 | // then the barrier access is unsafe (R/W after R) |
| 3260 | if (scope_read.IsReadBarrierHazard(event_queue, src_exec_scope)) { |
| 3261 | hazard.Set(this, usage_index, WRITE_AFTER_READ, scope_read.access, scope_read.tag); |
| 3262 | break; |
| 3263 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3264 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3265 | } |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3266 | if (!hazard.IsHazard() && (last_reads.size() > scope_read_count)) { |
| 3267 | const ReadState ¤t_read = last_reads[scope_read_count]; |
| 3268 | hazard.Set(this, usage_index, WRITE_AFTER_READ, current_read.access, current_read.tag); |
| 3269 | } |
| 3270 | } else if (last_write.any()) { |
| 3271 | // if there are no reads, the write is either the reason the access is in the event scope... they are a hazard |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3272 | // The write is in the first sync scope of the event (sync their aren't any reads to be the reason) |
| 3273 | // So do a normal barrier hazard check |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3274 | if (scope_state.IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 3275 | hazard.Set(&scope_state, usage_index, WRITE_AFTER_WRITE, scope_state.last_write, scope_state.write_tag); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3276 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3277 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3278 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3279 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3280 | return hazard; |
| 3281 | } |
| 3282 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3283 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 3284 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 3285 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 3286 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3287 | if (write_tag < other.write_tag) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3288 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 3289 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3290 | *this = other; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3291 | } else if (other.write_tag == write_tag) { |
| 3292 | // 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] | 3293 | // dependency chaining logic or any stage expansion) |
| 3294 | write_barriers |= other.write_barriers; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3295 | pending_write_barriers |= other.pending_write_barriers; |
| 3296 | pending_layout_transition |= other.pending_layout_transition; |
| 3297 | pending_write_dep_chain |= other.pending_write_dep_chain; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3298 | pending_layout_ordering_ |= other.pending_layout_ordering_; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3299 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3300 | // Merge the read states |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3301 | const auto pre_merge_count = last_reads.size(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3302 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3303 | 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] | 3304 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3305 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3306 | // 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] | 3307 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 3308 | // but we should wait on profiling data for that. |
| 3309 | 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] | 3310 | auto &my_read = last_reads[my_read_index]; |
| 3311 | if (other_read.stage == my_read.stage) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3312 | if (my_read.tag < other_read.tag) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3313 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3314 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3315 | my_read.tag = other_read.tag; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3316 | my_read.queue = other_read.queue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3317 | my_read.pending_dep_chain = other_read.pending_dep_chain; |
| 3318 | // TODO: Phase 2 -- review the state merge logic to avoid false positive from overwriting the barriers |
| 3319 | // May require tracking more than one access per stage. |
| 3320 | my_read.barriers = other_read.barriers; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3321 | my_read.sync_stages = other_read.sync_stages; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3322 | if (my_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3323 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 3324 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3325 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3326 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3327 | } else if (other_read.tag == my_read.tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3328 | // The read tags match so merge the barriers |
| 3329 | my_read.barriers |= other_read.barriers; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3330 | my_read.sync_stages |= other_read.sync_stages; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3331 | my_read.pending_dep_chain |= other_read.pending_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3332 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3333 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3334 | break; |
| 3335 | } |
| 3336 | } |
| 3337 | } else { |
| 3338 | // The other read stage doesn't exist in this, so add it. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3339 | last_reads.emplace_back(other_read); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3340 | last_read_stages |= other_read.stage; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3341 | if (other_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3342 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3343 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3344 | } |
| 3345 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3346 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3347 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 3348 | // ignore it. |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3349 | |
| 3350 | // Merge first access information by making a copy of this first_access and reconstructing with a shuffle |
| 3351 | // of the copy and other into this using the update first logic. |
| 3352 | // NOTE: All sorts of additional cleverness could be put into short circuts. (for example back is write and is before front |
| 3353 | // of the other first_accesses... ) |
| 3354 | if (!(first_accesses_ == other.first_accesses_) && !other.first_accesses_.empty()) { |
| 3355 | FirstAccesses firsts(std::move(first_accesses_)); |
| 3356 | first_accesses_.clear(); |
| 3357 | first_read_stages_ = 0U; |
| 3358 | auto a = firsts.begin(); |
| 3359 | auto a_end = firsts.end(); |
| 3360 | for (auto &b : other.first_accesses_) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3361 | // TODO: Determine whether some tag offset will be needed for PHASE II |
| 3362 | while ((a != a_end) && (a->tag < b.tag)) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3363 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3364 | ++a; |
| 3365 | } |
| 3366 | UpdateFirst(b.tag, b.usage_index, b.ordering_rule); |
| 3367 | } |
| 3368 | for (; a != a_end; ++a) { |
| 3369 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3370 | } |
| 3371 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3372 | } |
| 3373 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3374 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, SyncOrdering ordering_rule, const ResourceUsageTag tag) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3375 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 3376 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3377 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3378 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 3379 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 3380 | const auto usage_stage = PipelineStageBit(usage_index); |
| 3381 | if (usage_stage & last_read_stages) { |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3382 | const auto not_usage_stage = ~usage_stage; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3383 | for (auto &read_access : last_reads) { |
| 3384 | if (read_access.stage == usage_stage) { |
| 3385 | read_access.Set(usage_stage, usage_bit, 0, tag); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3386 | } else if (read_access.barriers & usage_stage) { |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3387 | // If the current access is barriered to this stage, mark it as "known to happen after" |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3388 | read_access.sync_stages |= usage_stage; |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3389 | } else { |
| 3390 | // If the current access is *NOT* barriered to this stage it needs to be cleared. |
| 3391 | // Note: this is possible because semaphores can *clear* effective barriers, so the assumption |
| 3392 | // that sync_stages is a subset of barriers may not apply. |
| 3393 | read_access.sync_stages &= not_usage_stage; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3394 | } |
| 3395 | } |
| 3396 | } else { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3397 | for (auto &read_access : last_reads) { |
| 3398 | if (read_access.barriers & usage_stage) { |
| 3399 | read_access.sync_stages |= usage_stage; |
| 3400 | } |
| 3401 | } |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3402 | last_reads.emplace_back(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3403 | last_read_stages |= usage_stage; |
| 3404 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3405 | |
| 3406 | // 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] | 3407 | if (usage_stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3408 | // TODO Revisit re: multiple reads for a given stage |
| 3409 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3410 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3411 | } else { |
| 3412 | // Assume write |
| 3413 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3414 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3415 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3416 | UpdateFirst(tag, usage_index, ordering_rule); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3417 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3418 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3419 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 3420 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 3421 | // We can overwrite them as *this* write is now after them. |
| 3422 | // |
| 3423 | // 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] | 3424 | void ResourceAccessState::SetWrite(const SyncStageAccessFlags &usage_bit, const ResourceUsageTag tag) { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3425 | ClearRead(); |
| 3426 | ClearWrite(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3427 | write_tag = tag; |
| 3428 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3429 | } |
| 3430 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3431 | void ResourceAccessState::ClearWrite() { |
| 3432 | read_execution_barriers = VK_PIPELINE_STAGE_2_NONE; |
| 3433 | input_attachment_read = false; // Denotes no outstanding input attachment read after the last write. |
| 3434 | write_barriers.reset(); |
| 3435 | write_dependency_chain = VK_PIPELINE_STAGE_2_NONE; |
| 3436 | last_write.reset(); |
| 3437 | |
| 3438 | write_tag = 0; |
| 3439 | write_queue = QueueSyncState::kQueueIdInvalid; |
| 3440 | } |
| 3441 | |
| 3442 | void ResourceAccessState::ClearRead() { |
| 3443 | last_reads.clear(); |
| 3444 | last_read_stages = VK_PIPELINE_STAGE_2_NONE; |
| 3445 | } |
| 3446 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3447 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 3448 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 3449 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 3450 | // replace the current write barriers or add to them, so accumulate to pending as well. |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3451 | template <typename ScopeOps> |
| 3452 | void ResourceAccessState::ApplyBarrier(ScopeOps &&scope, const SyncBarrier &barrier, bool layout_transition) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3453 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 3454 | // applying the memory barriers |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 3455 | // NOTE: We update the write barrier if the write is in the first access scope or if there is a layout |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3456 | // transistion, under the theory of "most recent access". If the resource acces *isn't* safe |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 3457 | // vs. this layout transition DetectBarrierHazard should report it. We treat the layout |
| 3458 | // transistion *as* a write and in scope with the barrier (it's before visibility). |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3459 | if (layout_transition || scope.WriteInScope(barrier, *this)) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3460 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3461 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3462 | if (layout_transition) { |
| 3463 | pending_layout_ordering_ |= OrderingBarrier(barrier.src_exec_scope.exec_scope, barrier.src_access_scope); |
| 3464 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3465 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3466 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 3467 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3468 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3469 | if (!pending_layout_transition) { |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3470 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/chains |
| 3471 | // don't need to be tracked as we're just going to clear them. |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3472 | VkPipelineStageFlags2 stages_in_scope = VK_PIPELINE_STAGE_2_NONE; |
| 3473 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3474 | for (auto &read_access : last_reads) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3475 | // The | implements the "dependency chain" logic for this access, as the barriers field stores the second sync scope |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3476 | if (scope.ReadInScope(barrier, read_access)) { |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3477 | // We'll apply the barrier in the next loop, because it's DRY'r to do it one place. |
| 3478 | stages_in_scope |= read_access.stage; |
| 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | for (auto &read_access : last_reads) { |
| 3483 | if (0 != ((read_access.stage | read_access.sync_stages) & stages_in_scope)) { |
| 3484 | // If this stage, or any stage known to be synchronized after it are in scope, apply the barrier to this read |
| 3485 | // NOTE: Forwarding barriers to known prior stages changes the sync_stages from shallow to deep, because the |
| 3486 | // barriers used to determine sync_stages have been propagated to all known earlier stages |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3487 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3488 | } |
| 3489 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3490 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3491 | } |
| 3492 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3493 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag tag) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3494 | if (pending_layout_transition) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3495 | // 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] | 3496 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3497 | UpdateFirst(tag, SYNC_IMAGE_LAYOUT_TRANSITION, SyncOrdering::kNonAttachment); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3498 | TouchupFirstForLayoutTransition(tag, pending_layout_ordering_); |
| 3499 | pending_layout_ordering_ = OrderingBarrier(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3500 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3501 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3502 | |
| 3503 | // Apply the accumulate execution barriers (and thus update chaining information) |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3504 | // 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] | 3505 | for (auto &read_access : last_reads) { |
| 3506 | read_access.barriers |= read_access.pending_dep_chain; |
| 3507 | read_execution_barriers |= read_access.barriers; |
| 3508 | read_access.pending_dep_chain = 0; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 3512 | write_dependency_chain |= pending_write_dep_chain; |
| 3513 | write_barriers |= pending_write_barriers; |
| 3514 | pending_write_dep_chain = 0; |
| 3515 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3516 | } |
| 3517 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3518 | // Assumes signal queue != wait queue |
| 3519 | void ResourceAccessState::ApplySemaphore(const SemaphoreScope &signal, const SemaphoreScope wait) { |
| 3520 | // Semaphores only guarantee the first scope of the signal is before the second scope of the wait. |
| 3521 | // If any access isn't in the first scope, there are no guarantees, thus those barriers are cleared |
| 3522 | assert(signal.queue != wait.queue); |
| 3523 | for (auto &read_access : last_reads) { |
| 3524 | if (read_access.ReadInQueueScopeOrChain(signal.queue, signal.exec_scope)) { |
| 3525 | // Deflects WAR on wait queue |
| 3526 | read_access.barriers = wait.exec_scope; |
| 3527 | } else { |
| 3528 | // Leave sync stages alone. Update method will clear unsynchronized stages on subsequent reads as needed. |
| 3529 | read_access.barriers = VK_PIPELINE_STAGE_2_NONE; |
| 3530 | } |
| 3531 | } |
| 3532 | if (WriteInQueueSourceScopeOrChain(signal.queue, signal.exec_scope, signal.valid_accesses)) { |
| 3533 | // Will deflect RAW wait queue, WAW needs a chained barrier on wait queue |
| 3534 | read_execution_barriers = wait.exec_scope; |
| 3535 | write_barriers = wait.valid_accesses; |
| 3536 | } else { |
| 3537 | read_execution_barriers = VK_PIPELINE_STAGE_2_NONE; |
| 3538 | write_barriers.reset(); |
| 3539 | } |
| 3540 | write_dependency_chain = read_execution_barriers; |
| 3541 | } |
| 3542 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3543 | bool ResourceAccessState::QueueTagPredicate::operator()(QueueId usage_queue, ResourceUsageTag usage_tag) { |
| 3544 | return (queue == usage_queue) && (tag <= usage_tag); |
| 3545 | } |
| 3546 | |
| 3547 | bool ResourceAccessState::QueuePredicate::operator()(QueueId usage_queue, ResourceUsageTag) { return queue == usage_queue; } |
| 3548 | |
| 3549 | bool ResourceAccessState::TagPredicate::operator()(QueueId, ResourceUsageTag usage_tag) { return tag <= usage_tag; } |
| 3550 | |
| 3551 | // Return if the resulting state is "empty" |
| 3552 | template <typename Pred> |
| 3553 | bool ResourceAccessState::ApplyQueueTagWait(Pred &&queue_tag_test) { |
| 3554 | VkPipelineStageFlags2KHR sync_reads = VK_PIPELINE_STAGE_2_NONE; |
| 3555 | |
| 3556 | // Use the predicate to build a mask of the read stages we are synchronizing |
| 3557 | // Use the sync_stages to also detect reads known to be before any synchronized reads (first pass) |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3558 | for (auto &read_access : last_reads) { |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3559 | if (queue_tag_test(read_access.queue, read_access.tag)) { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3560 | // If we know this stage is before any stage we syncing, or if the predicate tells us that we are waited for.. |
| 3561 | sync_reads |= read_access.stage; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3562 | } |
| 3563 | } |
| 3564 | |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3565 | // Now that we know the reads directly in scopejust need to go over the list again to pick up the "known earlier" stages. |
| 3566 | // NOTE: sync_stages is "deep" catching all stages synchronized after it because we forward barriers |
| 3567 | uint32_t unsync_count = 0; |
| 3568 | for (auto &read_access : last_reads) { |
| 3569 | if (0 != ((read_access.stage | read_access.sync_stages) & sync_reads)) { |
| 3570 | // This is redundant in the "stage" case, but avoids a second branch to get an accurate count |
| 3571 | sync_reads |= read_access.stage; |
| 3572 | } else { |
| 3573 | ++unsync_count; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | if (unsync_count) { |
| 3578 | if (sync_reads) { |
| 3579 | // When have some remaining unsynchronized reads, we have to rewrite the last_reads array. |
| 3580 | ReadStates unsync_reads; |
| 3581 | unsync_reads.reserve(unsync_count); |
| 3582 | VkPipelineStageFlags2KHR unsync_read_stages = VK_PIPELINE_STAGE_2_NONE; |
| 3583 | for (auto &read_access : last_reads) { |
| 3584 | if (0 == (read_access.stage & sync_reads)) { |
| 3585 | unsync_reads.emplace_back(read_access); |
| 3586 | unsync_read_stages |= read_access.stage; |
| 3587 | } |
| 3588 | } |
| 3589 | last_read_stages = unsync_read_stages; |
| 3590 | last_reads = std::move(unsync_reads); |
| 3591 | } |
| 3592 | } else { |
| 3593 | // Nothing remains (or it was empty to begin with) |
| 3594 | ClearRead(); |
| 3595 | } |
| 3596 | |
| 3597 | bool all_clear = last_reads.size() == 0; |
| 3598 | if (last_write.any()) { |
| 3599 | if (queue_tag_test(write_queue, write_tag) || sync_reads) { |
| 3600 | // Clear any predicated write, or any the write from any any access with synchronized reads. |
| 3601 | // This could drop RAW detection, but only if the synchronized reads were RAW hazards, and given |
| 3602 | // MRR approach to reporting, this is consistent with other drops, especially since fixing the |
| 3603 | // RAW wit the sync_reads stages would preclude a subsequent RAW. |
| 3604 | ClearWrite(); |
| 3605 | } else { |
| 3606 | all_clear = false; |
| 3607 | } |
| 3608 | } |
| 3609 | return all_clear; |
| 3610 | } |
| 3611 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3612 | bool ResourceAccessState::FirstAccessInTagRange(const ResourceUsageRange &tag_range) const { |
| 3613 | if (!first_accesses_.size()) return false; |
| 3614 | const ResourceUsageRange first_access_range = {first_accesses_.front().tag, first_accesses_.back().tag + 1}; |
| 3615 | return tag_range.intersects(first_access_range); |
| 3616 | } |
| 3617 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3618 | void ResourceAccessState::OffsetTag(ResourceUsageTag offset) { |
| 3619 | if (last_write.any()) write_tag += offset; |
| 3620 | for (auto &read_access : last_reads) { |
| 3621 | read_access.tag += offset; |
| 3622 | } |
| 3623 | for (auto &first : first_accesses_) { |
| 3624 | first.tag += offset; |
| 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | ResourceAccessState::ResourceAccessState() |
| 3629 | : write_barriers(~SyncStageAccessFlags(0)), |
| 3630 | write_dependency_chain(0), |
| 3631 | write_tag(), |
| 3632 | write_queue(QueueSyncState::kQueueIdInvalid), |
| 3633 | last_write(0), |
| 3634 | input_attachment_read(false), |
| 3635 | last_read_stages(0), |
| 3636 | read_execution_barriers(0), |
| 3637 | pending_write_dep_chain(0), |
| 3638 | pending_layout_transition(false), |
| 3639 | pending_write_barriers(0), |
| 3640 | pending_layout_ordering_(), |
| 3641 | first_accesses_(), |
| 3642 | first_read_stages_(0U), |
| 3643 | first_write_layout_ordering_() {} |
| 3644 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3645 | // 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] | 3646 | VkPipelineStageFlags2KHR ResourceAccessState::GetReadBarriers(const SyncStageAccessFlags &usage_bit) const { |
| 3647 | VkPipelineStageFlags2KHR barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3648 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3649 | for (const auto &read_access : last_reads) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3650 | if ((read_access.access & usage_bit).any()) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3651 | barriers = read_access.barriers; |
| 3652 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3653 | } |
| 3654 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3655 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3656 | return barriers; |
| 3657 | } |
| 3658 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3659 | void ResourceAccessState::SetQueueId(QueueId id) { |
| 3660 | for (auto &read_access : last_reads) { |
| 3661 | if (read_access.queue == QueueSyncState::kQueueIdInvalid) { |
| 3662 | read_access.queue = id; |
| 3663 | } |
| 3664 | } |
| 3665 | if (last_write.any() && (write_queue == QueueSyncState::kQueueIdInvalid)) { |
| 3666 | write_queue = id; |
| 3667 | } |
| 3668 | } |
| 3669 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 3670 | bool ResourceAccessState::WriteInChain(VkPipelineStageFlags2KHR src_exec_scope) const { |
| 3671 | return 0 != (write_dependency_chain & src_exec_scope); |
| 3672 | } |
| 3673 | |
| 3674 | bool ResourceAccessState::WriteInScope(const SyncStageAccessFlags &src_access_scope) const { |
| 3675 | return (src_access_scope & last_write).any(); |
| 3676 | } |
| 3677 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3678 | bool ResourceAccessState::WriteBarrierInScope(const SyncStageAccessFlags &src_access_scope) const { |
| 3679 | return (write_barriers & src_access_scope).any(); |
| 3680 | } |
| 3681 | |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3682 | bool ResourceAccessState::WriteInSourceScopeOrChain(VkPipelineStageFlags2KHR src_exec_scope, |
| 3683 | SyncStageAccessFlags src_access_scope) const { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 3684 | return WriteInChain(src_exec_scope) || WriteInScope(src_access_scope); |
| 3685 | } |
| 3686 | |
| 3687 | bool ResourceAccessState::WriteInQueueSourceScopeOrChain(QueueId queue, VkPipelineStageFlags2KHR src_exec_scope, |
| 3688 | SyncStageAccessFlags src_access_scope) const { |
| 3689 | return WriteInChain(src_exec_scope) || ((queue == write_queue) && WriteInScope(src_access_scope)); |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3690 | } |
| 3691 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3692 | bool ResourceAccessState::WriteInEventScope(VkPipelineStageFlags2KHR src_exec_scope, const SyncStageAccessFlags &src_access_scope, |
| 3693 | QueueId scope_queue, ResourceUsageTag scope_tag) const { |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3694 | // The scope logic for events is, if we're asking, the resource usage was flagged as "in the first execution scope" at |
| 3695 | // the time of the SetEvent, thus all we need check is whether the access is the same one (i.e. before the scope tag |
| 3696 | // in order to know if it's in the excecution scope |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3697 | return (write_tag < scope_tag) && WriteInQueueSourceScopeOrChain(scope_queue, src_exec_scope, src_access_scope); |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3698 | } |
| 3699 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3700 | bool ResourceAccessState::WriteInChainedScope(VkPipelineStageFlags2KHR src_exec_scope, |
| 3701 | const SyncStageAccessFlags &src_access_scope) const { |
| 3702 | return WriteInChain(src_exec_scope) && WriteBarrierInScope(src_access_scope); |
| 3703 | } |
| 3704 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3705 | bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlags2KHR usage_stage, const SyncStageAccessFlags &usage) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3706 | assert(IsRead(usage)); |
| 3707 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 3708 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 3709 | // any reads that happen after. |
| 3710 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 3711 | // 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] | 3712 | return last_write.any() && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3713 | } |
| 3714 | |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3715 | VkPipelineStageFlags2 ResourceAccessState::GetOrderedStages(QueueId queue_id, const OrderingBarrier &ordering) const { |
| 3716 | // At apply queue submission order limits on the effect of ordering |
| 3717 | VkPipelineStageFlags2 non_qso_stages = VK_PIPELINE_STAGE_2_NONE; |
| 3718 | if (queue_id != QueueSyncState::kQueueIdInvalid) { |
| 3719 | for (const auto &read_access : last_reads) { |
| 3720 | if (read_access.queue != queue_id) { |
| 3721 | non_qso_stages |= read_access.stage; |
| 3722 | } |
| 3723 | } |
| 3724 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3725 | // Whether the stage are in the ordering scope only matters if the current write is ordered |
John Zulauf | ec943ec | 2022-06-29 07:52:56 -0600 | [diff] [blame] | 3726 | const VkPipelineStageFlags2 read_stages_in_qso = last_read_stages & ~non_qso_stages; |
| 3727 | VkPipelineStageFlags2 ordered_stages = read_stages_in_qso & ordering.exec_scope; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3728 | // Special input attachment handling as always (not encoded in exec_scop) |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3729 | 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] | 3730 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3731 | // 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] | 3732 | ordered_stages |= VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | return ordered_stages; |
| 3736 | } |
| 3737 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3738 | void ResourceAccessState::UpdateFirst(const ResourceUsageTag tag, SyncStageAccessIndex usage_index, SyncOrdering ordering_rule) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3739 | // Only record until we record a write. |
| 3740 | if (first_accesses_.empty() || IsRead(first_accesses_.back().usage_index)) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3741 | const VkPipelineStageFlags2KHR usage_stage = IsRead(usage_index) ? PipelineStageBit(usage_index) : 0U; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3742 | if (0 == (usage_stage & first_read_stages_)) { |
| 3743 | // 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] | 3744 | // We always need to know what stages were found prior to write |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3745 | first_read_stages_ |= usage_stage; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3746 | if (0 == (read_execution_barriers & usage_stage)) { |
| 3747 | // If this stage isn't masked then we add it (since writes map to usage_stage 0, this also records writes) |
| 3748 | first_accesses_.emplace_back(tag, usage_index, ordering_rule); |
| 3749 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3750 | } |
| 3751 | } |
| 3752 | } |
| 3753 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3754 | void ResourceAccessState::TouchupFirstForLayoutTransition(ResourceUsageTag tag, const OrderingBarrier &layout_ordering) { |
| 3755 | // Only call this after recording an image layout transition |
| 3756 | assert(first_accesses_.size()); |
| 3757 | if (first_accesses_.back().tag == tag) { |
| 3758 | // 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] | 3759 | assert(first_accesses_.back().usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3760 | first_write_layout_ordering_ = layout_ordering; |
| 3761 | } |
| 3762 | } |
| 3763 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3764 | ResourceAccessState::ReadState::ReadState(VkPipelineStageFlags2KHR stage_, SyncStageAccessFlags access_, |
| 3765 | VkPipelineStageFlags2KHR barriers_, ResourceUsageTag tag_) |
| 3766 | : stage(stage_), |
| 3767 | access(access_), |
| 3768 | barriers(barriers_), |
| 3769 | sync_stages(VK_PIPELINE_STAGE_2_NONE), |
| 3770 | tag(tag_), |
| 3771 | queue(QueueSyncState::kQueueIdInvalid), |
| 3772 | pending_dep_chain(VK_PIPELINE_STAGE_2_NONE) {} |
| 3773 | |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 3774 | void ResourceAccessState::ReadState::Set(VkPipelineStageFlags2KHR stage_, const SyncStageAccessFlags &access_, |
| 3775 | VkPipelineStageFlags2KHR barriers_, ResourceUsageTag tag_) { |
| 3776 | stage = stage_; |
| 3777 | access = access_; |
| 3778 | barriers = barriers_; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3779 | sync_stages = VK_PIPELINE_STAGE_2_NONE; |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 3780 | tag = tag_; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3781 | pending_dep_chain = VK_PIPELINE_STAGE_2_NONE; // If this is a new read, we aren't applying a barrier set. |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 3782 | } |
| 3783 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 3784 | // Scope test including "queue submission order" effects. Specifically, accesses from a different queue are not |
| 3785 | // considered to be in "queue submission order" with barriers, events, or semaphore signalling, but any barriers |
| 3786 | // that have bee applied (via semaphore) to those accesses can be chained off of. |
| 3787 | bool ResourceAccessState::ReadState::ReadInQueueScopeOrChain(QueueId scope_queue, VkPipelineStageFlags2 exec_scope) const { |
| 3788 | VkPipelineStageFlags2 effective_stages = barriers | ((scope_queue == queue) ? stage : VK_PIPELINE_STAGE_2_NONE); |
| 3789 | return (exec_scope & effective_stages) != 0; |
| 3790 | } |
| 3791 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3792 | ResourceUsageRange SyncValidator::ReserveGlobalTagRange(size_t tag_count) const { |
| 3793 | ResourceUsageRange reserve; |
| 3794 | reserve.begin = tag_limit_.fetch_add(tag_count); |
| 3795 | reserve.end = reserve.begin + tag_count; |
| 3796 | return reserve; |
| 3797 | } |
| 3798 | |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 3799 | const QueueSyncState *SyncValidator::GetQueueSyncState(VkQueue queue) const { |
| 3800 | return GetMappedPlainFromShared(queue_sync_states_, queue); |
| 3801 | } |
| 3802 | |
| 3803 | QueueSyncState *SyncValidator::GetQueueSyncState(VkQueue queue) { return GetMappedPlainFromShared(queue_sync_states_, queue); } |
| 3804 | |
| 3805 | std::shared_ptr<const QueueSyncState> SyncValidator::GetQueueSyncStateShared(VkQueue queue) const { |
| 3806 | return GetMapped(queue_sync_states_, queue, []() { return std::shared_ptr<QueueSyncState>(); }); |
| 3807 | } |
| 3808 | |
| 3809 | std::shared_ptr<QueueSyncState> SyncValidator::GetQueueSyncStateShared(VkQueue queue) { |
| 3810 | return GetMapped(queue_sync_states_, queue, []() { return std::shared_ptr<QueueSyncState>(); }); |
| 3811 | } |
| 3812 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3813 | template <typename T> |
| 3814 | struct GetBatchTraits {}; |
| 3815 | template <> |
| 3816 | struct GetBatchTraits<std::shared_ptr<QueueSyncState>> { |
| 3817 | using Batch = std::shared_ptr<QueueBatchContext>; |
| 3818 | static Batch Get(const std::shared_ptr<QueueSyncState> &qss) { return qss ? qss->LastBatch() : Batch(); } |
| 3819 | }; |
| 3820 | |
| 3821 | template <> |
| 3822 | struct GetBatchTraits<std::shared_ptr<SignaledSemaphores::Signal>> { |
| 3823 | using Batch = std::shared_ptr<QueueBatchContext>; |
| 3824 | static Batch Get(const std::shared_ptr<SignaledSemaphores::Signal> &sig) { return sig ? sig->batch : Batch(); } |
| 3825 | }; |
| 3826 | |
| 3827 | template <typename BatchSet, typename Map, typename Predicate> |
| 3828 | static BatchSet GetQueueBatchSnapshotImpl(const Map &map, Predicate &&pred) { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3829 | BatchSet snapshot; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3830 | for (auto &entry : map) { |
| 3831 | // Intentional copy |
| 3832 | auto batch = GetBatchTraits<typename Map::mapped_type>::Get(entry.second); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3833 | if (batch && pred(batch)) snapshot.emplace(std::move(batch)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3834 | } |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3835 | return snapshot; |
| 3836 | } |
| 3837 | |
| 3838 | template <typename Predicate> |
| 3839 | QueueBatchContext::ConstBatchSet SyncValidator::GetQueueLastBatchSnapshot(Predicate &&pred) const { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3840 | return GetQueueBatchSnapshotImpl<QueueBatchContext::ConstBatchSet>(queue_sync_states_, std::forward<Predicate>(pred)); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | template <typename Predicate> |
| 3844 | QueueBatchContext::BatchSet SyncValidator::GetQueueLastBatchSnapshot(Predicate &&pred) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 3845 | return GetQueueBatchSnapshotImpl<QueueBatchContext::BatchSet>(queue_sync_states_, std::forward<Predicate>(pred)); |
| 3846 | } |
| 3847 | |
| 3848 | QueueBatchContext::BatchSet SyncValidator::GetQueueBatchSnapshot() { |
| 3849 | QueueBatchContext::BatchSet snapshot = GetQueueLastBatchSnapshot(); |
| 3850 | auto append = [&snapshot](const std::shared_ptr<QueueBatchContext> batch) { |
| 3851 | if (batch && !layer_data::Contains(snapshot, batch)) { |
| 3852 | snapshot.emplace(batch); |
| 3853 | } |
| 3854 | return false; |
| 3855 | }; |
| 3856 | GetQueueBatchSnapshotImpl<QueueBatchContext::BatchSet>(signaled_semaphores_, append); |
| 3857 | return snapshot; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3858 | } |
| 3859 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3860 | bool SignaledSemaphores::SignalSemaphore(const std::shared_ptr<const SEMAPHORE_STATE> &sem_state, |
| 3861 | const std::shared_ptr<QueueBatchContext> &batch, |
| 3862 | const VkSemaphoreSubmitInfo &signal_info) { |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3863 | assert(batch); |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3864 | const SyncExecScope exec_scope = |
| 3865 | SyncExecScope::MakeSrc(batch->GetQueueFlags(), signal_info.stageMask, VK_PIPELINE_STAGE_2_HOST_BIT); |
| 3866 | const VkSemaphore sem = sem_state->semaphore(); |
| 3867 | auto signal_it = signaled_.find(sem); |
| 3868 | std::shared_ptr<Signal> insert_signal; |
| 3869 | if (signal_it == signaled_.end()) { |
| 3870 | if (prev_) { |
| 3871 | auto prev_sig = GetMapped(prev_->signaled_, sem_state->semaphore(), []() { return std::shared_ptr<Signal>(); }); |
| 3872 | if (prev_sig) { |
| 3873 | // The is an invalid signal, as this semaphore is already signaled... copy the prev state (as prev_ is const) |
| 3874 | insert_signal = std::make_shared<Signal>(*prev_sig); |
| 3875 | } |
| 3876 | } |
| 3877 | auto insert_pair = signaled_.emplace(sem, std::move(insert_signal)); |
| 3878 | signal_it = insert_pair.first; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3879 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3880 | |
| 3881 | bool success = false; |
| 3882 | if (!signal_it->second) { |
| 3883 | signal_it->second = std::make_shared<Signal>(sem_state, batch, exec_scope); |
| 3884 | success = true; |
| 3885 | } |
| 3886 | |
| 3887 | return success; |
| 3888 | } |
| 3889 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3890 | std::shared_ptr<const SignaledSemaphores::Signal> SignaledSemaphores::Unsignal(VkSemaphore sem) { |
| 3891 | std::shared_ptr<const Signal> unsignaled; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3892 | const auto found_it = signaled_.find(sem); |
| 3893 | if (found_it != signaled_.end()) { |
| 3894 | // Move the unsignaled singal out from the signaled list, but keep the shared_ptr as the caller needs the contents for |
| 3895 | // a bit. |
| 3896 | unsignaled = std::move(found_it->second); |
| 3897 | if (!prev_) { |
| 3898 | // No parent, not need to keep the entry |
| 3899 | // IFF (prev_) leave the entry in the leaf table as we use it to export unsignal to prev_ during record phase |
| 3900 | signaled_.erase(found_it); |
| 3901 | } |
| 3902 | } else if (prev_) { |
| 3903 | // We can't unsignal prev_ because it's const * by design. |
| 3904 | // We put in an empty placeholder |
| 3905 | signaled_.emplace(sem, std::shared_ptr<Signal>()); |
| 3906 | unsignaled = GetPrev(sem); |
| 3907 | } |
| 3908 | // NOTE: No else clause. Because if we didn't find it, and there's no previous, this indicates an error, |
| 3909 | // but CoreChecks should have reported it |
| 3910 | |
| 3911 | // If unsignaled is null, there was a missing pending semaphore, and that's also issue CoreChecks reports |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3912 | return unsignaled; |
| 3913 | } |
| 3914 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3915 | void SignaledSemaphores::Import(VkSemaphore sem, std::shared_ptr<Signal> &&from) { |
| 3916 | // Overwrite the s tate with the last state from this |
| 3917 | if (from) { |
| 3918 | assert(sem == from->sem_state->semaphore()); |
| 3919 | signaled_[sem] = std::move(from); |
| 3920 | } else { |
| 3921 | signaled_.erase(sem); |
| 3922 | } |
| 3923 | } |
| 3924 | |
| 3925 | void SignaledSemaphores::Reset() { |
| 3926 | signaled_.clear(); |
| 3927 | prev_ = nullptr; |
| 3928 | } |
| 3929 | |
John Zulauf | ea943c5 | 2022-02-22 11:05:17 -0700 | [diff] [blame] | 3930 | std::shared_ptr<CommandBufferAccessContext> SyncValidator::AccessContextFactory(VkCommandBuffer command_buffer) { |
| 3931 | // If we don't have one, make it. |
| 3932 | auto cb_state = Get<CMD_BUFFER_STATE>(command_buffer); |
| 3933 | assert(cb_state.get()); |
| 3934 | auto queue_flags = cb_state->GetQueueFlags(); |
| 3935 | return std::make_shared<CommandBufferAccessContext>(*this, cb_state, queue_flags); |
| 3936 | } |
| 3937 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3938 | std::shared_ptr<CommandBufferAccessContext> SyncValidator::GetAccessContextShared(VkCommandBuffer command_buffer) { |
John Zulauf | ea943c5 | 2022-02-22 11:05:17 -0700 | [diff] [blame] | 3939 | return GetMappedInsert(cb_access_state, command_buffer, |
| 3940 | [this, command_buffer]() { return AccessContextFactory(command_buffer); }); |
| 3941 | } |
| 3942 | |
| 3943 | std::shared_ptr<const CommandBufferAccessContext> SyncValidator::GetAccessContextShared(VkCommandBuffer command_buffer) const { |
| 3944 | return GetMapped(cb_access_state, command_buffer, []() { return std::shared_ptr<CommandBufferAccessContext>(); }); |
| 3945 | } |
| 3946 | |
| 3947 | const CommandBufferAccessContext *SyncValidator::GetAccessContext(VkCommandBuffer command_buffer) const { |
| 3948 | return GetMappedPlainFromShared(cb_access_state, command_buffer); |
| 3949 | } |
| 3950 | |
| 3951 | CommandBufferAccessContext *SyncValidator::GetAccessContext(VkCommandBuffer command_buffer) { |
| 3952 | return GetAccessContextShared(command_buffer).get(); |
| 3953 | } |
| 3954 | |
| 3955 | CommandBufferAccessContext *SyncValidator::GetAccessContextNoInsert(VkCommandBuffer command_buffer) { |
| 3956 | return GetMappedPlainFromShared(cb_access_state, command_buffer); |
| 3957 | } |
| 3958 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3959 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3960 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 3961 | if (access_context) { |
| 3962 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3963 | } |
| 3964 | } |
| 3965 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3966 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 3967 | auto access_found = cb_access_state.find(command_buffer); |
| 3968 | if (access_found != cb_access_state.end()) { |
| 3969 | access_found->second->Reset(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3970 | access_found->second->MarkDestroyed(); |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3971 | cb_access_state.erase(access_found); |
| 3972 | } |
| 3973 | } |
| 3974 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3975 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3976 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 3977 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3978 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3979 | assert(cb_context); |
| 3980 | if (!cb_context) return skip; |
| 3981 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3982 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3983 | // If we have no previous accesses, we have no hazards |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3984 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 3985 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3986 | |
| 3987 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3988 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3989 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3990 | 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] | 3991 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3992 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3993 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3994 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3995 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3996 | cb_context->FormatHazard(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3997 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3998 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3999 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4000 | 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] | 4001 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4002 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4003 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4004 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4005 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4006 | cb_context->FormatHazard(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4007 | } |
| 4008 | } |
| 4009 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4010 | } |
| 4011 | return skip; |
| 4012 | } |
| 4013 | |
| 4014 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 4015 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4016 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4017 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 4018 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4019 | auto *context = cb_context->GetCurrentAccessContext(); |
| 4020 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4021 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 4022 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4023 | |
| 4024 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4025 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 4026 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4027 | 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] | 4028 | 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] | 4029 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 4030 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4031 | 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] | 4032 | 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] | 4033 | } |
| 4034 | } |
| 4035 | } |
| 4036 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4037 | void SyncValidator::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 4038 | // Clear out events from the command buffer contexts |
| 4039 | for (auto &cb_context : cb_access_state) { |
| 4040 | cb_context.second->RecordDestroyEvent(event); |
| 4041 | } |
| 4042 | } |
| 4043 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 4044 | bool SyncValidator::ValidateCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos, |
| 4045 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4046 | bool skip = false; |
| 4047 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4048 | assert(cb_context); |
| 4049 | if (!cb_context) return skip; |
| 4050 | const auto *context = cb_context->GetCurrentAccessContext(); |
| 4051 | |
| 4052 | // If we have no previous accesses, we have no hazards |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4053 | auto src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 4054 | auto dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4055 | |
| 4056 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 4057 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 4058 | if (src_buffer) { |
| 4059 | 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] | 4060 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4061 | if (hazard.hazard) { |
| 4062 | // TODO -- add tag information to log msg when useful. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4063 | skip |= |
| 4064 | LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4065 | "%s(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 4066 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
| 4067 | region, cb_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4068 | } |
| 4069 | } |
| 4070 | if (dst_buffer && !skip) { |
| 4071 | 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] | 4072 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4073 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4074 | skip |= |
| 4075 | LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4076 | "%s(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 4077 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
| 4078 | region, cb_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4079 | } |
| 4080 | } |
| 4081 | if (skip) break; |
| 4082 | } |
| 4083 | return skip; |
| 4084 | } |
| 4085 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 4086 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4087 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 4088 | return ValidateCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2KHR); |
| 4089 | } |
| 4090 | |
| 4091 | bool SyncValidator::PreCallValidateCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos) const { |
| 4092 | return ValidateCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2); |
| 4093 | } |
| 4094 | |
| 4095 | void SyncValidator::RecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos, CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4096 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4097 | assert(cb_context); |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 4098 | const auto tag = cb_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4099 | auto *context = cb_context->GetCurrentAccessContext(); |
| 4100 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4101 | auto src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 4102 | auto dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4103 | |
| 4104 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 4105 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 4106 | if (src_buffer) { |
| 4107 | 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] | 4108 | 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] | 4109 | } |
| 4110 | if (dst_buffer) { |
| 4111 | 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] | 4112 | 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] | 4113 | } |
| 4114 | } |
| 4115 | } |
| 4116 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 4117 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 4118 | RecordCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2KHR); |
| 4119 | } |
| 4120 | |
| 4121 | void SyncValidator::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos) { |
| 4122 | RecordCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2); |
| 4123 | } |
| 4124 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4125 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4126 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4127 | const VkImageCopy *pRegions) const { |
| 4128 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4129 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4130 | assert(cb_access_context); |
| 4131 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4132 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4133 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4134 | assert(context); |
| 4135 | if (!context) return skip; |
| 4136 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4137 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4138 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4139 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4140 | const auto ©_region = pRegions[region]; |
| 4141 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4142 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.srcSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4143 | copy_region.srcOffset, copy_region.extent, false); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4144 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4145 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4146 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4147 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4148 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4149 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4150 | } |
| 4151 | |
| 4152 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4153 | auto hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.dstSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4154 | copy_region.dstOffset, copy_region.extent, false); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4155 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4156 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4157 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4158 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4159 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4160 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 4161 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4162 | } |
| 4163 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4164 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4165 | return skip; |
| 4166 | } |
| 4167 | |
| 4168 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4169 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4170 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4171 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4172 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 4173 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4174 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4175 | assert(context); |
| 4176 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4177 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4178 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4179 | |
| 4180 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4181 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4182 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4183 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4184 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4185 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4186 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4187 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
ziga-lunarg | 7374651 | 2022-03-23 23:08:17 +0100 | [diff] [blame] | 4188 | copy_region.dstSubresource, copy_region.dstOffset, copy_region.extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4189 | } |
| 4190 | } |
| 4191 | } |
| 4192 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4193 | bool SyncValidator::ValidateCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo, |
| 4194 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4195 | bool skip = false; |
| 4196 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4197 | assert(cb_access_context); |
| 4198 | if (!cb_access_context) return skip; |
| 4199 | |
| 4200 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4201 | assert(context); |
| 4202 | if (!context) return skip; |
| 4203 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4204 | auto src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 4205 | auto dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4206 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4207 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 4208 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 4209 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4210 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.srcSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4211 | copy_region.srcOffset, copy_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4212 | if (hazard.hazard) { |
| 4213 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4214 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4215 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4216 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4217 | } |
| 4218 | } |
| 4219 | |
| 4220 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4221 | auto hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.dstSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4222 | copy_region.dstOffset, copy_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4223 | if (hazard.hazard) { |
| 4224 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4225 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4226 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4227 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4228 | } |
| 4229 | if (skip) break; |
| 4230 | } |
| 4231 | } |
| 4232 | |
| 4233 | return skip; |
| 4234 | } |
| 4235 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4236 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 4237 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 4238 | return ValidateCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2KHR); |
| 4239 | } |
| 4240 | |
| 4241 | bool SyncValidator::PreCallValidateCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) const { |
| 4242 | return ValidateCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2); |
| 4243 | } |
| 4244 | |
| 4245 | void SyncValidator::RecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo, CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4246 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4247 | assert(cb_access_context); |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4248 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4249 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4250 | assert(context); |
| 4251 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4252 | auto src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 4253 | auto dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4254 | |
| 4255 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 4256 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 4257 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4258 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4259 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4260 | } |
| 4261 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4262 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
ziga-lunarg | 7374651 | 2022-03-23 23:08:17 +0100 | [diff] [blame] | 4263 | copy_region.dstSubresource, copy_region.dstOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4264 | } |
| 4265 | } |
| 4266 | } |
| 4267 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4268 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 4269 | RecordCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2KHR); |
| 4270 | } |
| 4271 | |
| 4272 | void SyncValidator::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) { |
| 4273 | RecordCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2); |
| 4274 | } |
| 4275 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4276 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 4277 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 4278 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4279 | uint32_t bufferMemoryBarrierCount, |
| 4280 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4281 | uint32_t imageMemoryBarrierCount, |
| 4282 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 4283 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4284 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4285 | assert(cb_access_context); |
| 4286 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 4287 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4288 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 4289 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 4290 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 4291 | pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 4292 | skip = pipeline_barrier.Validate(*cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4293 | return skip; |
| 4294 | } |
| 4295 | |
| 4296 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 4297 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 4298 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4299 | uint32_t bufferMemoryBarrierCount, |
| 4300 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4301 | uint32_t imageMemoryBarrierCount, |
| 4302 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4303 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4304 | assert(cb_access_context); |
| 4305 | if (!cb_access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4306 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 4307 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), |
| 4308 | srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, |
| 4309 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 4310 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4311 | } |
| 4312 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4313 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 4314 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 4315 | bool skip = false; |
| 4316 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4317 | assert(cb_access_context); |
| 4318 | if (!cb_access_context) return skip; |
| 4319 | |
| 4320 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 4321 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 4322 | return skip; |
| 4323 | } |
| 4324 | |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 4325 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2(VkCommandBuffer commandBuffer, |
| 4326 | const VkDependencyInfo *pDependencyInfo) const { |
| 4327 | bool skip = false; |
| 4328 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4329 | assert(cb_access_context); |
| 4330 | if (!cb_access_context) return skip; |
| 4331 | |
| 4332 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 4333 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 4334 | return skip; |
| 4335 | } |
| 4336 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4337 | void SyncValidator::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) { |
| 4338 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4339 | assert(cb_access_context); |
| 4340 | if (!cb_access_context) return; |
| 4341 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 4342 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), |
| 4343 | *pDependencyInfo); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4344 | } |
| 4345 | |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 4346 | void SyncValidator::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer, const VkDependencyInfo *pDependencyInfo) { |
| 4347 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4348 | assert(cb_access_context); |
| 4349 | if (!cb_access_context) return; |
| 4350 | |
| 4351 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER2, *this, cb_access_context->GetQueueFlags(), |
| 4352 | *pDependencyInfo); |
| 4353 | } |
| 4354 | |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 4355 | void SyncValidator::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4356 | // The state tracker sets up the device state |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 4357 | StateTracker::CreateDevice(pCreateInfo); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4358 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 4359 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 4360 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4361 | // TODO: Find a good way to do this hooklessly. |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 4362 | SetCommandBufferResetCallback([this](VkCommandBuffer command_buffer) -> void { ResetCommandBufferCallback(command_buffer); }); |
| 4363 | SetCommandBufferFreeCallback([this](VkCommandBuffer command_buffer) -> void { FreeCommandBufferCallback(command_buffer); }); |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 4364 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 4365 | QueueId queue_id = QueueSyncState::kQueueIdBase; |
| 4366 | ForEachShared<QUEUE_STATE>([this, &queue_id](const std::shared_ptr<QUEUE_STATE> &queue_state) { |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 4367 | auto queue_flags = physical_device_state->queue_family_properties[queue_state->queueFamilyIndex].queueFlags; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 4368 | std::shared_ptr<QueueSyncState> queue_sync_state = std::make_shared<QueueSyncState>(queue_state, queue_flags, queue_id++); |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 4369 | queue_sync_states_.emplace(std::make_pair(queue_state->Queue(), std::move(queue_sync_state))); |
| 4370 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4371 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4372 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4373 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4374 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4375 | bool skip = false; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4376 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4377 | if (cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4378 | SyncOpBeginRenderPass sync_op(cmd_type, *this, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4379 | skip = sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4380 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4381 | return skip; |
| 4382 | } |
| 4383 | |
| 4384 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4385 | VkSubpassContents contents) const { |
| 4386 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4387 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4388 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4389 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4390 | return skip; |
| 4391 | } |
| 4392 | |
| 4393 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4394 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4395 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4396 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4397 | return skip; |
| 4398 | } |
| 4399 | |
| 4400 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4401 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4402 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4403 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4404 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4405 | return skip; |
| 4406 | } |
| 4407 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4408 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 4409 | VkResult result) { |
| 4410 | // The state tracker sets up the command buffer state |
| 4411 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 4412 | |
| 4413 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 4414 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 4415 | assert(cb_access_context); |
| 4416 | cb_access_context->Reset(); |
| 4417 | } |
| 4418 | |
| 4419 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4420 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd_type) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4421 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4422 | if (cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4423 | cb_context->RecordSyncOp<SyncOpBeginRenderPass>(cmd_type, *this, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4424 | } |
| 4425 | } |
| 4426 | |
| 4427 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4428 | VkSubpassContents contents) { |
| 4429 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4430 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4431 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4432 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4433 | } |
| 4434 | |
| 4435 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4436 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 4437 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4438 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4442 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4443 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 4444 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4445 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4446 | } |
| 4447 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4448 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4449 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4450 | bool skip = false; |
| 4451 | |
| 4452 | auto cb_context = GetAccessContext(commandBuffer); |
| 4453 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4454 | if (!cb_context) return skip; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4455 | SyncOpNextSubpass sync_op(cmd_type, *this, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4456 | return sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4457 | } |
| 4458 | |
| 4459 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 4460 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4461 | // Convert to a NextSubpass2 |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4462 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4463 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4464 | auto subpass_end_info = LvlInitStruct<VkSubpassEndInfo>(); |
| 4465 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, &subpass_end_info, CMD_NEXTSUBPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4466 | return skip; |
| 4467 | } |
| 4468 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4469 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4470 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4471 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4472 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4473 | return skip; |
| 4474 | } |
| 4475 | |
| 4476 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4477 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 4478 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4479 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4480 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4484 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd_type) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4485 | auto cb_context = GetAccessContext(commandBuffer); |
| 4486 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4487 | if (!cb_context) return; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4488 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4489 | cb_context->RecordSyncOp<SyncOpNextSubpass>(cmd_type, *this, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 4493 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4494 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4495 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4496 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4500 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 4501 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4502 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4503 | } |
| 4504 | |
| 4505 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4506 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 4507 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4508 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2KHR); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4509 | } |
| 4510 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4511 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4512 | CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4513 | bool skip = false; |
| 4514 | |
| 4515 | auto cb_context = GetAccessContext(commandBuffer); |
| 4516 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4517 | if (!cb_context) return skip; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4518 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4519 | SyncOpEndRenderPass sync_op(cmd_type, *this, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4520 | skip |= sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4521 | return skip; |
| 4522 | } |
| 4523 | |
| 4524 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 4525 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4526 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4527 | return skip; |
| 4528 | } |
| 4529 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4530 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4531 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4532 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4533 | return skip; |
| 4534 | } |
| 4535 | |
| 4536 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4537 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4538 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4539 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4540 | return skip; |
| 4541 | } |
| 4542 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4543 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
| 4544 | CMD_TYPE cmd_type) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4545 | // Resolve the all subpass contexts to the command buffer contexts |
| 4546 | auto cb_context = GetAccessContext(commandBuffer); |
| 4547 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4548 | if (!cb_context) return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4549 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4550 | cb_context->RecordSyncOp<SyncOpEndRenderPass>(cmd_type, *this, pSubpassEndInfo); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4551 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4552 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 4553 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 4554 | // updates to a resource which do not conflict at the byte level. |
| 4555 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 4556 | // TODO: Add programatic control over suppression heuristics |
| 4557 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 4558 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 4559 | } |
| 4560 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4561 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4562 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4563 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4564 | } |
| 4565 | |
| 4566 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4567 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4568 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4572 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2KHR); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4573 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4574 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4575 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4576 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4577 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4578 | VkImageLayout dstImageLayout, uint32_t regionCount, const RegionType *pRegions, |
| 4579 | CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4580 | bool skip = false; |
| 4581 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4582 | assert(cb_access_context); |
| 4583 | if (!cb_access_context) return skip; |
| 4584 | |
| 4585 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4586 | assert(context); |
| 4587 | if (!context) return skip; |
| 4588 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4589 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 4590 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4591 | |
| 4592 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4593 | const auto ©_region = pRegions[region]; |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4594 | HazardResult hazard; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4595 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4596 | if (src_buffer) { |
| 4597 | ResourceAccessRange src_range = |
| 4598 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4599 | hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4600 | if (hazard.hazard) { |
| 4601 | // PHASE1 TODO -- add tag information to log msg when useful. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4602 | skip |= |
| 4603 | LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4604 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 4605 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
| 4606 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4607 | } |
| 4608 | } |
| 4609 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4610 | hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.imageSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4611 | copy_region.imageOffset, copy_region.imageExtent, false); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4612 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4613 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4614 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4615 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4616 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4617 | } |
| 4618 | if (skip) break; |
| 4619 | } |
| 4620 | if (skip) break; |
| 4621 | } |
| 4622 | return skip; |
| 4623 | } |
| 4624 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4625 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4626 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4627 | const VkBufferImageCopy *pRegions) const { |
| 4628 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4629 | CMD_COPYBUFFERTOIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 4633 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 4634 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4635 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4636 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2KHR); |
| 4637 | } |
| 4638 | |
| 4639 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, |
| 4640 | const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) const { |
| 4641 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4642 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 4643 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4644 | } |
| 4645 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4646 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4647 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4648 | VkImageLayout dstImageLayout, uint32_t regionCount, const RegionType *pRegions, |
| 4649 | CMD_TYPE cmd_type) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4650 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4651 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4652 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4653 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4654 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4655 | assert(context); |
| 4656 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4657 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 4658 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4659 | |
| 4660 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4661 | const auto ©_region = pRegions[region]; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4662 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4663 | if (src_buffer) { |
| 4664 | ResourceAccessRange src_range = |
| 4665 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4666 | 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] | 4667 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4668 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4669 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4670 | } |
| 4671 | } |
| 4672 | } |
| 4673 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4674 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4675 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4676 | const VkBufferImageCopy *pRegions) { |
| 4677 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4678 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, CMD_COPYBUFFERTOIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 4682 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 4683 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 4684 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4685 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4686 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2KHR); |
| 4687 | } |
| 4688 | |
| 4689 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, |
| 4690 | const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) { |
| 4691 | StateTracker::PreCallRecordCmdCopyBufferToImage2(commandBuffer, pCopyBufferToImageInfo); |
| 4692 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4693 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 4694 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4695 | } |
| 4696 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4697 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4698 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4699 | VkBuffer dstBuffer, uint32_t regionCount, const RegionType *pRegions, |
| 4700 | CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4701 | bool skip = false; |
| 4702 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4703 | assert(cb_access_context); |
| 4704 | if (!cb_access_context) return skip; |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4705 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4706 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4707 | assert(context); |
| 4708 | if (!context) return skip; |
| 4709 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4710 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4711 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 4712 | 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] | 4713 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4714 | const auto ©_region = pRegions[region]; |
| 4715 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4716 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.imageSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4717 | copy_region.imageOffset, copy_region.imageExtent, false); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4718 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4719 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4720 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4721 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4722 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4723 | } |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4724 | if (dst_mem) { |
| 4725 | ResourceAccessRange dst_range = |
| 4726 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4727 | hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4728 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4729 | skip |= |
| 4730 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4731 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 4732 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
| 4733 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4734 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4735 | } |
| 4736 | } |
| 4737 | if (skip) break; |
| 4738 | } |
| 4739 | return skip; |
| 4740 | } |
| 4741 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4742 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 4743 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 4744 | const VkBufferImageCopy *pRegions) const { |
| 4745 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4746 | CMD_COPYIMAGETOBUFFER); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4750 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 4751 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4752 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4753 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2KHR); |
| 4754 | } |
| 4755 | |
| 4756 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, |
| 4757 | const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) const { |
| 4758 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4759 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 4760 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4761 | } |
| 4762 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4763 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4764 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4765 | VkBuffer dstBuffer, uint32_t regionCount, const RegionType *pRegions, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4766 | CMD_TYPE cmd_type) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4767 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4768 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4769 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4770 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4771 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4772 | assert(context); |
| 4773 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4774 | auto src_image = Get<IMAGE_STATE>(srcImage); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4775 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 4776 | 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] | 4777 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4778 | |
| 4779 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4780 | const auto ©_region = pRegions[region]; |
| 4781 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4782 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4783 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4784 | if (dst_buffer) { |
| 4785 | ResourceAccessRange dst_range = |
| 4786 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4787 | 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] | 4788 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4789 | } |
| 4790 | } |
| 4791 | } |
| 4792 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4793 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4794 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 4795 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4796 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, CMD_COPYIMAGETOBUFFER); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4797 | } |
| 4798 | |
| 4799 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4800 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 4801 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 4802 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4803 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4804 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2KHR); |
| 4805 | } |
| 4806 | |
| 4807 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, |
| 4808 | const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) { |
| 4809 | StateTracker::PreCallRecordCmdCopyImageToBuffer2(commandBuffer, pCopyImageToBufferInfo); |
| 4810 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4811 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 4812 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | template <typename RegionType> |
| 4816 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4817 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4818 | const RegionType *pRegions, VkFilter filter, CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4819 | bool skip = false; |
| 4820 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4821 | assert(cb_access_context); |
| 4822 | if (!cb_access_context) return skip; |
| 4823 | |
| 4824 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4825 | assert(context); |
| 4826 | if (!context) return skip; |
| 4827 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4828 | const char *caller_name = CommandTypeString(cmd_type); |
| 4829 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4830 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4831 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4832 | |
| 4833 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4834 | const auto &blit_region = pRegions[region]; |
| 4835 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4836 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4837 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4838 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4839 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4840 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4841 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].z - blit_region.srcOffsets[0].z))}; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4842 | auto hazard = |
| 4843 | context->DetectHazard(*src_image, SYNC_BLIT_TRANSFER_READ, blit_region.srcSubresource, offset, extent, false); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4844 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4845 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4846 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", caller_name, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4847 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4848 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4849 | } |
| 4850 | } |
| 4851 | |
| 4852 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4853 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4854 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4855 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4856 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4857 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4858 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].z - blit_region.dstOffsets[0].z))}; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4859 | auto hazard = |
| 4860 | context->DetectHazard(*dst_image, SYNC_BLIT_TRANSFER_WRITE, blit_region.dstSubresource, offset, extent, false); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4861 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4862 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4863 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", caller_name, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4864 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4865 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4866 | } |
| 4867 | if (skip) break; |
| 4868 | } |
| 4869 | } |
| 4870 | |
| 4871 | return skip; |
| 4872 | } |
| 4873 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4874 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4875 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4876 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 4877 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4878 | CMD_BLITIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 4882 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 4883 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4884 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4885 | pBlitImageInfo->filter, CMD_BLITIMAGE2KHR); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4886 | } |
| 4887 | |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4888 | bool SyncValidator::PreCallValidateCmdBlitImage2(VkCommandBuffer commandBuffer, |
| 4889 | const VkBlitImageInfo2 *pBlitImageInfo) const { |
| 4890 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4891 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4892 | pBlitImageInfo->filter, CMD_BLITIMAGE2); |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4893 | } |
| 4894 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4895 | template <typename RegionType> |
| 4896 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4897 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4898 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4899 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4900 | assert(cb_access_context); |
| 4901 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4902 | assert(context); |
| 4903 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4904 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4905 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4906 | |
| 4907 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4908 | const auto &blit_region = pRegions[region]; |
| 4909 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4910 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4911 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4912 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4913 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4914 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4915 | 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] | 4916 | context->UpdateAccessState(*src_image, SYNC_BLIT_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4917 | blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4918 | } |
| 4919 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4920 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4921 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4922 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4923 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4924 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4925 | 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] | 4926 | context->UpdateAccessState(*dst_image, SYNC_BLIT_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4927 | blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4928 | } |
| 4929 | } |
| 4930 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4931 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4932 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4933 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4934 | const VkImageBlit *pRegions, VkFilter filter) { |
| 4935 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4936 | assert(cb_access_context); |
| 4937 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 4938 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4939 | pRegions, filter); |
| 4940 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 4941 | } |
| 4942 | |
| 4943 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 4944 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 4945 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4946 | assert(cb_access_context); |
| 4947 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 4948 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4949 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4950 | pBlitImageInfo->filter, tag); |
| 4951 | } |
| 4952 | |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4953 | void SyncValidator::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) { |
| 4954 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 4955 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4956 | assert(cb_access_context); |
| 4957 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2); |
| 4958 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4959 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4960 | pBlitImageInfo->filter, tag); |
| 4961 | } |
| 4962 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4963 | bool SyncValidator::ValidateIndirectBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4964 | VkCommandBuffer commandBuffer, const VkDeviceSize struct_size, const VkBuffer buffer, |
| 4965 | const VkDeviceSize offset, const uint32_t drawCount, const uint32_t stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4966 | CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4967 | bool skip = false; |
| 4968 | if (drawCount == 0) return skip; |
| 4969 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4970 | const char *caller_name = CommandTypeString(cmd_type); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4971 | auto buf_state = Get<BUFFER_STATE>(buffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4972 | VkDeviceSize size = struct_size; |
| 4973 | if (drawCount == 1 || stride == size) { |
| 4974 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4975 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4976 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4977 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4978 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4979 | "%s: Hazard %s for indirect %s in %s. Access info %s.", caller_name, string_SyncHazard(hazard.hazard), |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4980 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4981 | cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4982 | } |
| 4983 | } else { |
| 4984 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4985 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4986 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4987 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4988 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4989 | "%s: Hazard %s for indirect %s in %s. Access info %s.", caller_name, |
| 4990 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(buffer).c_str(), |
| 4991 | report_data->FormatHandle(commandBuffer).c_str(), cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4992 | break; |
| 4993 | } |
| 4994 | } |
| 4995 | } |
| 4996 | return skip; |
| 4997 | } |
| 4998 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 4999 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag tag, const VkDeviceSize struct_size, |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5000 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 5001 | uint32_t stride) { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5002 | auto buf_state = Get<BUFFER_STATE>(buffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5003 | VkDeviceSize size = struct_size; |
| 5004 | if (drawCount == 1 || stride == size) { |
| 5005 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5006 | const ResourceAccessRange range = MakeRange(offset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5007 | 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] | 5008 | } else { |
| 5009 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5010 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5011 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, |
| 5012 | tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5013 | } |
| 5014 | } |
| 5015 | } |
| 5016 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5017 | bool SyncValidator::ValidateCountBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 5018 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5019 | CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5020 | bool skip = false; |
| 5021 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5022 | auto count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5023 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5024 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 5025 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5026 | skip |= LogError(count_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5027 | "%s: Hazard %s for countBuffer %s in %s. Access info %s.", CommandTypeString(cmd_type), |
| 5028 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(buffer).c_str(), |
| 5029 | report_data->FormatHandle(commandBuffer).c_str(), cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5030 | } |
| 5031 | return skip; |
| 5032 | } |
| 5033 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 5034 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag tag, VkBuffer buffer, VkDeviceSize offset) { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5035 | auto count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5036 | const ResourceAccessRange range = MakeRange(offset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5037 | 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] | 5038 | } |
| 5039 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 5040 | 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] | 5041 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5042 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5043 | assert(cb_access_context); |
| 5044 | if (!cb_access_context) return skip; |
| 5045 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5046 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5047 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | 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] | 5051 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5052 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5053 | assert(cb_access_context); |
| 5054 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5055 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5056 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 5057 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5058 | |
| 5059 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5060 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 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 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5069 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, CMD_DISPATCHINDIRECT); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5070 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5071 | 1, sizeof(VkDispatchIndirectCommand), CMD_DISPATCHINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5072 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5073 | } |
| 5074 | |
| 5075 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5076 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5077 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5078 | assert(cb_access_context); |
| 5079 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 5080 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5081 | assert(context); |
| 5082 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5083 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 5084 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 5088 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 5089 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5090 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5091 | assert(cb_access_context); |
| 5092 | if (!cb_access_context) return skip; |
| 5093 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5094 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAW); |
| 5095 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, CMD_DRAW); |
| 5096 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAW); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 5097 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 5101 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5102 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5103 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5104 | assert(cb_access_context); |
| 5105 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5106 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5107 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5108 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 5109 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5110 | } |
| 5111 | |
| 5112 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 5113 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 5114 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5115 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5116 | assert(cb_access_context); |
| 5117 | if (!cb_access_context) return skip; |
| 5118 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5119 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAWINDEXED); |
| 5120 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, CMD_DRAWINDEXED); |
| 5121 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAWINDEXED); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 5122 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 5126 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5127 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5128 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5129 | assert(cb_access_context); |
| 5130 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5131 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5132 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5133 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 5134 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5135 | } |
| 5136 | |
| 5137 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5138 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5139 | bool skip = false; |
| 5140 | if (drawCount == 0) return skip; |
| 5141 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5142 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5143 | assert(cb_access_context); |
| 5144 | if (!cb_access_context) return skip; |
| 5145 | |
| 5146 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5147 | assert(context); |
| 5148 | if (!context) return skip; |
| 5149 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5150 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAWINDIRECT); |
| 5151 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAWINDIRECT); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5152 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5153 | drawCount, stride, CMD_DRAWINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5154 | |
| 5155 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 5156 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5157 | // We will validate the vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5158 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, CMD_DRAWINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5159 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5163 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5164 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5165 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5166 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5167 | assert(cb_access_context); |
| 5168 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 5169 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5170 | assert(context); |
| 5171 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5172 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5173 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5174 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5175 | |
| 5176 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 5177 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5178 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5179 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5183 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5184 | bool skip = false; |
| 5185 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5186 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5187 | assert(cb_access_context); |
| 5188 | if (!cb_access_context) return skip; |
| 5189 | |
| 5190 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5191 | assert(context); |
| 5192 | if (!context) return skip; |
| 5193 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5194 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAWINDEXEDINDIRECT); |
| 5195 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAWINDEXEDINDIRECT); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5196 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5197 | offset, drawCount, stride, CMD_DRAWINDEXEDINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5198 | |
| 5199 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 5200 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 5201 | // We will validate the index and vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5202 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, CMD_DRAWINDEXEDINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5203 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5207 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5208 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5209 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5210 | assert(cb_access_context); |
| 5211 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 5212 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5213 | assert(context); |
| 5214 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5215 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5216 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5217 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5218 | |
| 5219 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 5220 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 5221 | // 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] | 5222 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5223 | } |
| 5224 | |
| 5225 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5226 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5227 | uint32_t stride, CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5228 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5229 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5230 | assert(cb_access_context); |
| 5231 | if (!cb_access_context) return skip; |
| 5232 | |
| 5233 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5234 | assert(context); |
| 5235 | if (!context) return skip; |
| 5236 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5237 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, cmd_type); |
| 5238 | skip |= cb_access_context->ValidateDrawSubpassAttachment(cmd_type); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5239 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5240 | maxDrawCount, stride, cmd_type); |
| 5241 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5242 | |
| 5243 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 5244 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5245 | // We will validate the vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5246 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5247 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5248 | } |
| 5249 | |
| 5250 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5251 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5252 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5253 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5254 | CMD_DRAWINDIRECTCOUNT); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5255 | } |
| 5256 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5257 | void SyncValidator::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5258 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5259 | uint32_t stride, CMD_TYPE cmd_type) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5260 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5261 | assert(cb_access_context); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5262 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5263 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5264 | assert(context); |
| 5265 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5266 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5267 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5268 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 5269 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5270 | |
| 5271 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 5272 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5273 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5274 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5275 | } |
| 5276 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5277 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5278 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5279 | uint32_t stride) { |
| 5280 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 5281 | stride); |
| 5282 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5283 | CMD_DRAWINDIRECTCOUNT); |
| 5284 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5285 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5286 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5287 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5288 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5289 | CMD_DRAWINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5293 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5294 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5295 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 5296 | stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5297 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5298 | CMD_DRAWINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5302 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5303 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5304 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5305 | CMD_DRAWINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5309 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5310 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5311 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 5312 | stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5313 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5314 | CMD_DRAWINDIRECTCOUNTAMD); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5315 | } |
| 5316 | |
| 5317 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5318 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5319 | uint32_t stride, CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5320 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5321 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5322 | assert(cb_access_context); |
| 5323 | if (!cb_access_context) return skip; |
| 5324 | |
| 5325 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5326 | assert(context); |
| 5327 | if (!context) return skip; |
| 5328 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5329 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, cmd_type); |
| 5330 | skip |= cb_access_context->ValidateDrawSubpassAttachment(cmd_type); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5331 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5332 | offset, maxDrawCount, stride, cmd_type); |
| 5333 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5334 | |
| 5335 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 5336 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 5337 | // We will validate the index and vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5338 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5339 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5343 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5344 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5345 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5346 | CMD_DRAWINDEXEDINDIRECTCOUNT); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5347 | } |
| 5348 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5349 | void SyncValidator::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5350 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5351 | uint32_t stride, CMD_TYPE cmd_type) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5352 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5353 | assert(cb_access_context); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5354 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5355 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5356 | assert(context); |
| 5357 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5358 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5359 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5360 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 5361 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5362 | |
| 5363 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 5364 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5365 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 5366 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5367 | } |
| 5368 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5369 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5370 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5371 | uint32_t maxDrawCount, uint32_t stride) { |
| 5372 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 5373 | maxDrawCount, stride); |
| 5374 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5375 | CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 5376 | } |
| 5377 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5378 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5379 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5380 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5381 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5382 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5383 | CMD_DRAWINDEXEDINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5384 | } |
| 5385 | |
| 5386 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5387 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5388 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5389 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 5390 | maxDrawCount, stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5391 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5392 | CMD_DRAWINDEXEDINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5396 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5397 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5398 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5399 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5400 | CMD_DRAWINDEXEDINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5404 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5405 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5406 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 5407 | maxDrawCount, stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5408 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5409 | CMD_DRAWINDEXEDINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5413 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 5414 | const VkImageSubresourceRange *pRanges) const { |
| 5415 | bool skip = false; |
| 5416 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5417 | assert(cb_access_context); |
| 5418 | if (!cb_access_context) return skip; |
| 5419 | |
| 5420 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5421 | assert(context); |
| 5422 | if (!context) return skip; |
| 5423 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5424 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5425 | |
| 5426 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5427 | const auto &range = pRanges[index]; |
| 5428 | if (image_state) { |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5429 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5430 | if (hazard.hazard) { |
| 5431 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5432 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5433 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5434 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5435 | } |
| 5436 | } |
| 5437 | } |
| 5438 | return skip; |
| 5439 | } |
| 5440 | |
| 5441 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5442 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 5443 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5444 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5445 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5446 | assert(cb_access_context); |
| 5447 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 5448 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5449 | assert(context); |
| 5450 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5451 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5452 | |
| 5453 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5454 | const auto &range = pRanges[index]; |
| 5455 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5456 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5457 | } |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 5462 | VkImageLayout imageLayout, |
| 5463 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 5464 | const VkImageSubresourceRange *pRanges) const { |
| 5465 | bool skip = false; |
| 5466 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5467 | assert(cb_access_context); |
| 5468 | if (!cb_access_context) return skip; |
| 5469 | |
| 5470 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5471 | assert(context); |
| 5472 | if (!context) return skip; |
| 5473 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5474 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5475 | |
| 5476 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5477 | const auto &range = pRanges[index]; |
| 5478 | if (image_state) { |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5479 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5480 | if (hazard.hazard) { |
| 5481 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5482 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5483 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5484 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5485 | } |
| 5486 | } |
| 5487 | } |
| 5488 | return skip; |
| 5489 | } |
| 5490 | |
| 5491 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5492 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 5493 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5494 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5495 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5496 | assert(cb_access_context); |
| 5497 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 5498 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5499 | assert(context); |
| 5500 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5501 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5502 | |
| 5503 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5504 | const auto &range = pRanges[index]; |
| 5505 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5506 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5507 | } |
| 5508 | } |
| 5509 | } |
| 5510 | |
| 5511 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 5512 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 5513 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 5514 | VkQueryResultFlags flags) const { |
| 5515 | bool skip = false; |
| 5516 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5517 | assert(cb_access_context); |
| 5518 | if (!cb_access_context) return skip; |
| 5519 | |
| 5520 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5521 | assert(context); |
| 5522 | if (!context) return skip; |
| 5523 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5524 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5525 | |
| 5526 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5527 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5528 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5529 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5530 | skip |= |
| 5531 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5532 | "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] | 5533 | 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] | 5534 | } |
| 5535 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5536 | |
| 5537 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5538 | return skip; |
| 5539 | } |
| 5540 | |
| 5541 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 5542 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5543 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5544 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 5545 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5546 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5547 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5548 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5549 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5550 | assert(context); |
| 5551 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5552 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5553 | |
| 5554 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5555 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5556 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5557 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5558 | |
| 5559 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5563 | VkDeviceSize size, uint32_t data) const { |
| 5564 | bool skip = false; |
| 5565 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5566 | assert(cb_access_context); |
| 5567 | if (!cb_access_context) return skip; |
| 5568 | |
| 5569 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5570 | assert(context); |
| 5571 | if (!context) return skip; |
| 5572 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5573 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5574 | |
| 5575 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5576 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5577 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5578 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5579 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5580 | "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] | 5581 | 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] | 5582 | } |
| 5583 | } |
| 5584 | return skip; |
| 5585 | } |
| 5586 | |
| 5587 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5588 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5589 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5590 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5591 | assert(cb_access_context); |
| 5592 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 5593 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5594 | assert(context); |
| 5595 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5596 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5597 | |
| 5598 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5599 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5600 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5601 | } |
| 5602 | } |
| 5603 | |
| 5604 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 5605 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 5606 | const VkImageResolve *pRegions) const { |
| 5607 | bool skip = false; |
| 5608 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5609 | assert(cb_access_context); |
| 5610 | if (!cb_access_context) return skip; |
| 5611 | |
| 5612 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5613 | assert(context); |
| 5614 | if (!context) return skip; |
| 5615 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5616 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 5617 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5618 | |
| 5619 | for (uint32_t region = 0; region < regionCount; region++) { |
| 5620 | const auto &resolve_region = pRegions[region]; |
| 5621 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5622 | auto hazard = context->DetectHazard(*src_image, SYNC_RESOLVE_TRANSFER_READ, resolve_region.srcSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5623 | resolve_region.srcOffset, resolve_region.extent, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5624 | if (hazard.hazard) { |
| 5625 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5626 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5627 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5628 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5629 | } |
| 5630 | } |
| 5631 | |
| 5632 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5633 | auto hazard = context->DetectHazard(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, resolve_region.dstSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5634 | resolve_region.dstOffset, resolve_region.extent, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5635 | if (hazard.hazard) { |
| 5636 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5637 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5638 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5639 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5640 | } |
| 5641 | if (skip) break; |
| 5642 | } |
| 5643 | } |
| 5644 | |
| 5645 | return skip; |
| 5646 | } |
| 5647 | |
| 5648 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 5649 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 5650 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5651 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 5652 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5653 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5654 | assert(cb_access_context); |
| 5655 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 5656 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5657 | assert(context); |
| 5658 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 5659 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 5660 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5661 | |
| 5662 | for (uint32_t region = 0; region < regionCount; region++) { |
| 5663 | const auto &resolve_region = pRegions[region]; |
| 5664 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5665 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5666 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5667 | } |
| 5668 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5669 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5670 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5671 | } |
| 5672 | } |
| 5673 | } |
| 5674 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5675 | bool SyncValidator::ValidateCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2KHR *pResolveImageInfo, |
| 5676 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5677 | bool skip = false; |
| 5678 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5679 | assert(cb_access_context); |
| 5680 | if (!cb_access_context) return skip; |
| 5681 | |
| 5682 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5683 | assert(context); |
| 5684 | if (!context) return skip; |
| 5685 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5686 | auto src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 5687 | auto dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5688 | |
| 5689 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 5690 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 5691 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5692 | auto hazard = context->DetectHazard(*src_image, SYNC_RESOLVE_TRANSFER_READ, resolve_region.srcSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5693 | resolve_region.srcOffset, resolve_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5694 | if (hazard.hazard) { |
| 5695 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5696 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5697 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5698 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5699 | } |
| 5700 | } |
| 5701 | |
| 5702 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5703 | auto hazard = context->DetectHazard(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, resolve_region.dstSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5704 | resolve_region.dstOffset, resolve_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5705 | if (hazard.hazard) { |
| 5706 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5707 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5708 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5709 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5710 | } |
| 5711 | if (skip) break; |
| 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | return skip; |
| 5716 | } |
| 5717 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5718 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 5719 | const VkResolveImageInfo2KHR *pResolveImageInfo) const { |
| 5720 | return ValidateCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2KHR); |
| 5721 | } |
| 5722 | |
| 5723 | bool SyncValidator::PreCallValidateCmdResolveImage2(VkCommandBuffer commandBuffer, |
| 5724 | const VkResolveImageInfo2 *pResolveImageInfo) const { |
| 5725 | return ValidateCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2); |
| 5726 | } |
| 5727 | |
| 5728 | void SyncValidator::RecordCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2KHR *pResolveImageInfo, |
| 5729 | CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5730 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 5731 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5732 | assert(cb_access_context); |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5733 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5734 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5735 | assert(context); |
| 5736 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 5737 | auto src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 5738 | auto dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5739 | |
| 5740 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 5741 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 5742 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5743 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5744 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5745 | } |
| 5746 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5747 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5748 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5749 | } |
| 5750 | } |
| 5751 | } |
| 5752 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5753 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 5754 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 5755 | RecordCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2KHR); |
| 5756 | } |
| 5757 | |
| 5758 | void SyncValidator::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2 *pResolveImageInfo) { |
| 5759 | RecordCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2); |
| 5760 | } |
| 5761 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5762 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5763 | VkDeviceSize dataSize, const void *pData) const { |
| 5764 | bool skip = false; |
| 5765 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5766 | assert(cb_access_context); |
| 5767 | if (!cb_access_context) return skip; |
| 5768 | |
| 5769 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5770 | assert(context); |
| 5771 | if (!context) return skip; |
| 5772 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5773 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5774 | |
| 5775 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5776 | // VK_WHOLE_SIZE not allowed |
| 5777 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5778 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5779 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5780 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5781 | "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] | 5782 | 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] | 5783 | } |
| 5784 | } |
| 5785 | return skip; |
| 5786 | } |
| 5787 | |
| 5788 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5789 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5790 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5791 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5792 | assert(cb_access_context); |
| 5793 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 5794 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5795 | assert(context); |
| 5796 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5797 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5798 | |
| 5799 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5800 | // VK_WHOLE_SIZE not allowed |
| 5801 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5802 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5803 | } |
| 5804 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5805 | |
| 5806 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 5807 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 5808 | bool skip = false; |
| 5809 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5810 | assert(cb_access_context); |
| 5811 | if (!cb_access_context) return skip; |
| 5812 | |
| 5813 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5814 | assert(context); |
| 5815 | if (!context) return skip; |
| 5816 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5817 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5818 | |
| 5819 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5820 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5821 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5822 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5823 | skip |= |
| 5824 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5825 | "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] | 5826 | 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] | 5827 | } |
| 5828 | } |
| 5829 | return skip; |
| 5830 | } |
| 5831 | |
| 5832 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 5833 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5834 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5835 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5836 | assert(cb_access_context); |
| 5837 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 5838 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5839 | assert(context); |
| 5840 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5841 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5842 | |
| 5843 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5844 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5845 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5846 | } |
| 5847 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5848 | |
| 5849 | bool SyncValidator::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
| 5850 | bool skip = false; |
| 5851 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5852 | assert(cb_context); |
| 5853 | if (!cb_context) return skip; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5854 | const auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5855 | assert(access_context); |
| 5856 | if (!access_context) return skip; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5857 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5858 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask, nullptr); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5859 | return set_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5860 | } |
| 5861 | |
| 5862 | void SyncValidator::PostCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 5863 | StateTracker::PostCallRecordCmdSetEvent(commandBuffer, event, stageMask); |
| 5864 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5865 | assert(cb_context); |
| 5866 | if (!cb_context) return; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5867 | |
| 5868 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask, |
| 5869 | cb_context->GetCurrentAccessContext()); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5870 | } |
| 5871 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5872 | bool SyncValidator::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5873 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 5874 | bool skip = false; |
| 5875 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5876 | assert(cb_context); |
| 5877 | if (!cb_context || !pDependencyInfo) return skip; |
| 5878 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5879 | const auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5880 | assert(access_context); |
| 5881 | if (!access_context) return skip; |
| 5882 | |
| 5883 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo, nullptr); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5884 | return set_event_op.Validate(*cb_context); |
| 5885 | } |
| 5886 | |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5887 | bool SyncValidator::PreCallValidateCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5888 | const VkDependencyInfo *pDependencyInfo) const { |
| 5889 | bool skip = false; |
| 5890 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5891 | assert(cb_context); |
| 5892 | if (!cb_context || !pDependencyInfo) return skip; |
| 5893 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5894 | SyncOpSetEvent set_event_op(CMD_SETEVENT2, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo, nullptr); |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5895 | return set_event_op.Validate(*cb_context); |
| 5896 | } |
| 5897 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5898 | void SyncValidator::PostCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5899 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 5900 | StateTracker::PostCallRecordCmdSetEvent2KHR(commandBuffer, event, pDependencyInfo); |
| 5901 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5902 | assert(cb_context); |
| 5903 | if (!cb_context || !pDependencyInfo) return; |
| 5904 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5905 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo, |
| 5906 | cb_context->GetCurrentAccessContext()); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5907 | } |
| 5908 | |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5909 | void SyncValidator::PostCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5910 | const VkDependencyInfo *pDependencyInfo) { |
| 5911 | StateTracker::PostCallRecordCmdSetEvent2(commandBuffer, event, pDependencyInfo); |
| 5912 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5913 | assert(cb_context); |
| 5914 | if (!cb_context || !pDependencyInfo) return; |
| 5915 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 5916 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT2, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo, |
| 5917 | cb_context->GetCurrentAccessContext()); |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5920 | bool SyncValidator::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 5921 | VkPipelineStageFlags stageMask) const { |
| 5922 | bool skip = false; |
| 5923 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5924 | assert(cb_context); |
| 5925 | if (!cb_context) return skip; |
| 5926 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5927 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5928 | return reset_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5929 | } |
| 5930 | |
| 5931 | void SyncValidator::PostCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 5932 | StateTracker::PostCallRecordCmdResetEvent(commandBuffer, event, stageMask); |
| 5933 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5934 | assert(cb_context); |
| 5935 | if (!cb_context) return; |
| 5936 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5937 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5938 | } |
| 5939 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5940 | bool SyncValidator::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5941 | VkPipelineStageFlags2KHR stageMask) const { |
| 5942 | bool skip = false; |
| 5943 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5944 | assert(cb_context); |
| 5945 | if (!cb_context) return skip; |
| 5946 | |
| 5947 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5948 | return reset_event_op.Validate(*cb_context); |
| 5949 | } |
| 5950 | |
Tony-LunarG | a2662db | 2021-11-16 07:26:24 -0700 | [diff] [blame] | 5951 | bool SyncValidator::PreCallValidateCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5952 | VkPipelineStageFlags2 stageMask) const { |
| 5953 | bool skip = false; |
| 5954 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5955 | assert(cb_context); |
| 5956 | if (!cb_context) return skip; |
| 5957 | |
| 5958 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5959 | return reset_event_op.Validate(*cb_context); |
| 5960 | } |
| 5961 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5962 | void SyncValidator::PostCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5963 | VkPipelineStageFlags2KHR stageMask) { |
| 5964 | StateTracker::PostCallRecordCmdResetEvent2KHR(commandBuffer, event, stageMask); |
| 5965 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5966 | assert(cb_context); |
| 5967 | if (!cb_context) return; |
| 5968 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5969 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5970 | } |
| 5971 | |
Tony-LunarG | a2662db | 2021-11-16 07:26:24 -0700 | [diff] [blame] | 5972 | void SyncValidator::PostCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2 stageMask) { |
| 5973 | StateTracker::PostCallRecordCmdResetEvent2(commandBuffer, event, stageMask); |
| 5974 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5975 | assert(cb_context); |
| 5976 | if (!cb_context) return; |
| 5977 | |
| 5978 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT2, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5979 | } |
| 5980 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5981 | bool SyncValidator::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5982 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5983 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5984 | uint32_t bufferMemoryBarrierCount, |
| 5985 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5986 | uint32_t imageMemoryBarrierCount, |
| 5987 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 5988 | bool skip = false; |
| 5989 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5990 | assert(cb_context); |
| 5991 | if (!cb_context) return skip; |
| 5992 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5993 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 5994 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 5995 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5996 | return wait_events_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5997 | } |
| 5998 | |
| 5999 | void SyncValidator::PostCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 6000 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 6001 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 6002 | uint32_t bufferMemoryBarrierCount, |
| 6003 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 6004 | uint32_t imageMemoryBarrierCount, |
| 6005 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 6006 | StateTracker::PostCallRecordCmdWaitEvents(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
| 6007 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 6008 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 6009 | |
| 6010 | auto *cb_context = GetAccessContext(commandBuffer); |
| 6011 | assert(cb_context); |
| 6012 | if (!cb_context) return; |
| 6013 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6014 | cb_context->RecordSyncOp<SyncOpWaitEvents>( |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6015 | CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6016 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6017 | } |
| 6018 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6019 | bool SyncValidator::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 6020 | const VkDependencyInfoKHR *pDependencyInfos) const { |
| 6021 | bool skip = false; |
| 6022 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 6023 | assert(cb_context); |
| 6024 | if (!cb_context) return skip; |
| 6025 | |
| 6026 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 6027 | skip |= wait_events_op.Validate(*cb_context); |
| 6028 | return skip; |
| 6029 | } |
| 6030 | |
| 6031 | void SyncValidator::PostCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 6032 | const VkDependencyInfoKHR *pDependencyInfos) { |
| 6033 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 6034 | |
| 6035 | auto *cb_context = GetAccessContext(commandBuffer); |
| 6036 | assert(cb_context); |
| 6037 | if (!cb_context) return; |
| 6038 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6039 | cb_context->RecordSyncOp<SyncOpWaitEvents>(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, |
| 6040 | pDependencyInfos); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6041 | } |
| 6042 | |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 6043 | bool SyncValidator::PreCallValidateCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 6044 | const VkDependencyInfo *pDependencyInfos) const { |
| 6045 | bool skip = false; |
| 6046 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 6047 | assert(cb_context); |
| 6048 | if (!cb_context) return skip; |
| 6049 | |
| 6050 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 6051 | skip |= wait_events_op.Validate(*cb_context); |
| 6052 | return skip; |
| 6053 | } |
| 6054 | |
| 6055 | void SyncValidator::PostCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 6056 | const VkDependencyInfo *pDependencyInfos) { |
| 6057 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 6058 | |
| 6059 | auto *cb_context = GetAccessContext(commandBuffer); |
| 6060 | assert(cb_context); |
| 6061 | if (!cb_context) return; |
| 6062 | |
| 6063 | cb_context->RecordSyncOp<SyncOpWaitEvents>(CMD_WAITEVENTS2, *this, cb_context->GetQueueFlags(), eventCount, pEvents, |
| 6064 | pDependencyInfos); |
| 6065 | } |
| 6066 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6067 | void SyncEventState::ResetFirstScope() { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6068 | first_scope.reset(); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 6069 | scope = SyncExecScope(); |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6070 | first_scope_tag = 0; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6071 | } |
| 6072 | |
| 6073 | // Keep the "ignore this event" logic in same place for ValidateWait and RecordWait to use |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6074 | SyncEventState::IgnoreReason SyncEventState::IsIgnoredByWait(CMD_TYPE cmd_type, VkPipelineStageFlags2KHR srcStageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6075 | IgnoreReason reason = NotIgnored; |
| 6076 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6077 | if ((CMD_WAITEVENTS2KHR == cmd_type || CMD_WAITEVENTS2 == cmd_type) && (CMD_SETEVENT == last_command)) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6078 | reason = SetVsWait2; |
| 6079 | } else if ((last_command == CMD_RESETEVENT || last_command == CMD_RESETEVENT2KHR) && !HasBarrier(0U, 0U)) { |
| 6080 | reason = (last_command == CMD_RESETEVENT) ? ResetWaitRace : Reset2WaitRace; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6081 | } else if (unsynchronized_set) { |
| 6082 | reason = SetRace; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6083 | } else if (first_scope) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6084 | const VkPipelineStageFlags2KHR missing_bits = scope.mask_param & ~srcStageMask; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6085 | // Note it is the "not missing bits" path that is the only "NotIgnored" path |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6086 | if (missing_bits) reason = MissingStageBits; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6087 | } else { |
| 6088 | reason = MissingSetEvent; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | return reason; |
| 6092 | } |
| 6093 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6094 | bool SyncEventState::HasBarrier(VkPipelineStageFlags2KHR stageMask, VkPipelineStageFlags2KHR exec_scope_arg) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 6095 | bool has_barrier = (last_command == CMD_NONE) || (stageMask & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) || |
| 6096 | (barriers & exec_scope_arg) || (barriers & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 6097 | return has_barrier; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 6098 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6099 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6100 | void SyncOpBase::SetReplayContext(uint32_t subpass, ReplayContextPtr &&replay) { |
| 6101 | subpass_ = subpass; |
| 6102 | replay_context_ = std::move(replay); |
| 6103 | } |
| 6104 | |
| 6105 | const ReplayTrackbackBarriersAction *SyncOpBase::GetReplayTrackback() const { |
| 6106 | if (replay_context_) { |
| 6107 | assert(subpass_ < replay_context_->subpass_contexts.size()); |
| 6108 | return &replay_context_->subpass_contexts[subpass_]; |
| 6109 | } |
| 6110 | return nullptr; |
| 6111 | } |
| 6112 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6113 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 6114 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 6115 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6116 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 6117 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 6118 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6119 | : SyncOpBase(cmd_type), barriers_(1) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6120 | auto &barrier_set = barriers_[0]; |
| 6121 | barrier_set.dependency_flags = dependencyFlags; |
| 6122 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, srcStageMask); |
| 6123 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, dstStageMask); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6124 | // 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] | 6125 | barrier_set.MakeMemoryBarriers(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, memoryBarrierCount, |
| 6126 | pMemoryBarriers); |
| 6127 | barrier_set.MakeBufferMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 6128 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
| 6129 | barrier_set.MakeImageMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 6130 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6131 | } |
| 6132 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6133 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t event_count, |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6134 | const VkDependencyInfoKHR *dep_infos) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6135 | : SyncOpBase(cmd_type), barriers_(event_count) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6136 | for (uint32_t i = 0; i < event_count; i++) { |
| 6137 | const auto &dep_info = dep_infos[i]; |
| 6138 | auto &barrier_set = barriers_[i]; |
| 6139 | barrier_set.dependency_flags = dep_info.dependencyFlags; |
| 6140 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 6141 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, stage_masks.src); |
| 6142 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, stage_masks.dst); |
| 6143 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
| 6144 | barrier_set.MakeMemoryBarriers(queue_flags, dep_info.dependencyFlags, dep_info.memoryBarrierCount, |
| 6145 | dep_info.pMemoryBarriers); |
| 6146 | barrier_set.MakeBufferMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.bufferMemoryBarrierCount, |
| 6147 | dep_info.pBufferMemoryBarriers); |
| 6148 | barrier_set.MakeImageMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.imageMemoryBarrierCount, |
| 6149 | dep_info.pImageMemoryBarriers); |
| 6150 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6151 | } |
| 6152 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6153 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6154 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 6155 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 6156 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 6157 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 6158 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6159 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, |
| 6160 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 6161 | pImageMemoryBarriers) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6162 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6163 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6164 | const VkDependencyInfoKHR &dep_info) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6165 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, 1, &dep_info) {} |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6166 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6167 | bool SyncOpPipelineBarrier::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6168 | bool skip = false; |
| 6169 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 6170 | assert(context); |
| 6171 | if (!context) return skip; |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 6172 | assert(barriers_.size() == 1); // PipelineBarriers only support a single barrier set. |
| 6173 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6174 | // Validate Image Layout transitions |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 6175 | const auto &barrier_set = barriers_[0]; |
| 6176 | for (const auto &image_barrier : barrier_set.image_memory_barriers) { |
| 6177 | if (image_barrier.new_layout == image_barrier.old_layout) continue; // Only interested in layout transitions at this point. |
| 6178 | const auto *image_state = image_barrier.image.get(); |
| 6179 | if (!image_state) continue; |
| 6180 | const auto hazard = context->DetectImageBarrierHazard(image_barrier); |
| 6181 | if (hazard.hazard) { |
| 6182 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 6183 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6184 | const auto image_handle = image_state->image(); |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 6185 | skip |= sync_state.LogError(image_handle, string_SyncHazardVUID(hazard.hazard), |
| 6186 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 6187 | string_SyncHazard(hazard.hazard), image_barrier.index, |
| 6188 | sync_state.report_data->FormatHandle(image_handle).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6189 | cb_context.FormatHazard(hazard).c_str()); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6190 | } |
| 6191 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6192 | return skip; |
| 6193 | } |
| 6194 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6195 | struct SyncOpPipelineBarrierFunctorFactory { |
| 6196 | using BarrierOpFunctor = PipelineBarrierOp; |
| 6197 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 6198 | using GlobalBarrierOpFunctor = PipelineBarrierOp; |
| 6199 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 6200 | using BufferRange = ResourceAccessRange; |
| 6201 | using ImageRange = subresource_adapter::ImageRangeGenerator; |
| 6202 | using GlobalRange = ResourceAccessRange; |
| 6203 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6204 | ApplyFunctor MakeApplyFunctor(QueueId queue_id, const SyncBarrier &barrier, bool layout_transition) const { |
| 6205 | return ApplyFunctor(BarrierOpFunctor(queue_id, barrier, layout_transition)); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6206 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 6207 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6208 | return GlobalApplyFunctor(true /* resolve */, size_hint, tag); |
| 6209 | } |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6210 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(QueueId queue_id, const SyncBarrier &barrier) const { |
| 6211 | return GlobalBarrierOpFunctor(queue_id, barrier, false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6212 | } |
| 6213 | |
| 6214 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range) const { |
| 6215 | if (!SimpleBinding(buffer)) return ResourceAccessRange(); |
| 6216 | const auto base_address = ResourceBaseAddress(buffer); |
| 6217 | return (range + base_address); |
| 6218 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 6219 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 6220 | if (!SimpleBinding(image)) return subresource_adapter::ImageRangeGenerator(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6221 | |
| 6222 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 6223 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address, false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6224 | return range_gen; |
| 6225 | } |
| 6226 | GlobalRange MakeGlobalRangeGen(AccessAddressType) const { return kFullRange; } |
| 6227 | }; |
| 6228 | |
| 6229 | template <typename Barriers, typename FunctorFactory> |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6230 | void SyncOpBarriers::ApplyBarriers(const Barriers &barriers, const FunctorFactory &factory, const QueueId queue_id, |
| 6231 | const ResourceUsageTag tag, AccessContext *context) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6232 | for (const auto &barrier : barriers) { |
| 6233 | const auto *state = barrier.GetState(); |
| 6234 | if (state) { |
| 6235 | auto *const accesses = &context->GetAccessStateMap(GetAccessAddressType(*state)); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6236 | auto update_action = factory.MakeApplyFunctor(queue_id, barrier.barrier, barrier.IsLayoutTransition()); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6237 | auto range_gen = factory.MakeRangeGen(*state, barrier.Range()); |
| 6238 | UpdateMemoryAccessState(accesses, update_action, &range_gen); |
| 6239 | } |
| 6240 | } |
| 6241 | } |
| 6242 | |
| 6243 | template <typename Barriers, typename FunctorFactory> |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6244 | void SyncOpBarriers::ApplyGlobalBarriers(const Barriers &barriers, const FunctorFactory &factory, const QueueId queue_id, |
| 6245 | const ResourceUsageTag tag, AccessContext *access_context) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6246 | auto barriers_functor = factory.MakeGlobalApplyFunctor(barriers.size(), tag); |
| 6247 | for (const auto &barrier : barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6248 | barriers_functor.EmplaceBack(factory.MakeGlobalBarrierOpFunctor(queue_id, barrier)); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6249 | } |
| 6250 | for (const auto address_type : kAddressTypes) { |
| 6251 | auto range_gen = factory.MakeGlobalRangeGen(address_type); |
| 6252 | UpdateMemoryAccessState(&(access_context->GetAccessStateMap(address_type)), barriers_functor, &range_gen); |
| 6253 | } |
| 6254 | } |
| 6255 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6256 | ResourceUsageTag SyncOpPipelineBarrier::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6257 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6258 | auto *events_context = cb_context->GetCurrentEventsContext(); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6259 | const QueueId queue_id = cb_context->GetQueueId(); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6260 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6261 | ReplayRecord(queue_id, tag, access_context, events_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6262 | return tag; |
| 6263 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6264 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6265 | void SyncOpPipelineBarrier::ReplayRecord(QueueId queue_id, const ResourceUsageTag tag, AccessContext *access_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6266 | SyncEventsContext *events_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6267 | SyncOpPipelineBarrierFunctorFactory factory; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6268 | // Pipeline barriers only have a single barrier set, unlike WaitEvents2 |
| 6269 | assert(barriers_.size() == 1); |
| 6270 | const auto &barrier_set = barriers_[0]; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6271 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, queue_id, tag, access_context); |
| 6272 | ApplyBarriers(barrier_set.image_memory_barriers, factory, queue_id, tag, access_context); |
| 6273 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, queue_id, tag, access_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6274 | if (barrier_set.single_exec_scope) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6275 | events_context->ApplyBarrier(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, tag); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6276 | } else { |
| 6277 | for (const auto &barrier : barrier_set.memory_barriers) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6278 | events_context->ApplyBarrier(barrier.src_exec_scope, barrier.dst_exec_scope, tag); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6279 | } |
| 6280 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6281 | } |
| 6282 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6283 | bool SyncOpPipelineBarrier::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6284 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6285 | // No Validation for replay, as the layout transition accesses are checked directly, and the src*Mask ordering is captured |
| 6286 | // with first access information. |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6287 | return false; |
| 6288 | } |
| 6289 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6290 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(const SyncExecScope &src, const SyncExecScope &dst, |
| 6291 | VkDependencyFlags dependency_flags, uint32_t memory_barrier_count, |
| 6292 | const VkMemoryBarrier *barriers) { |
| 6293 | memory_barriers.reserve(std::max<uint32_t>(1, memory_barrier_count)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6294 | 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] | 6295 | const auto &barrier = barriers[barrier_index]; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6296 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6297 | memory_barriers.emplace_back(sync_barrier); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6298 | } |
| 6299 | if (0 == memory_barrier_count) { |
| 6300 | // If there are no global memory barriers, force an exec barrier |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6301 | memory_barriers.emplace_back(SyncBarrier(src, dst)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6302 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6303 | single_exec_scope = true; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6304 | } |
| 6305 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6306 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 6307 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 6308 | uint32_t barrier_count, const VkBufferMemoryBarrier *barriers) { |
| 6309 | buffer_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6310 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6311 | const auto &barrier = barriers[index]; |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6312 | auto buffer = sync_state.Get<BUFFER_STATE>(barrier.buffer); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6313 | if (buffer) { |
| 6314 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 6315 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 6316 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6317 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6318 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6319 | buffer_memory_barriers.emplace_back(); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6320 | } |
| 6321 | } |
| 6322 | } |
| 6323 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6324 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(VkQueueFlags queue_flags, VkDependencyFlags dependency_flags, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 6325 | uint32_t memory_barrier_count, const VkMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6326 | memory_barriers.reserve(memory_barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6327 | 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] | 6328 | const auto &barrier = barriers[barrier_index]; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6329 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 6330 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 6331 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6332 | memory_barriers.emplace_back(sync_barrier); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6333 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6334 | single_exec_scope = false; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6335 | } |
| 6336 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6337 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6338 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 6339 | const VkBufferMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6340 | buffer_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6341 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6342 | const auto &barrier = barriers[index]; |
| 6343 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 6344 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6345 | auto buffer = sync_state.Get<BUFFER_STATE>(barrier.buffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6346 | if (buffer) { |
| 6347 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 6348 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 6349 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6350 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6351 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6352 | buffer_memory_barriers.emplace_back(); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6353 | } |
| 6354 | } |
| 6355 | } |
| 6356 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6357 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 6358 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 6359 | uint32_t barrier_count, const VkImageMemoryBarrier *barriers) { |
| 6360 | image_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6361 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6362 | const auto &barrier = barriers[index]; |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6363 | auto image = sync_state.Get<IMAGE_STATE>(barrier.image); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6364 | if (image) { |
| 6365 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 6366 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6367 | 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] | 6368 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6369 | image_memory_barriers.emplace_back(); |
| 6370 | 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] | 6371 | } |
| 6372 | } |
| 6373 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6374 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6375 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6376 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 6377 | const VkImageMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6378 | image_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6379 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6380 | const auto &barrier = barriers[index]; |
| 6381 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 6382 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6383 | auto image = sync_state.Get<IMAGE_STATE>(barrier.image); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6384 | if (image) { |
| 6385 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 6386 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6387 | 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] | 6388 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6389 | image_memory_barriers.emplace_back(); |
| 6390 | 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] | 6391 | } |
| 6392 | } |
| 6393 | } |
| 6394 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6395 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6396 | uint32_t eventCount, const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, |
| 6397 | VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, |
| 6398 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 6399 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 6400 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
| 6401 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, srcStageMask, dstStageMask, VkDependencyFlags(0U), memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6402 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 6403 | pImageMemoryBarriers) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6404 | MakeEventsList(sync_state, eventCount, pEvents); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6405 | } |
| 6406 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6407 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6408 | uint32_t eventCount, const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfo) |
| 6409 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, eventCount, pDependencyInfo) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6410 | MakeEventsList(sync_state, eventCount, pEvents); |
| 6411 | assert(events_.size() == barriers_.size()); // Just so nobody gets clever and decides to cull the event or barrier arrays |
| 6412 | } |
| 6413 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6414 | const char *const SyncOpWaitEvents::kIgnored = "Wait operation is ignored for this event."; |
| 6415 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6416 | bool SyncOpWaitEvents::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6417 | bool skip = false; |
| 6418 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6419 | const auto command_buffer_handle = cb_context.GetCBState().commandBuffer(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6420 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6421 | // This is only interesting at record and not replay (Execute/Submit) time. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6422 | for (size_t barrier_set_index = 0; barrier_set_index < barriers_.size(); barrier_set_index++) { |
| 6423 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6424 | if (barrier_set.single_exec_scope) { |
| 6425 | if (barrier_set.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 6426 | const std::string vuid = std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 6427 | skip = sync_state.LogInfo(command_buffer_handle, vuid, |
| 6428 | "%s, srcStageMask includes %s, unsupported by synchronization validation.", CmdName(), |
| 6429 | string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT)); |
| 6430 | } else { |
| 6431 | const auto &barriers = barrier_set.memory_barriers; |
| 6432 | for (size_t barrier_index = 0; barrier_index < barriers.size(); barrier_index++) { |
| 6433 | const auto &barrier = barriers[barrier_index]; |
| 6434 | if (barrier.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 6435 | const std::string vuid = |
| 6436 | std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 6437 | skip = |
| 6438 | sync_state.LogInfo(command_buffer_handle, vuid, |
| 6439 | "%s, srcStageMask %s of %s %zu, %s %zu, unsupported by synchronization validation.", |
| 6440 | CmdName(), string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT), |
| 6441 | "pDependencyInfo", barrier_set_index, "pMemoryBarriers", barrier_index); |
| 6442 | } |
| 6443 | } |
| 6444 | } |
| 6445 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6446 | } |
| 6447 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6448 | // The rest is common to record time and replay time. |
| 6449 | skip |= DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6450 | return skip; |
| 6451 | } |
| 6452 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6453 | bool SyncOpWaitEvents::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6454 | bool skip = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6455 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6456 | const QueueId queue_id = exec_context.GetQueueId(); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6457 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6458 | VkPipelineStageFlags2KHR event_stage_masks = 0U; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6459 | VkPipelineStageFlags2KHR barrier_mask_params = 0U; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6460 | bool events_not_found = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6461 | const auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6462 | assert(events_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6463 | size_t barrier_set_index = 0; |
| 6464 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6465 | for (const auto &event : events_) { |
| 6466 | const auto *sync_event = events_context->Get(event.get()); |
| 6467 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6468 | if (!sync_event) { |
| 6469 | // NOTE PHASE2: This is where we'll need queue submit time validation to come back and check the srcStageMask bits |
| 6470 | // or solve this with replay creating the SyncEventState in the queue context... also this will be a |
| 6471 | // new validation error... wait without previously submitted set event... |
| 6472 | 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] | 6473 | barrier_set_index += barrier_set_incr; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6474 | continue; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6475 | } |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6476 | |
| 6477 | // For replay calls, don't revalidate "same command buffer" events |
| 6478 | if (sync_event->last_command_tag > base_tag) continue; |
| 6479 | |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6480 | const auto event_handle = sync_event->event->event(); |
| 6481 | // TODO add "destroyed" checks |
| 6482 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6483 | if (sync_event->first_scope) { |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6484 | // Only accumulate barrier and event stages if there is a pending set in the current context |
| 6485 | barrier_mask_params |= barrier_set.src_exec_scope.mask_param; |
| 6486 | event_stage_masks |= sync_event->scope.mask_param; |
| 6487 | } |
| 6488 | |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6489 | const auto &src_exec_scope = barrier_set.src_exec_scope; |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6490 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6491 | const auto ignore_reason = sync_event->IsIgnoredByWait(cmd_type_, src_exec_scope.mask_param); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6492 | if (ignore_reason) { |
| 6493 | switch (ignore_reason) { |
| 6494 | case SyncEventState::ResetWaitRace: |
| 6495 | case SyncEventState::Reset2WaitRace: { |
| 6496 | // Four permuations of Reset and Wait calls... |
| 6497 | const char *vuid = |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6498 | (cmd_type_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent-event-03834" : "VUID-vkCmdResetEvent-event-03835"; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6499 | if (ignore_reason == SyncEventState::Reset2WaitRace) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6500 | vuid = (cmd_type_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent2-event-03831" |
| 6501 | : "VUID-vkCmdResetEvent2-event-03832"; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6502 | } |
| 6503 | const char *const message = |
| 6504 | "%s: %s %s operation following %s without intervening execution barrier, may cause race condition. %s"; |
| 6505 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6506 | sync_state.report_data->FormatHandle(event_handle).c_str(), CmdName(), |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6507 | CommandTypeString(sync_event->last_command), kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6508 | break; |
| 6509 | } |
| 6510 | case SyncEventState::SetRace: { |
| 6511 | // Issue error message that Wait is waiting on an signal subject to race condition, and is thus ignored for |
| 6512 | // this event |
| 6513 | const char *const vuid = "SYNC-vkCmdWaitEvents-unsynchronized-setops"; |
| 6514 | const char *const message = |
| 6515 | "%s: %s Unsychronized %s calls result in race conditions w.r.t. event signalling, %s %s"; |
| 6516 | const char *const reason = "First synchronization scope is undefined."; |
| 6517 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6518 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6519 | CommandTypeString(sync_event->last_command), reason, kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6520 | break; |
| 6521 | } |
| 6522 | case SyncEventState::MissingStageBits: { |
| 6523 | const auto missing_bits = sync_event->scope.mask_param & ~src_exec_scope.mask_param; |
| 6524 | // Issue error message that event waited for is not in wait events scope |
| 6525 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 6526 | const char *const message = "%s: %s stageMask %" PRIx64 " includes bits not present in srcStageMask 0x%" PRIx64 |
| 6527 | ". Bits missing from srcStageMask %s. %s"; |
| 6528 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6529 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 6530 | sync_event->scope.mask_param, src_exec_scope.mask_param, |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6531 | sync_utils::StringPipelineStageFlags(missing_bits).c_str(), kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6532 | break; |
| 6533 | } |
| 6534 | case SyncEventState::SetVsWait2: { |
Tony-LunarG | 279601c | 2021-11-16 10:50:51 -0700 | [diff] [blame] | 6535 | skip |= sync_state.LogError(event_handle, "VUID-vkCmdWaitEvents2-pEvents-03837", |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6536 | "%s: Follows set of %s by %s. Disallowed.", CmdName(), |
| 6537 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 6538 | CommandTypeString(sync_event->last_command)); |
| 6539 | break; |
| 6540 | } |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6541 | case SyncEventState::MissingSetEvent: { |
| 6542 | // TODO: There are conditions at queue submit time where we can definitively say that |
| 6543 | // a missing set event is an error. Add those if not captured in CoreChecks |
| 6544 | break; |
| 6545 | } |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6546 | default: |
| 6547 | assert(ignore_reason == SyncEventState::NotIgnored); |
| 6548 | } |
| 6549 | } else if (barrier_set.image_memory_barriers.size()) { |
| 6550 | const auto &image_memory_barriers = barrier_set.image_memory_barriers; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6551 | const auto *context = exec_context.GetCurrentAccessContext(); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6552 | assert(context); |
| 6553 | for (const auto &image_memory_barrier : image_memory_barriers) { |
| 6554 | if (image_memory_barrier.old_layout == image_memory_barrier.new_layout) continue; |
| 6555 | const auto *image_state = image_memory_barrier.image.get(); |
| 6556 | if (!image_state) continue; |
| 6557 | const auto &subresource_range = image_memory_barrier.range; |
| 6558 | const auto &src_access_scope = image_memory_barrier.barrier.src_access_scope; |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6559 | const auto hazard = context->DetectImageBarrierHazard(*image_state, subresource_range, sync_event->scope.exec_scope, |
| 6560 | src_access_scope, queue_id, *sync_event, |
| 6561 | AccessContext::DetectOptions::kDetectAll); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6562 | if (hazard.hazard) { |
| 6563 | skip |= sync_state.LogError(image_state->image(), string_SyncHazardVUID(hazard.hazard), |
| 6564 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 6565 | string_SyncHazard(hazard.hazard), image_memory_barrier.index, |
| 6566 | sync_state.report_data->FormatHandle(image_state->image()).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6567 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6568 | break; |
| 6569 | } |
| 6570 | } |
| 6571 | } |
| 6572 | // TODO: Add infrastructure for checking pDependencyInfo's vs. CmdSetEvent2 VUID - vkCmdWaitEvents2KHR - pEvents - |
| 6573 | // 03839 |
| 6574 | barrier_set_index += barrier_set_incr; |
| 6575 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6576 | |
| 6577 | // 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] | 6578 | 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] | 6579 | if (extra_stage_bits) { |
| 6580 | // 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] | 6581 | // NOTE: This isn't exactly the right VUID for WaitEvents2, but it's as close as we currently have support for |
| 6582 | const char *const vuid = |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6583 | (CMD_WAITEVENTS == cmd_type_) ? "VUID-vkCmdWaitEvents-srcStageMask-01158" : "VUID-vkCmdWaitEvents2-pEvents-03838"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6584 | const char *const message = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6585 | "%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] | 6586 | const auto handle = exec_context.Handle(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6587 | if (events_not_found) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6588 | skip |= sync_state.LogInfo(handle, vuid, message, CmdName(), barrier_mask_params, |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6589 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6590 | " vkCmdSetEvent may be in previously submitted command buffer."); |
| 6591 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6592 | skip |= sync_state.LogError(handle, vuid, message, CmdName(), barrier_mask_params, |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6593 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), ""); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6594 | } |
| 6595 | } |
| 6596 | return skip; |
| 6597 | } |
| 6598 | |
| 6599 | struct SyncOpWaitEventsFunctorFactory { |
| 6600 | using BarrierOpFunctor = WaitEventBarrierOp; |
| 6601 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 6602 | using GlobalBarrierOpFunctor = WaitEventBarrierOp; |
| 6603 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 6604 | using BufferRange = EventSimpleRangeGenerator; |
| 6605 | using ImageRange = EventImageRangeGenerator; |
| 6606 | using GlobalRange = EventSimpleRangeGenerator; |
| 6607 | |
| 6608 | // Need to restrict to only valid exec and access scope for this event |
| 6609 | // Pass by value is intentional to get a copy we can change without modifying the passed barrier |
| 6610 | SyncBarrier RestrictToEvent(SyncBarrier barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 6611 | 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] | 6612 | barrier.src_access_scope = sync_event->scope.valid_accesses & barrier.src_access_scope; |
| 6613 | return barrier; |
| 6614 | } |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6615 | ApplyFunctor MakeApplyFunctor(QueueId queue_id, const SyncBarrier &barrier_arg, bool layout_transition) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6616 | auto barrier = RestrictToEvent(barrier_arg); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6617 | return ApplyFunctor(BarrierOpFunctor(queue_id, sync_event->first_scope_tag, barrier, layout_transition)); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6618 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 6619 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6620 | return GlobalApplyFunctor(false /* don't resolve */, size_hint, tag); |
| 6621 | } |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6622 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const QueueId queue_id, const SyncBarrier &barrier_arg) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6623 | auto barrier = RestrictToEvent(barrier_arg); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6624 | return GlobalBarrierOpFunctor(queue_id, sync_event->first_scope_tag, barrier, false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6625 | } |
| 6626 | |
| 6627 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range_arg) const { |
| 6628 | const AccessAddressType address_type = GetAccessAddressType(buffer); |
| 6629 | const auto base_address = ResourceBaseAddress(buffer); |
| 6630 | ResourceAccessRange range = SimpleBinding(buffer) ? (range_arg + base_address) : ResourceAccessRange(); |
| 6631 | EventSimpleRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), range); |
| 6632 | return filtered_range_gen; |
| 6633 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 6634 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6635 | if (!SimpleBinding(image)) return ImageRange(); |
| 6636 | const auto address_type = GetAccessAddressType(image); |
| 6637 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 6638 | subresource_adapter::ImageRangeGenerator image_range_gen(*image.fragment_encoder.get(), subresource_range, base_address, |
| 6639 | false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6640 | EventImageRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), image_range_gen); |
| 6641 | |
| 6642 | return filtered_range_gen; |
| 6643 | } |
| 6644 | GlobalRange MakeGlobalRangeGen(AccessAddressType address_type) const { |
| 6645 | return EventSimpleRangeGenerator(sync_event->FirstScope(address_type), kFullRange); |
| 6646 | } |
| 6647 | SyncOpWaitEventsFunctorFactory(SyncEventState *sync_event_) : sync_event(sync_event_) { assert(sync_event); } |
| 6648 | SyncEventState *sync_event; |
| 6649 | }; |
| 6650 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6651 | ResourceUsageTag SyncOpWaitEvents::Record(CommandBufferAccessContext *cb_context) const { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6652 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6653 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6654 | const QueueId queue_id = cb_context->GetQueueId(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6655 | assert(access_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6656 | if (!access_context) return tag; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6657 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 6658 | assert(events_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6659 | if (!events_context) return tag; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6660 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6661 | ReplayRecord(queue_id, tag, access_context, events_context); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6662 | return tag; |
| 6663 | } |
| 6664 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6665 | void SyncOpWaitEvents::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
| 6666 | SyncEventsContext *events_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6667 | // Unlike PipelineBarrier, WaitEvent is *not* limited to accesses within the current subpass (if any) and thus needs to import |
| 6668 | // all accesses. Can instead import for all first_scopes, or a union of them, if this becomes a performance/memory issue, |
| 6669 | // but with no idea of the performance of the union, nor of whether it even matters... take the simplest approach here, |
| 6670 | access_context->ResolvePreviousAccesses(); |
| 6671 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6672 | size_t barrier_set_index = 0; |
| 6673 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 6674 | assert(barriers_.size() == 1 || (barriers_.size() == events_.size())); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6675 | for (auto &event_shared : events_) { |
| 6676 | if (!event_shared.get()) continue; |
| 6677 | auto *sync_event = events_context->GetFromShared(event_shared); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6678 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6679 | sync_event->last_command = cmd_type_; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6680 | sync_event->last_command_tag = tag; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6681 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6682 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6683 | const auto &dst = barrier_set.dst_exec_scope; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6684 | if (!sync_event->IsIgnoredByWait(cmd_type_, barrier_set.src_exec_scope.mask_param)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6685 | // These apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 6686 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 6687 | // of the barriers is maintained. |
| 6688 | SyncOpWaitEventsFunctorFactory factory(sync_event); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6689 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, queue_id, tag, access_context); |
| 6690 | ApplyBarriers(barrier_set.image_memory_barriers, factory, queue_id, tag, access_context); |
| 6691 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, queue_id, tag, access_context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6692 | |
| 6693 | // Apply the global barrier to the event itself (for race condition tracking) |
| 6694 | // Events don't happen at a stage, so we need to store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 6695 | sync_event->barriers = dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 6696 | sync_event->barriers |= dst.exec_scope; |
| 6697 | } else { |
| 6698 | // We ignored this wait, so we don't have any effective synchronization barriers for it. |
| 6699 | sync_event->barriers = 0U; |
| 6700 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6701 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6702 | } |
| 6703 | |
| 6704 | // Apply the pending barriers |
| 6705 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
| 6706 | access_context->ApplyToContext(apply_pending_action); |
| 6707 | } |
| 6708 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6709 | bool SyncOpWaitEvents::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6710 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
| 6711 | return DoValidate(*exec_context, base_tag); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6712 | } |
| 6713 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6714 | bool SyncValidator::PreCallValidateCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 6715 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 6716 | bool skip = false; |
| 6717 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 6718 | assert(cb_access_context); |
| 6719 | if (!cb_access_context) return skip; |
| 6720 | |
| 6721 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 6722 | assert(context); |
| 6723 | if (!context) return skip; |
| 6724 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6725 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6726 | |
| 6727 | if (dst_buffer) { |
| 6728 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 6729 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
| 6730 | if (hazard.hazard) { |
| 6731 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 6732 | "vkCmdWriteBufferMarkerAMD2: Hazard %s for dstBuffer %s. Access info %s.", |
| 6733 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6734 | cb_access_context->FormatHazard(hazard).c_str()); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6735 | } |
| 6736 | } |
| 6737 | return skip; |
| 6738 | } |
| 6739 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6740 | 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] | 6741 | events_.reserve(event_count); |
| 6742 | for (uint32_t event_index = 0; event_index < event_count; event_index++) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6743 | events_.emplace_back(sync_state.Get<EVENT_STATE>(events[event_index])); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6744 | } |
| 6745 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6746 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6747 | SyncOpResetEvent::SyncOpResetEvent(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6748 | VkPipelineStageFlags2KHR stageMask) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6749 | : SyncOpBase(cmd_type), |
| 6750 | event_(sync_state.Get<EVENT_STATE>(event)), |
| 6751 | exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6752 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6753 | bool SyncOpResetEvent::Validate(const CommandBufferAccessContext& cb_context) const { |
| 6754 | return DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6755 | } |
| 6756 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6757 | bool SyncOpResetEvent::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
| 6758 | auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6759 | assert(events_context); |
| 6760 | bool skip = false; |
| 6761 | if (!events_context) return skip; |
| 6762 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6763 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6764 | const auto *sync_event = events_context->Get(event_); |
| 6765 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 6766 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6767 | if (sync_event->last_command_tag > base_tag) return skip; // if we validated this in recording of the secondary, don't repeat |
| 6768 | |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6769 | const char *const set_wait = |
| 6770 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 6771 | "hazards."; |
| 6772 | const char *message = set_wait; // Only one message this call. |
| 6773 | if (!sync_event->HasBarrier(exec_scope_.mask_param, exec_scope_.exec_scope)) { |
| 6774 | const char *vuid = nullptr; |
| 6775 | switch (sync_event->last_command) { |
| 6776 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6777 | case CMD_SETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6778 | case CMD_SETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6779 | // Needs a barrier between set and reset |
| 6780 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-set"; |
| 6781 | break; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6782 | case CMD_WAITEVENTS: |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 6783 | case CMD_WAITEVENTS2: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6784 | case CMD_WAITEVENTS2KHR: { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6785 | // Needs to be in the barriers chain (either because of a barrier, or because of dstStageMask |
| 6786 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-wait"; |
| 6787 | break; |
| 6788 | } |
| 6789 | default: |
| 6790 | // The only other valid last command that wasn't one. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6791 | assert((sync_event->last_command == CMD_NONE) || (sync_event->last_command == CMD_RESETEVENT) || |
| 6792 | (sync_event->last_command == CMD_RESETEVENT2KHR)); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6793 | break; |
| 6794 | } |
| 6795 | if (vuid) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6796 | skip |= sync_state.LogError(event_->event(), vuid, message, CmdName(), |
| 6797 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6798 | CommandTypeString(sync_event->last_command)); |
| 6799 | } |
| 6800 | } |
| 6801 | return skip; |
| 6802 | } |
| 6803 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6804 | ResourceUsageTag SyncOpResetEvent::Record(CommandBufferAccessContext *cb_context) const { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6805 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6806 | auto *events_context = cb_context->GetCurrentEventsContext(); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6807 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 6808 | const QueueId queue_id = cb_context->GetQueueId(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6809 | assert(events_context); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6810 | if (access_context && events_context) { |
| 6811 | ReplayRecord(queue_id, tag, access_context, events_context); |
| 6812 | } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6813 | return tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6814 | } |
| 6815 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6816 | bool SyncOpResetEvent::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6817 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
| 6818 | return DoValidate(*exec_context, base_tag); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6819 | } |
| 6820 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6821 | void SyncOpResetEvent::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6822 | SyncEventsContext *events_context) const { |
| 6823 | auto *sync_event = events_context->GetFromShared(event_); |
| 6824 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 6825 | |
| 6826 | // Update the event state |
| 6827 | sync_event->last_command = cmd_type_; |
| 6828 | sync_event->last_command_tag = tag; |
| 6829 | sync_event->unsynchronized_set = CMD_NONE; |
| 6830 | sync_event->ResetFirstScope(); |
| 6831 | sync_event->barriers = 0U; |
| 6832 | } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6833 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6834 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6835 | VkPipelineStageFlags2KHR stageMask, const AccessContext *access_context) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6836 | : SyncOpBase(cmd_type), |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6837 | event_(sync_state.Get<EVENT_STATE>(event)), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6838 | recorded_context_(), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6839 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6840 | dep_info_() { |
| 6841 | // Snapshot the current access_context for later inspection at wait time. |
| 6842 | // NOTE: This appears brute force, but given that we only save a "first-last" model of access history, the current |
| 6843 | // access context (include barrier state for chaining) won't necessarily contain the needed information at Wait |
| 6844 | // or Submit time reference. |
| 6845 | if (access_context) { |
| 6846 | recorded_context_ = std::make_shared<const AccessContext>(*access_context); |
| 6847 | } |
| 6848 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6849 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6850 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6851 | const VkDependencyInfoKHR &dep_info, const AccessContext *access_context) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6852 | : SyncOpBase(cmd_type), |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6853 | event_(sync_state.Get<EVENT_STATE>(event)), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6854 | recorded_context_(), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6855 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, sync_utils::GetGlobalStageMasks(dep_info).src)), |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6856 | dep_info_(new safe_VkDependencyInfo(&dep_info)) { |
| 6857 | if (access_context) { |
| 6858 | recorded_context_ = std::make_shared<const AccessContext>(*access_context); |
| 6859 | } |
| 6860 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6861 | |
| 6862 | bool SyncOpSetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6863 | return DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6864 | } |
| 6865 | bool SyncOpSetEvent::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6866 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
| 6867 | assert(exec_context); |
| 6868 | return DoValidate(*exec_context, base_tag); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6869 | } |
| 6870 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6871 | bool SyncOpSetEvent::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6872 | bool skip = false; |
| 6873 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6874 | const auto &sync_state = exec_context.GetSyncState(); |
| 6875 | auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6876 | assert(events_context); |
| 6877 | if (!events_context) return skip; |
| 6878 | |
| 6879 | const auto *sync_event = events_context->Get(event_); |
| 6880 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 6881 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6882 | if (sync_event->last_command_tag >= base_tag) return skip; // for replay we don't want to revalidate internal "last commmand" |
| 6883 | |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6884 | const char *const reset_set = |
| 6885 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 6886 | "hazards."; |
| 6887 | const char *const wait = |
| 6888 | "%s: %s %s operation following %s without intervening vkCmdResetEvent, may result in data hazard and is ignored."; |
| 6889 | |
| 6890 | 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] | 6891 | const char *vuid_stem = nullptr; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6892 | const char *message = nullptr; |
| 6893 | switch (sync_event->last_command) { |
| 6894 | case CMD_RESETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6895 | case CMD_RESETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6896 | case CMD_RESETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6897 | // Needs a barrier between reset and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6898 | vuid_stem = "-missingbarrier-reset"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6899 | message = reset_set; |
| 6900 | break; |
| 6901 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6902 | case CMD_SETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6903 | case CMD_SETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6904 | // Needs a barrier between set and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6905 | vuid_stem = "-missingbarrier-set"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6906 | message = reset_set; |
| 6907 | break; |
| 6908 | case CMD_WAITEVENTS: |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 6909 | case CMD_WAITEVENTS2: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6910 | case CMD_WAITEVENTS2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6911 | // Needs a barrier or is in second execution scope |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6912 | vuid_stem = "-missingbarrier-wait"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6913 | message = wait; |
| 6914 | break; |
| 6915 | default: |
| 6916 | // The only other valid last command that wasn't one. |
| 6917 | assert(sync_event->last_command == CMD_NONE); |
| 6918 | break; |
| 6919 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6920 | if (vuid_stem) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6921 | assert(nullptr != message); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6922 | std::string vuid("SYNC-"); |
| 6923 | vuid.append(CmdName()).append(vuid_stem); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6924 | skip |= sync_state.LogError(event_->event(), vuid.c_str(), message, CmdName(), |
| 6925 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6926 | CommandTypeString(sync_event->last_command)); |
| 6927 | } |
| 6928 | } |
| 6929 | |
| 6930 | return skip; |
| 6931 | } |
| 6932 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6933 | ResourceUsageTag SyncOpSetEvent::Record(CommandBufferAccessContext *cb_context) const { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6934 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6935 | auto *events_context = cb_context->GetCurrentEventsContext(); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6936 | const QueueId queue_id = cb_context->GetQueueId(); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6937 | assert(recorded_context_); |
| 6938 | if (recorded_context_ && events_context) { |
| 6939 | DoRecord(queue_id, tag, recorded_context_, events_context); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6940 | } |
| 6941 | return tag; |
| 6942 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6943 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6944 | void SyncOpSetEvent::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
| 6945 | SyncEventsContext *events_context) const { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6946 | // Create a copy of the current context, and merge in the state snapshot at record set event time |
| 6947 | // Note: we mustn't change the recorded context copy, as a given CB could be submitted more than once (in generaL) |
| 6948 | auto merged_context = std::make_shared<AccessContext>(*access_context); |
| 6949 | merged_context->ResolveFromContext(QueueTagOffsetBarrierAction(queue_id, tag), *recorded_context_); |
| 6950 | DoRecord(queue_id, tag, merged_context, events_context); |
| 6951 | } |
| 6952 | |
| 6953 | void SyncOpSetEvent::DoRecord(QueueId queue_id, ResourceUsageTag tag, const std::shared_ptr<const AccessContext> &access_context, |
| 6954 | SyncEventsContext *events_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6955 | auto *sync_event = events_context->GetFromShared(event_); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6956 | 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] | 6957 | |
| 6958 | // NOTE: We're going to simply record the sync scope here, as anything else would be implementation defined/undefined |
| 6959 | // and we're issuing errors re: missing barriers between event commands, which if the user fixes would fix |
| 6960 | // any issues caused by naive scope setting here. |
| 6961 | |
| 6962 | // What happens with two SetEvent is that one cannot know what group of operations will be waited for. |
| 6963 | // Given: |
| 6964 | // Stuff1; SetEvent; Stuff2; SetEvent; WaitEvents; |
| 6965 | // WaitEvents cannot know which of Stuff1, Stuff2, or both has completed execution. |
| 6966 | |
| 6967 | if (!sync_event->HasBarrier(src_exec_scope_.mask_param, src_exec_scope_.exec_scope)) { |
| 6968 | sync_event->unsynchronized_set = sync_event->last_command; |
| 6969 | sync_event->ResetFirstScope(); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6970 | } else if (!sync_event->first_scope) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6971 | // We only set the scope if there isn't one |
| 6972 | sync_event->scope = src_exec_scope_; |
| 6973 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 6974 | // Save the shared_ptr to copy of the access_context present at set time (sent us by the caller) |
| 6975 | sync_event->first_scope = access_context; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6976 | sync_event->unsynchronized_set = CMD_NONE; |
| 6977 | sync_event->first_scope_tag = tag; |
| 6978 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6979 | // TODO: Store dep_info_ shared ptr in sync_state for WaitEvents2 validation |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6980 | sync_event->last_command = cmd_type_; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6981 | sync_event->last_command_tag = tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6982 | sync_event->barriers = 0U; |
| 6983 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6984 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6985 | SyncOpBeginRenderPass::SyncOpBeginRenderPass(CMD_TYPE cmd_type, const SyncValidator &sync_state, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6986 | const VkRenderPassBeginInfo *pRenderPassBegin, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 6987 | const VkSubpassBeginInfo *pSubpassBeginInfo) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6988 | : SyncOpBase(cmd_type) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6989 | if (pRenderPassBegin) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6990 | rp_state_ = sync_state.Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6991 | renderpass_begin_info_ = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6992 | auto fb_state = sync_state.Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6993 | if (fb_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6994 | shared_attachments_ = sync_state.GetAttachmentViews(*renderpass_begin_info_.ptr(), *fb_state); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6995 | // TODO: Revisit this when all attachment validation is through SyncOps to see if we can discard the plain pointer copy |
| 6996 | // Note that this a safe to presist as long as shared_attachments is not cleared |
| 6997 | attachments_.reserve(shared_attachments_.size()); |
sfricke-samsung | 01c9ae9 | 2021-02-09 22:30:52 -0800 | [diff] [blame] | 6998 | for (const auto &attachment : shared_attachments_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6999 | attachments_.emplace_back(attachment.get()); |
| 7000 | } |
| 7001 | } |
| 7002 | if (pSubpassBeginInfo) { |
| 7003 | subpass_begin_info_ = safe_VkSubpassBeginInfo(pSubpassBeginInfo); |
| 7004 | } |
| 7005 | } |
| 7006 | } |
| 7007 | |
| 7008 | bool SyncOpBeginRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 7009 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 7010 | bool skip = false; |
| 7011 | |
| 7012 | assert(rp_state_.get()); |
| 7013 | if (nullptr == rp_state_.get()) return skip; |
| 7014 | auto &rp_state = *rp_state_.get(); |
| 7015 | |
| 7016 | const uint32_t subpass = 0; |
| 7017 | |
| 7018 | // Construct the state we can use to validate against... (since validation is const and RecordCmdBeginRenderPass |
| 7019 | // hasn't happened yet) |
| 7020 | const std::vector<AccessContext> empty_context_vector; |
| 7021 | AccessContext temp_context(subpass, cb_context.GetQueueFlags(), rp_state.subpass_dependencies, empty_context_vector, |
| 7022 | cb_context.GetCurrentAccessContext()); |
| 7023 | |
| 7024 | // Validate attachment operations |
| 7025 | if (attachments_.size() == 0) return skip; |
| 7026 | const auto &render_area = renderpass_begin_info_.renderArea; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7027 | |
| 7028 | // Since the isn't a valid RenderPassAccessContext until Record, needs to create the view/generator list... we could limit this |
| 7029 | // by predicating on whether subpass 0 uses the attachment if it is too expensive to create the full list redundantly here. |
| 7030 | // More broadly we could look at thread specific state shared between Validate and Record as is done for other heavyweight |
| 7031 | // operations (though it's currently a messy approach) |
| 7032 | AttachmentViewGenVector view_gens = RenderPassAccessContext::CreateAttachmentViewGen(render_area, attachments_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7033 | skip |= temp_context.ValidateLayoutTransitions(cb_context, rp_state, render_area, subpass, view_gens, cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7034 | |
| 7035 | // Validate load operations if there were no layout transition hazards |
| 7036 | if (!skip) { |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 7037 | temp_context.RecordLayoutTransitions(rp_state, subpass, view_gens, kInvalidTag); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7038 | skip |= temp_context.ValidateLoadOperation(cb_context, rp_state, render_area, subpass, view_gens, cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7039 | } |
| 7040 | |
| 7041 | return skip; |
| 7042 | } |
| 7043 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7044 | ResourceUsageTag SyncOpBeginRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7045 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 7046 | assert(rp_state_.get()); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7047 | if (nullptr == rp_state_.get()) return cb_context->NextCommandTag(cmd_type_); |
| 7048 | return cb_context->RecordBeginRenderPass(cmd_type_, *rp_state_.get(), renderpass_begin_info_.renderArea, attachments_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7049 | } |
| 7050 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7051 | bool SyncOpBeginRenderPass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 7052 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7053 | return false; |
| 7054 | } |
| 7055 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7056 | void SyncOpBeginRenderPass::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 7057 | SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7058 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7059 | SyncOpNextSubpass::SyncOpNextSubpass(CMD_TYPE cmd_type, const SyncValidator &sync_state, |
| 7060 | const VkSubpassBeginInfo *pSubpassBeginInfo, const VkSubpassEndInfo *pSubpassEndInfo) |
| 7061 | : SyncOpBase(cmd_type) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7062 | if (pSubpassBeginInfo) { |
| 7063 | subpass_begin_info_.initialize(pSubpassBeginInfo); |
| 7064 | } |
| 7065 | if (pSubpassEndInfo) { |
| 7066 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 7067 | } |
| 7068 | } |
| 7069 | |
| 7070 | bool SyncOpNextSubpass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 7071 | bool skip = false; |
| 7072 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 7073 | if (!renderpass_context) return skip; |
| 7074 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7075 | skip |= renderpass_context->ValidateNextSubpass(cb_context.GetExecutionContext(), cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7076 | return skip; |
| 7077 | } |
| 7078 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7079 | ResourceUsageTag SyncOpNextSubpass::Record(CommandBufferAccessContext *cb_context) const { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7080 | return cb_context->RecordNextSubpass(cmd_type_); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7081 | } |
| 7082 | |
| 7083 | bool SyncOpNextSubpass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 7084 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7085 | return false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7086 | } |
| 7087 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7088 | SyncOpEndRenderPass::SyncOpEndRenderPass(CMD_TYPE cmd_type, const SyncValidator &sync_state, |
| 7089 | const VkSubpassEndInfo *pSubpassEndInfo) |
| 7090 | : SyncOpBase(cmd_type) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7091 | if (pSubpassEndInfo) { |
| 7092 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 7093 | } |
| 7094 | } |
| 7095 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7096 | void SyncOpNextSubpass::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
| 7097 | SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7098 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7099 | bool SyncOpEndRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 7100 | bool skip = false; |
| 7101 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 7102 | |
| 7103 | if (!renderpass_context) return skip; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7104 | skip |= renderpass_context->ValidateEndRenderPass(cb_context.GetExecutionContext(), cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7105 | return skip; |
| 7106 | } |
| 7107 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7108 | ResourceUsageTag SyncOpEndRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7109 | return cb_context->RecordEndRenderPass(cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 7110 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 7111 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7112 | bool SyncOpEndRenderPass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 7113 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7114 | return false; |
| 7115 | } |
| 7116 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7117 | void SyncOpEndRenderPass::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 7118 | SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7119 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 7120 | void SyncValidator::PreCallRecordCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 7121 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
| 7122 | StateTracker::PreCallRecordCmdWriteBufferMarker2AMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
| 7123 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 7124 | assert(cb_access_context); |
| 7125 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 7126 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 7127 | assert(context); |
| 7128 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 7129 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 7130 | |
| 7131 | if (dst_buffer) { |
| 7132 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 7133 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
| 7134 | } |
| 7135 | } |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 7136 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7137 | bool SyncValidator::PreCallValidateCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 7138 | const VkCommandBuffer *pCommandBuffers) const { |
| 7139 | bool skip = StateTracker::PreCallValidateCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7140 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 7141 | assert(cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7142 | |
| 7143 | // Heavyweight, but we need a proxy copy of the active command buffer access context |
| 7144 | CommandBufferAccessContext proxy_cb_context(*cb_context, CommandBufferAccessContext::AsProxyContext()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7145 | |
| 7146 | // Make working copies of the access and events contexts |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7147 | for (uint32_t cb_index = 0; cb_index < commandBufferCount; ++cb_index) { |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 7148 | proxy_cb_context.NextIndexedCommandTag(CMD_EXECUTECOMMANDS, cb_index); |
| 7149 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7150 | const auto *recorded_cb_context = GetAccessContext(pCommandBuffers[cb_index]); |
| 7151 | if (!recorded_cb_context) continue; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7152 | |
| 7153 | const auto *recorded_context = recorded_cb_context->GetCurrentAccessContext(); |
| 7154 | assert(recorded_context); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7155 | skip |= recorded_cb_context->ValidateFirstUse(&proxy_cb_context, "vkCmdExecuteCommands", cb_index); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7156 | |
| 7157 | // The barriers have already been applied in ValidatFirstUse |
| 7158 | ResourceUsageRange tag_range = proxy_cb_context.ImportRecordedAccessLog(*recorded_cb_context); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7159 | proxy_cb_context.ResolveExecutedCommandBuffer(*recorded_context, tag_range.begin); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7160 | } |
| 7161 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7162 | return skip; |
| 7163 | } |
| 7164 | |
| 7165 | void SyncValidator::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 7166 | const VkCommandBuffer *pCommandBuffers) { |
| 7167 | StateTracker::PreCallRecordCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7168 | auto *cb_context = GetAccessContext(commandBuffer); |
| 7169 | assert(cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7170 | for (uint32_t cb_index = 0; cb_index < commandBufferCount; ++cb_index) { |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 7171 | cb_context->NextIndexedCommandTag(CMD_EXECUTECOMMANDS, cb_index); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7172 | const auto *recorded_cb_context = GetAccessContext(pCommandBuffers[cb_index]); |
| 7173 | if (!recorded_cb_context) continue; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7174 | cb_context->RecordExecutedCommandBuffer(*recorded_cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7175 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7176 | } |
| 7177 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7178 | void SyncValidator::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) { |
| 7179 | StateTracker::PostCallRecordQueueWaitIdle(queue, result); |
| 7180 | if ((result != VK_SUCCESS) || (!enabled[sync_validation_queue_submit]) || (queue == VK_NULL_HANDLE)) return; |
| 7181 | |
| 7182 | const auto queue_state = GetQueueSyncStateShared(queue); |
| 7183 | if (!queue_state) return; // Invalid queue |
| 7184 | QueueId waited_queue = queue_state->GetQueueId(); |
| 7185 | |
| 7186 | // We need to go through every queue batch context and clear all accesses this wait synchronizes |
| 7187 | // As usual -- two groups, the "last batch" and the signaled semaphores |
| 7188 | // NOTE: Since ApplyTaggedWait crawls through every usage in every ResourceAccessState in the AccessContext of *every* |
| 7189 | // QueueBatchContext, track which we've done to avoid duplicate traversals |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7190 | QueueBatchContext::BatchSet queue_batch_contexts = GetQueueBatchSnapshot(); |
| 7191 | for (auto &batch : queue_batch_contexts) { |
| 7192 | batch->ApplyTaggedWait(waited_queue, ResourceUsageRecord::kMaxIndex); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7193 | } |
| 7194 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7195 | // TODO: Fences affected by Wait |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7196 | } |
| 7197 | |
| 7198 | void SyncValidator::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) { |
| 7199 | StateTracker::PostCallRecordDeviceWaitIdle(device, result); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7200 | |
| 7201 | QueueBatchContext::BatchSet queue_batch_contexts = GetQueueBatchSnapshot(); |
| 7202 | for (auto &batch : queue_batch_contexts) { |
| 7203 | batch->ApplyDeviceWait(); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7204 | } |
| 7205 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7206 | // TODO: Update Fences affected by Wait |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7207 | } |
| 7208 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7209 | struct QueueSubmitCmdState { |
| 7210 | std::shared_ptr<const QueueSyncState> queue; |
| 7211 | std::shared_ptr<QueueBatchContext> last_batch; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7212 | AccessLogger logger; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7213 | SignaledSemaphores signaled; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7214 | QueueSubmitCmdState(const AccessLogger &parent_log, const SignaledSemaphores &parent_semaphores) |
| 7215 | : logger(&parent_log), signaled(parent_semaphores) {} |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7216 | }; |
| 7217 | |
| 7218 | template <> |
| 7219 | thread_local layer_data::optional<QueueSubmitCmdState> layer_data::TlsGuard<QueueSubmitCmdState>::payload_{}; |
| 7220 | |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7221 | bool SyncValidator::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, |
| 7222 | VkFence fence) const { |
| 7223 | bool skip = false; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7224 | |
| 7225 | // Since this early return is above the TlsGuard, the Record phase must also be. |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7226 | if (!enabled[sync_validation_queue_submit]) return skip; |
| 7227 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7228 | layer_data::TlsGuard<QueueSubmitCmdState> cmd_state(&skip, global_access_log_, signaled_semaphores_); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7229 | const auto fence_state = Get<FENCE_STATE>(fence); |
| 7230 | cmd_state->queue = GetQueueSyncStateShared(queue); |
| 7231 | if (!cmd_state->queue) return skip; // Invalid Queue |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7232 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7233 | // The submit id is a mutable automic which is not recoverable on a skip == true condition |
| 7234 | uint64_t submit_id = cmd_state->queue->ReserveSubmitId(); |
| 7235 | |
| 7236 | // verify each submit batch |
| 7237 | // Since the last batch from the queue state is const, we need to track the last_batch separately from the |
| 7238 | // most recently created batch |
| 7239 | std::shared_ptr<const QueueBatchContext> last_batch = cmd_state->queue->LastBatch(); |
| 7240 | std::shared_ptr<QueueBatchContext> batch; |
| 7241 | for (uint32_t batch_idx = 0; batch_idx < submitCount; batch_idx++) { |
| 7242 | const VkSubmitInfo &submit = pSubmits[batch_idx]; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7243 | batch = std::make_shared<QueueBatchContext>(*this, *cmd_state->queue); |
| 7244 | batch->Setup(last_batch, submit, cmd_state->signaled); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7245 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7246 | // Skip import and validation of empty batches |
| 7247 | if (batch->GetTagRange().size()) { |
| 7248 | batch->SetBatchLog(cmd_state->logger, submit_id, batch_idx); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7249 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7250 | // For each submit in the batch... |
| 7251 | for (const auto &cb : *batch) { |
| 7252 | if (cb.cb->GetTagLimit() == 0) continue; // Skip empty CB's |
| 7253 | skip |= cb.cb->ValidateFirstUse(batch.get(), "vkQueueSubmit", cb.index); |
| 7254 | |
| 7255 | // The barriers have already been applied in ValidatFirstUse |
| 7256 | ResourceUsageRange tag_range = batch->ImportRecordedAccessLog(*cb.cb); |
| 7257 | batch->ResolveSubmittedCommandBuffer(*cb.cb->GetCurrentAccessContext(), tag_range.begin); |
| 7258 | } |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7259 | } |
| 7260 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7261 | // Empty batches could have semaphores, though. |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7262 | for (auto &sem : layer_data::make_span(submit.pSignalSemaphores, submit.signalSemaphoreCount)) { |
| 7263 | // Make a copy of the state, signal the copy and pend it... |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7264 | auto sem_state = Get<SEMAPHORE_STATE>(sem); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7265 | if (!sem_state) continue; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7266 | auto semaphore_info = lvl_init_struct<VkSemaphoreSubmitInfo>(); |
| 7267 | semaphore_info.stageMask = VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT; |
| 7268 | cmd_state->signaled.SignalSemaphore(sem_state, batch, semaphore_info); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7269 | } |
| 7270 | // Unless the previous batch was referenced by a signal, the QueueBatchContext will self destruct, but as |
| 7271 | // we ResolvePrevious as we can let any contexts we've fully referenced go. |
| 7272 | last_batch = batch; |
| 7273 | } |
| 7274 | // The most recently created batch will become the queue's "last batch" in the record phase |
| 7275 | if (batch) { |
| 7276 | cmd_state->last_batch = std::move(batch); |
| 7277 | } |
| 7278 | |
| 7279 | // Note that if we skip, guard cleans up for us, but cannot release the reserved tag range |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7280 | return skip; |
| 7281 | } |
| 7282 | |
| 7283 | void SyncValidator::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence, |
| 7284 | VkResult result) { |
| 7285 | StateTracker::PostCallRecordQueueSubmit(queue, submitCount, pSubmits, fence, result); |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7286 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7287 | // If this return is above the TlsGuard, then the Validate phase return must also be. |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7288 | if (!enabled[sync_validation_queue_submit]) return; // Queue submit validation must be affirmatively enabled |
| 7289 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7290 | // The earliest return (when enabled), must be *after* the TlsGuard, as it is the TlsGuard that cleans up the cmd_state |
| 7291 | // static payload |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7292 | layer_data::TlsGuard<QueueSubmitCmdState> cmd_state; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7293 | |
| 7294 | if (VK_SUCCESS != result) return; // dispatched QueueSubmit failed |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7295 | if (!cmd_state->queue) return; // Validation couldn't find a valid queue object |
| 7296 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7297 | // Don't need to look up the queue state again, but we need a non-const version |
| 7298 | std::shared_ptr<QueueSyncState> queue_state = std::const_pointer_cast<QueueSyncState>(std::move(cmd_state->queue)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7299 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7300 | // The global the semaphores we applied to the cmd_state QueueBatchContexts |
| 7301 | // NOTE: All conserved QueueBatchContext's need to have there access logs reset to use the global logger and the only conserved |
| 7302 | // QBC's are those referenced by unwaited signals and the last batch. |
| 7303 | for (auto &sig_sem : cmd_state->signaled) { |
| 7304 | if (sig_sem.second && sig_sem.second->batch) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7305 | auto &sig_batch = sig_sem.second->batch; |
| 7306 | sig_batch->ResetAccessLog(); |
| 7307 | // Batches retained for signalled semaphore don't need to retain event data, unless it's the last batch in the submit |
| 7308 | if (sig_batch != cmd_state->last_batch) { |
| 7309 | sig_batch->ResetEventsContext(); |
| 7310 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7311 | } |
| 7312 | signaled_semaphores_.Import(sig_sem.first, std::move(sig_sem.second)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7313 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7314 | cmd_state->signaled.Reset(); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7315 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7316 | // Update the queue to point to the last batch from the submit |
| 7317 | if (cmd_state->last_batch) { |
| 7318 | cmd_state->last_batch->ResetAccessLog(); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7319 | |
| 7320 | // Clean up the events data in the previous last batch on queue, as only the subsequent batches have valid use for them |
| 7321 | // and the QueueBatchContext::Setup calls have be copying them along from batch to batch during submit. |
| 7322 | auto last_batch = queue_state->LastBatch(); |
| 7323 | if (last_batch) { |
| 7324 | last_batch->ResetEventsContext(); |
| 7325 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7326 | queue_state->SetLastBatch(std::move(cmd_state->last_batch)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7327 | } |
| 7328 | |
| 7329 | // Update the global access log from the one built during validation |
| 7330 | global_access_log_.MergeMove(std::move(cmd_state->logger)); |
| 7331 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7332 | |
| 7333 | // WIP: record information about fences |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7334 | } |
| 7335 | |
| 7336 | bool SyncValidator::PreCallValidateQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 7337 | VkFence fence) const { |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7338 | bool skip = false; |
| 7339 | if (!enabled[sync_validation_queue_submit]) return skip; |
| 7340 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7341 | // WIP: Add Submit2 support |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7342 | return skip; |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7343 | } |
| 7344 | |
| 7345 | void SyncValidator::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 7346 | VkFence fence, VkResult result) { |
| 7347 | StateTracker::PostCallRecordQueueSubmit2KHR(queue, submitCount, pSubmits, fence, result); |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7348 | if (VK_SUCCESS != result) return; // dispatched QueueSubmit2 failed |
| 7349 | |
| 7350 | if (!enabled[sync_validation_queue_submit]) return; |
| 7351 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7352 | // WIP: Add Submit2 support |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7353 | } |
| 7354 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7355 | AttachmentViewGen::AttachmentViewGen(const IMAGE_VIEW_STATE *view, const VkOffset3D &offset, const VkExtent3D &extent) |
| 7356 | : view_(view), view_mask_(), gen_store_() { |
| 7357 | if (!view_ || !view_->image_state || !SimpleBinding(*view_->image_state)) return; |
| 7358 | const IMAGE_STATE &image_state = *view_->image_state.get(); |
| 7359 | const auto base_address = ResourceBaseAddress(image_state); |
| 7360 | const auto *encoder = image_state.fragment_encoder.get(); |
| 7361 | if (!encoder) return; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 7362 | // Get offset and extent for the view, accounting for possible depth slicing |
| 7363 | const VkOffset3D zero_offset = view->GetOffset(); |
| 7364 | const VkExtent3D &image_extent = view->GetExtent(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7365 | // Intentional copy |
| 7366 | VkImageSubresourceRange subres_range = view_->normalized_subresource_range; |
| 7367 | view_mask_ = subres_range.aspectMask; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 7368 | gen_store_[Gen::kViewSubresource].emplace(*encoder, subres_range, zero_offset, image_extent, base_address, |
| 7369 | view->IsDepthSliced()); |
| 7370 | gen_store_[Gen::kRenderArea].emplace(*encoder, subres_range, offset, extent, base_address, view->IsDepthSliced()); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7371 | |
| 7372 | const auto depth = view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT; |
| 7373 | if (depth && (depth != view_mask_)) { |
| 7374 | subres_range.aspectMask = depth; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 7375 | gen_store_[Gen::kDepthOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address, view->IsDepthSliced()); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7376 | } |
| 7377 | const auto stencil = view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT; |
| 7378 | if (stencil && (stencil != view_mask_)) { |
| 7379 | subres_range.aspectMask = stencil; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 7380 | gen_store_[Gen::kStencilOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address, |
| 7381 | view->IsDepthSliced()); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7382 | } |
| 7383 | } |
| 7384 | |
| 7385 | const ImageRangeGen *AttachmentViewGen::GetRangeGen(AttachmentViewGen::Gen gen_type) const { |
| 7386 | const ImageRangeGen *got = nullptr; |
| 7387 | switch (gen_type) { |
| 7388 | case kViewSubresource: |
| 7389 | got = &gen_store_[kViewSubresource]; |
| 7390 | break; |
| 7391 | case kRenderArea: |
| 7392 | got = &gen_store_[kRenderArea]; |
| 7393 | break; |
| 7394 | case kDepthOnlyRenderArea: |
| 7395 | got = |
| 7396 | (view_mask_ == VK_IMAGE_ASPECT_DEPTH_BIT) ? &gen_store_[Gen::kRenderArea] : &gen_store_[Gen::kDepthOnlyRenderArea]; |
| 7397 | break; |
| 7398 | case kStencilOnlyRenderArea: |
| 7399 | got = (view_mask_ == VK_IMAGE_ASPECT_STENCIL_BIT) ? &gen_store_[Gen::kRenderArea] |
| 7400 | : &gen_store_[Gen::kStencilOnlyRenderArea]; |
| 7401 | break; |
| 7402 | default: |
| 7403 | assert(got); |
| 7404 | } |
| 7405 | return got; |
| 7406 | } |
| 7407 | |
| 7408 | AttachmentViewGen::Gen AttachmentViewGen::GetDepthStencilRenderAreaGenType(bool depth_op, bool stencil_op) const { |
| 7409 | assert(IsValid()); |
| 7410 | assert(view_mask_ & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); |
| 7411 | if (depth_op) { |
| 7412 | assert(view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 7413 | if (stencil_op) { |
| 7414 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 7415 | return kRenderArea; |
| 7416 | } |
| 7417 | return kDepthOnlyRenderArea; |
| 7418 | } |
| 7419 | if (stencil_op) { |
| 7420 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 7421 | return kStencilOnlyRenderArea; |
| 7422 | } |
| 7423 | |
| 7424 | assert(depth_op || stencil_op); |
| 7425 | return kRenderArea; |
| 7426 | } |
| 7427 | |
| 7428 | AccessAddressType AttachmentViewGen::GetAddressType() const { return AccessContext::ImageAddressType(*view_->image_state); } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7429 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7430 | void SyncEventsContext::ApplyBarrier(const SyncExecScope &src, const SyncExecScope &dst, ResourceUsageTag tag) { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7431 | const bool all_commands_bit = 0 != (src.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 7432 | for (auto &event_pair : map_) { |
| 7433 | assert(event_pair.second); // Shouldn't be storing empty |
| 7434 | auto &sync_event = *event_pair.second; |
| 7435 | // Events don't happen at a stage, so we need to check and store the unexpanded ALL_COMMANDS if set for inter-event-calls |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7436 | // But only if occuring before the tag |
| 7437 | if (((sync_event.barriers & src.exec_scope) || all_commands_bit) && (sync_event.last_command_tag <= tag)) { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7438 | sync_event.barriers |= dst.exec_scope; |
| 7439 | sync_event.barriers |= dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 7440 | } |
| 7441 | } |
| 7442 | } |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 7443 | |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7444 | void SyncEventsContext::ApplyTaggedWait(VkQueueFlags queue_flags, ResourceUsageTag tag) { |
| 7445 | const SyncExecScope src_scope = |
| 7446 | SyncExecScope::MakeSrc(queue_flags, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_2_HOST_BIT); |
| 7447 | const SyncExecScope dst_scope = SyncExecScope::MakeDst(queue_flags, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT); |
| 7448 | ApplyBarrier(src_scope, dst_scope, tag); |
| 7449 | } |
| 7450 | |
| 7451 | SyncEventsContext &SyncEventsContext::DeepCopy(const SyncEventsContext &from) { |
| 7452 | // We need a deep copy of the const context to update during validation phase |
| 7453 | for (const auto &event : from.map_) { |
| 7454 | map_.emplace(event.first, std::make_shared<SyncEventState>(*event.second)); |
| 7455 | } |
| 7456 | return *this; |
| 7457 | } |
| 7458 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 7459 | ReplayTrackbackBarriersAction::ReplayTrackbackBarriersAction(VkQueueFlags queue_flags, |
| 7460 | const SubpassDependencyGraphNode &subpass_dep, |
| 7461 | const std::vector<ReplayTrackbackBarriersAction> &replay_contexts) { |
| 7462 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 7463 | trackback_barriers.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
| 7464 | for (const auto &prev_dep : subpass_dep.prev) { |
| 7465 | const auto prev_pass = prev_dep.first->pass; |
| 7466 | const auto &prev_barriers = prev_dep.second; |
| 7467 | trackback_barriers.emplace_back(&replay_contexts[prev_pass], queue_flags, prev_barriers); |
| 7468 | } |
| 7469 | if (has_barrier_from_external) { |
| 7470 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 7471 | trackback_barriers.emplace_back(nullptr, queue_flags, subpass_dep.barrier_from_external); |
| 7472 | } |
| 7473 | } |
| 7474 | |
| 7475 | void ReplayTrackbackBarriersAction::operator()(ResourceAccessState *access) const { |
| 7476 | if (trackback_barriers.size() == 1) { |
| 7477 | trackback_barriers[0](access); |
| 7478 | } else { |
| 7479 | ResourceAccessState resolved; |
| 7480 | for (const auto &trackback : trackback_barriers) { |
| 7481 | ResourceAccessState access_copy = *access; |
| 7482 | trackback(&access_copy); |
| 7483 | resolved.Resolve(access_copy); |
| 7484 | } |
| 7485 | *access = resolved; |
| 7486 | } |
| 7487 | } |
| 7488 | |
| 7489 | ReplayTrackbackBarriersAction::TrackbackBarriers::TrackbackBarriers( |
| 7490 | const ReplayTrackbackBarriersAction *source_subpass_, VkQueueFlags queue_flags_, |
| 7491 | const std::vector<const VkSubpassDependency2 *> &subpass_dependencies_) |
| 7492 | : Base(source_subpass_, queue_flags_, subpass_dependencies_) {} |
| 7493 | |
| 7494 | void ReplayTrackbackBarriersAction::TrackbackBarriers::operator()(ResourceAccessState *access) const { |
| 7495 | if (source_subpass) { |
| 7496 | (*source_subpass)(access); |
| 7497 | } |
| 7498 | access->ApplyBarriersImmediate(barriers); |
| 7499 | } |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7500 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7501 | QueueBatchContext::QueueBatchContext(const SyncValidator &sync_state, const QueueSyncState &queue_state) |
| 7502 | : CommandExecutionContext(&sync_state), queue_state_(&queue_state), tag_range_(0, 0), batch_log_(nullptr) {} |
| 7503 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7504 | template <typename BatchInfo> |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7505 | void QueueBatchContext::Setup(const std::shared_ptr<const QueueBatchContext> &prev_batch, const BatchInfo &batch_info, |
| 7506 | SignaledSemaphores &signaled) { |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7507 | SetupCommandBufferInfo(batch_info); |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7508 | SetupAccessContext(prev_batch, batch_info, signaled); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7509 | } |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7510 | void QueueBatchContext::ResolveSubmittedCommandBuffer(const AccessContext &recorded_context, ResourceUsageTag offset) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7511 | GetCurrentAccessContext()->ResolveFromContext(QueueTagOffsetBarrierAction(GetQueueId(), offset), recorded_context); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7512 | } |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7513 | |
| 7514 | VulkanTypedHandle QueueBatchContext::Handle() const { return queue_state_->Handle(); } |
| 7515 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7516 | void QueueBatchContext::ApplyTaggedWait(QueueId queue_id, ResourceUsageTag tag) { |
| 7517 | QueueWaitWorm wait_worm(queue_id); |
| 7518 | access_context_.ForAll(wait_worm); |
| 7519 | if (wait_worm.erase_all) { |
| 7520 | access_context_.Reset(); |
| 7521 | } else { |
| 7522 | // TODO: Profiling will tell us if we need a more efficient clean up. |
| 7523 | for (const auto &address : wait_worm.erase_list) { |
| 7524 | access_context_.DeleteAccess(address); |
| 7525 | } |
| 7526 | } |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7527 | |
| 7528 | if (queue_id == GetQueueId()) { |
| 7529 | events_context_.ApplyTaggedWait(GetQueueFlags(), tag); |
| 7530 | } |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7531 | } |
| 7532 | |
| 7533 | // Clear all accesses |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7534 | void QueueBatchContext::ApplyDeviceWait() { |
| 7535 | access_context_.Reset(); |
| 7536 | events_context_.ApplyTaggedWait(GetQueueFlags(), ResourceUsageRecord::kMaxIndex); |
| 7537 | } |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7538 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7539 | class ApplySemaphoreBarrierAction { |
| 7540 | public: |
| 7541 | ApplySemaphoreBarrierAction(const SemaphoreScope &signal, const SemaphoreScope &wait) : signal_(signal), wait_(wait) {} |
| 7542 | void operator()(ResourceAccessState *access) const { access->ApplySemaphore(signal_, wait_); } |
| 7543 | |
| 7544 | private: |
| 7545 | const SemaphoreScope &signal_; |
| 7546 | const SemaphoreScope wait_; |
| 7547 | }; |
| 7548 | |
| 7549 | std::shared_ptr<QueueBatchContext> QueueBatchContext::ResolveOneWaitSemaphore(VkSemaphore sem, VkPipelineStageFlags2 wait_mask, |
| 7550 | SignaledSemaphores &signaled) { |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7551 | auto sem_state = sync_state_->Get<SEMAPHORE_STATE>(sem); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7552 | if (!sem_state) return nullptr; // Semaphore validity is handled by CoreChecks |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7553 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7554 | // When signal state goes out of scope, the signal information will be dropped, as Unsignal has released ownership. |
| 7555 | auto signal_state = signaled.Unsignal(sem); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7556 | if (!signal_state) return nullptr; // Invalid signal, skip it. |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7557 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7558 | assert(signal_state->batch); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7559 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7560 | const SemaphoreScope &signal_scope = signal_state->first_scope; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7561 | const auto queue_flags = queue_state_->GetQueueFlags(); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7562 | SemaphoreScope wait_scope{GetQueueId(), SyncExecScope::MakeDst(queue_flags, wait_mask)}; |
| 7563 | if (signal_scope.queue == wait_scope.queue) { |
| 7564 | // If signal queue == wait queue, signal is treated as a memory barrier with an access scope equal to the |
| 7565 | // valid accesses for the sync scope. |
| 7566 | SyncBarrier sem_barrier(signal_scope, wait_scope, SyncBarrier::AllAccess()); |
| 7567 | const BatchBarrierOp sem_barrier_op(wait_scope.queue, sem_barrier); |
| 7568 | access_context_.ResolveFromContext(sem_barrier_op, signal_state->batch->access_context_); |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7569 | events_context_.ApplyBarrier(sem_barrier.src_exec_scope, sem_barrier.dst_exec_scope, ResourceUsageRecord::kMaxIndex); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7570 | } else { |
| 7571 | ApplySemaphoreBarrierAction sem_op(signal_scope, wait_scope); |
| 7572 | access_context_.ResolveFromContext(sem_op, signal_state->batch->access_context_); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7573 | } |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7574 | // Cannot move from the signal state because it could be from the const global state, and C++ doesn't |
| 7575 | // enforce deep constness. |
| 7576 | return signal_state->batch; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7577 | } |
| 7578 | |
| 7579 | // Accessor Traits to allow Submit and Submit2 constructors to call the same utilities |
| 7580 | template <> |
| 7581 | class QueueBatchContext::SubmitInfoAccessor<VkSubmitInfo> { |
| 7582 | public: |
| 7583 | SubmitInfoAccessor(const VkSubmitInfo &info) : info_(info) {} |
| 7584 | inline uint32_t WaitSemaphoreCount() const { return info_.waitSemaphoreCount; } |
| 7585 | inline VkSemaphore WaitSemaphore(uint32_t index) { return info_.pWaitSemaphores[index]; } |
| 7586 | inline VkPipelineStageFlags2 WaitDstMask(uint32_t index) { return info_.pWaitDstStageMask[index]; } |
| 7587 | inline uint32_t CommandBufferCount() const { return info_.commandBufferCount; } |
| 7588 | inline VkCommandBuffer CommandBuffer(uint32_t index) { return info_.pCommandBuffers[index]; } |
| 7589 | |
| 7590 | private: |
| 7591 | const VkSubmitInfo &info_; |
| 7592 | }; |
| 7593 | template <typename BatchInfo, typename Fn> |
| 7594 | void QueueBatchContext::ForEachWaitSemaphore(const BatchInfo &batch_info, Fn &&func) { |
| 7595 | using Accessor = QueueBatchContext::SubmitInfoAccessor<BatchInfo>; |
| 7596 | Accessor batch(batch_info); |
| 7597 | const uint32_t wait_count = batch.WaitSemaphoreCount(); |
| 7598 | for (uint32_t i = 0; i < wait_count; ++i) { |
| 7599 | func(batch.WaitSemaphore(i), batch.WaitDstMask(i)); |
| 7600 | } |
| 7601 | } |
| 7602 | |
| 7603 | template <typename BatchInfo> |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7604 | void QueueBatchContext::SetupAccessContext(const std::shared_ptr<const QueueBatchContext> &prev, const BatchInfo &batch_info, |
| 7605 | SignaledSemaphores &signaled) { |
John Zulauf | e0757ba | 2022-06-10 16:51:45 -0600 | [diff] [blame] | 7606 | // Copy in the event state from the previous batch (on this queue) |
| 7607 | if (prev) { |
| 7608 | events_context_.DeepCopy(prev->events_context_); |
| 7609 | } |
| 7610 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7611 | // Import (resolve) the batches that are waited on, with the semaphore's effective barriers applied |
| 7612 | layer_data::unordered_set<std::shared_ptr<const QueueBatchContext>> batches_resolved; |
| 7613 | ForEachWaitSemaphore(batch_info, [this, &signaled, &batches_resolved](VkSemaphore sem, VkPipelineStageFlags2 wait_mask) { |
| 7614 | std::shared_ptr<QueueBatchContext> resolved = ResolveOneWaitSemaphore(sem, wait_mask, signaled); |
| 7615 | if (resolved) { |
| 7616 | batches_resolved.emplace(std::move(resolved)); |
| 7617 | } |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7618 | }); |
| 7619 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7620 | // If there are no semaphores to the previous batch, make sure a "submit order" non-barriered import is done |
| 7621 | if (prev && !layer_data::Contains(batches_resolved, prev)) { |
| 7622 | access_context_.ResolveFromContext(NoopBarrierAction(), prev->access_context_); |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7623 | } |
| 7624 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7625 | // Gather async context information for hazard checks and conserve the QBC's for the async batches |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7626 | async_batches_ = |
| 7627 | sync_state_->GetQueueLastBatchSnapshot([&batches_resolved, &prev](const std::shared_ptr<const QueueBatchContext> &batch) { |
| 7628 | return (batch != prev) && !layer_data::Contains(batches_resolved, batch); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7629 | }); |
| 7630 | for (const auto &async_batch : async_batches_) { |
| 7631 | access_context_.AddAsyncContext(async_batch->GetCurrentAccessContext()); |
| 7632 | } |
| 7633 | } |
| 7634 | |
| 7635 | template <typename BatchInfo> |
| 7636 | void QueueBatchContext::SetupCommandBufferInfo(const BatchInfo &batch_info) { |
| 7637 | using Accessor = QueueBatchContext::SubmitInfoAccessor<BatchInfo>; |
| 7638 | Accessor batch(batch_info); |
| 7639 | |
| 7640 | // Create the list of command buffers to submit |
| 7641 | const uint32_t cb_count = batch.CommandBufferCount(); |
| 7642 | command_buffers_.reserve(cb_count); |
| 7643 | for (uint32_t index = 0; index < cb_count; ++index) { |
| 7644 | auto cb_context = sync_state_->GetAccessContextShared(batch.CommandBuffer(index)); |
| 7645 | if (cb_context) { |
| 7646 | tag_range_.end += cb_context->GetTagLimit(); |
| 7647 | command_buffers_.emplace_back(index, std::move(cb_context)); |
| 7648 | } |
| 7649 | } |
| 7650 | } |
| 7651 | |
| 7652 | // Look up the usage informaiton from the local or global logger |
| 7653 | std::string QueueBatchContext::FormatUsage(ResourceUsageTag tag) const { |
| 7654 | const AccessLogger &use_logger = (logger_) ? *logger_ : sync_state_->global_access_log_; |
| 7655 | std::stringstream out; |
| 7656 | AccessLogger::AccessRecord access = use_logger[tag]; |
| 7657 | if (access.IsValid()) { |
| 7658 | const AccessLogger::BatchRecord &batch = *access.batch; |
| 7659 | const ResourceUsageRecord &record = *access.record; |
| 7660 | // Queue and Batch information |
| 7661 | out << SyncNodeFormatter(*sync_state_, batch.queue->GetQueueState()); |
| 7662 | out << ", submit: " << batch.submit_index << ", batch: " << batch.batch_index; |
| 7663 | |
| 7664 | // Commandbuffer Usages Information |
| 7665 | out << record; |
| 7666 | out << SyncNodeFormatter(*sync_state_, record.cb_state); |
| 7667 | out << ", reset_no: " << std::to_string(record.reset_count); |
| 7668 | } |
| 7669 | return out.str(); |
| 7670 | } |
| 7671 | |
| 7672 | VkQueueFlags QueueBatchContext::GetQueueFlags() const { return queue_state_->GetQueueFlags(); } |
| 7673 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7674 | QueueId QueueBatchContext::GetQueueId() const { |
| 7675 | QueueId id = queue_state_ ? queue_state_->GetQueueId() : QueueSyncState::kQueueIdInvalid; |
| 7676 | return id; |
| 7677 | } |
| 7678 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7679 | void QueueBatchContext::SetBatchLog(AccessLogger &logger, uint64_t submit_id, uint32_t batch_id) { |
| 7680 | // Need new global tags for all accesses... the Reserve updates a mutable atomic |
| 7681 | ResourceUsageRange global_tags = sync_state_->ReserveGlobalTagRange(GetTagRange().size()); |
| 7682 | SetTagBias(global_tags.begin); |
| 7683 | // Add an access log for the batches range and point the batch at it. |
| 7684 | logger_ = &logger; |
| 7685 | batch_log_ = logger.AddBatch(queue_state_, submit_id, batch_id, global_tags); |
| 7686 | } |
| 7687 | |
| 7688 | void QueueBatchContext::InsertRecordedAccessLogEntries(const CommandBufferAccessContext &submitted_cb) { |
| 7689 | assert(batch_log_); // Don't import command buffer contexts until you've set up the log for the batch context |
| 7690 | batch_log_->Append(submitted_cb.GetAccessLog()); |
| 7691 | } |
| 7692 | |
| 7693 | void QueueBatchContext::SetTagBias(ResourceUsageTag bias) { |
| 7694 | const auto size = tag_range_.size(); |
| 7695 | tag_range_.begin = bias; |
| 7696 | tag_range_.end = bias + size; |
| 7697 | access_context_.SetStartTag(bias); |
| 7698 | } |
| 7699 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7700 | QueueBatchContext::QueueWaitWorm::QueueWaitWorm(QueueId queue, ResourceUsageTag tag) : predicate(queue) {} |
| 7701 | |
| 7702 | void QueueBatchContext::QueueWaitWorm::operator()(AccessAddressType address_type, ResourceAccessRangeMap::value_type &access) { |
| 7703 | bool erased = access.second.ApplyQueueTagWait(predicate); |
| 7704 | if (erased) { |
| 7705 | erase_list.emplace_back(address_type, access.first); |
| 7706 | } else { |
| 7707 | erase_all = false; |
| 7708 | } |
| 7709 | } |
| 7710 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7711 | AccessLogger::BatchLog *AccessLogger::AddBatch(const QueueSyncState *queue_state, uint64_t submit_id, uint32_t batch_id, |
| 7712 | const ResourceUsageRange &range) { |
| 7713 | const auto inserted = access_log_map_.insert(std::make_pair(range, BatchLog(BatchRecord(queue_state, submit_id, batch_id)))); |
| 7714 | assert(inserted.second); |
| 7715 | return &inserted.first->second; |
| 7716 | } |
| 7717 | |
| 7718 | void AccessLogger::MergeMove(AccessLogger &&child) { |
| 7719 | for (auto &range : child.access_log_map_) { |
| 7720 | BatchLog &child_batch = range.second; |
| 7721 | auto insert_pair = access_log_map_.insert(std::make_pair(range.first, BatchLog())); |
| 7722 | insert_pair.first->second = std::move(child_batch); |
| 7723 | assert(insert_pair.second); |
| 7724 | } |
| 7725 | child.Reset(); |
| 7726 | } |
| 7727 | |
| 7728 | void AccessLogger::Reset() { |
| 7729 | prev_ = nullptr; |
| 7730 | access_log_map_.clear(); |
| 7731 | } |
| 7732 | |
| 7733 | // Since we're updating the QueueSync state, this is Record phase and the access log needs to point to the global one |
| 7734 | // Batch Contexts saved during signalling have their AccessLog reset when the pending signals are signalled. |
| 7735 | // NOTE: By design, QueueBatchContexts that are neither last, nor referenced by a signal are abandoned as unowned, since |
| 7736 | // the contexts Resolve all history from previous all contexts when created |
| 7737 | void QueueSyncState::SetLastBatch(std::shared_ptr<QueueBatchContext> &&last) { |
| 7738 | last_batch_ = std::move(last); |
| 7739 | last_batch_->ResetAccessLog(); |
| 7740 | } |
| 7741 | |
| 7742 | // Note that function is const, but updates mutable submit_index to allow Validate to create correct tagging for command invocation |
| 7743 | // scope state. |
| 7744 | // Given that queue submits are supposed to be externally synchronized for the same queue, this should safe without being |
| 7745 | // atomic... but as the ops are per submit, the performance cost is negible for the peace of mind. |
| 7746 | uint64_t QueueSyncState::ReserveSubmitId() const { return submit_index_.fetch_add(1); } |
| 7747 | |
| 7748 | void AccessLogger::BatchLog::Append(const CommandExecutionContext::AccessLog &other) { |
| 7749 | log_.insert(log_.end(), other.cbegin(), other.cend()); |
| 7750 | for (const auto &record : other) { |
| 7751 | assert(record.cb_state); |
| 7752 | cbs_referenced_.insert(record.cb_state->shared_from_this()); |
| 7753 | } |
| 7754 | } |
| 7755 | |
| 7756 | AccessLogger::AccessRecord AccessLogger::BatchLog::operator[](size_t index) const { |
| 7757 | assert(index < log_.size()); |
| 7758 | return AccessRecord{&batch_, &log_[index]}; |
| 7759 | } |
| 7760 | |
| 7761 | AccessLogger::AccessRecord AccessLogger::operator[](ResourceUsageTag tag) const { |
| 7762 | AccessRecord access_record = {nullptr, nullptr}; |
| 7763 | |
| 7764 | auto found_range = access_log_map_.find(tag); |
| 7765 | if (found_range != access_log_map_.cend()) { |
| 7766 | const ResourceUsageTag bias = found_range->first.begin; |
| 7767 | assert(tag >= bias); |
| 7768 | access_record = found_range->second[tag - bias]; |
| 7769 | } else if (prev_) { |
| 7770 | access_record = (*prev_)[tag]; |
| 7771 | } |
| 7772 | |
| 7773 | return access_record; |
| 7774 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7775 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7776 | // This is a const method, force the returned value to be const |
| 7777 | std::shared_ptr<const SignaledSemaphores::Signal> SignaledSemaphores::GetPrev(VkSemaphore sem) const { |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7778 | std::shared_ptr<Signal> prev_state; |
| 7779 | if (prev_) { |
| 7780 | prev_state = GetMapped(prev_->signaled_, sem, [&prev_state]() { return prev_state; }); |
| 7781 | } |
| 7782 | return prev_state; |
| 7783 | } |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7784 | |
| 7785 | SignaledSemaphores::Signal::Signal(const std::shared_ptr<const SEMAPHORE_STATE> &sem_state_, |
| 7786 | const std::shared_ptr<QueueBatchContext> &batch_, const SyncExecScope &exec_scope_) |
| 7787 | : sem_state(sem_state_), batch(batch_), first_scope({batch->GetQueueId(), exec_scope_}) { |
| 7788 | // Illegal to create a signal from no batch or an invalid semaphore... caller must assure validity |
| 7789 | assert(batch); |
| 7790 | assert(sem_state); |
| 7791 | } |