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 | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 823 | HazardResult AccessContext::DetectPreviousHazard(AccessAddressType type, const 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 | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 848 | HazardResult AccessContext::DetectHazard(AccessAddressType type, const 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 | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 926 | struct ApplyTrackbackStackAction { |
| 927 | explicit ApplyTrackbackStackAction(const std::vector<SyncBarrier> &barriers_, |
| 928 | const ResourceAccessStateFunction *previous_barrier_ = nullptr) |
| 929 | : barriers(barriers_), previous_barrier(previous_barrier_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 930 | void operator()(ResourceAccessState *access) const { |
| 931 | assert(access); |
| 932 | assert(!access->HasPendingState()); |
| 933 | access->ApplyBarriers(barriers, false); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 934 | // NOTE: We can use invalid tag, as these barriers do no include layout transitions (would assert in SetWrite) |
| 935 | access->ApplyPendingBarriers(kInvalidTag); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 936 | if (previous_barrier) { |
| 937 | assert(bool(*previous_barrier)); |
| 938 | (*previous_barrier)(access); |
| 939 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 940 | } |
| 941 | const std::vector<SyncBarrier> &barriers; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 942 | const ResourceAccessStateFunction *previous_barrier; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 943 | }; |
| 944 | |
| 945 | // Splits a single map entry into piece matching the entries in [first, last) the total range over [first, last) must be |
| 946 | // contained with entry. Entry must be an iterator pointing to dest, first and last must be iterators pointing to a |
| 947 | // *different* map from dest. |
| 948 | // Returns the position past the last resolved range -- the entry covering the remainder of entry->first not included in the |
| 949 | // range [first, last) |
| 950 | template <typename BarrierAction> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 951 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 952 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 953 | BarrierAction &barrier_action) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 954 | auto at = entry; |
| 955 | for (auto pos = first; pos != last; ++pos) { |
| 956 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 957 | assert(at->first.includes(pos->first)); |
| 958 | assert(at != dest->end()); |
| 959 | // Trim up at to the same size as the entry to resolve |
| 960 | at = sparse_container::split(at, *dest, pos->first); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 961 | auto access = pos->second; // intentional copy |
| 962 | barrier_action(&access); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 963 | at->second.Resolve(access); |
| 964 | ++at; // Go to the remaining unused section of entry |
| 965 | } |
| 966 | } |
| 967 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 968 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 969 | SyncBarrier merged = {}; |
| 970 | for (const auto &barrier : barriers) { |
| 971 | merged.Merge(barrier); |
| 972 | } |
| 973 | return merged; |
| 974 | } |
| 975 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 976 | template <typename BarrierAction> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 977 | void AccessContext::ResolveAccessRange(AccessAddressType type, const ResourceAccessRange &range, BarrierAction &barrier_action, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 978 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 979 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 980 | if (!range.non_empty()) return; |
| 981 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 982 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 983 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 984 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 985 | if (current->pos_B->valid) { |
| 986 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 987 | auto access = src_pos->second; // intentional copy |
| 988 | barrier_action(&access); |
| 989 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 990 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 991 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 992 | trimmed->second.Resolve(access); |
| 993 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 994 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 995 | 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] | 996 | 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] | 997 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 998 | } else { |
| 999 | // we have to descend to fill this gap |
| 1000 | if (recur_to_infill) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1001 | ResourceAccessRange recurrence_range = current_range; |
| 1002 | // The current context is empty for the current range, so recur to fill the gap. |
| 1003 | // Since we will be recurring back up the DAG, expand the gap descent to cover the full range for which B |
| 1004 | // is not valid, to minimize that recurrence |
| 1005 | if (current->pos_B.at_end()) { |
| 1006 | // Do the remainder here.... |
| 1007 | recurrence_range.end = range.end; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1008 | } else { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1009 | // Recur only over the range until B becomes valid (within the limits of range). |
| 1010 | 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] | 1011 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1012 | ResolvePreviousAccessStack(type, recurrence_range, resolve_map, infill_state, barrier_action); |
| 1013 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1014 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 1015 | // iterator of the outer while. |
| 1016 | |
| 1017 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 1018 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 1019 | // we stepped on the dest map |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1020 | 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] | 1021 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1022 | current.seek(seek_to); |
| 1023 | } else if (!current->pos_A->valid && infill_state) { |
| 1024 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 1025 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 1026 | 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] | 1027 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1028 | } |
ziga-lunarg | f0e27ad | 2022-03-28 00:44:12 +0200 | [diff] [blame] | 1029 | if (current->range.non_empty()) { |
| 1030 | ++current; |
| 1031 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1032 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1033 | |
| 1034 | // Infill if range goes passed both the current and resolve map prior contents |
| 1035 | if (recur_to_infill && (current->range.end < range.end)) { |
| 1036 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1037 | ResolvePreviousAccessStack<BarrierAction>(type, trailing_fill_range, resolve_map, infill_state, barrier_action); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1038 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1039 | } |
| 1040 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1041 | template <typename BarrierAction> |
| 1042 | void AccessContext::ResolvePreviousAccessStack(AccessAddressType type, const ResourceAccessRange &range, |
| 1043 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 1044 | const BarrierAction &previous_barrier) const { |
| 1045 | ResourceAccessStateFunction stacked_barrier(std::ref(previous_barrier)); |
| 1046 | ResolvePreviousAccess(type, range, descent_map, infill_state, &stacked_barrier); |
| 1047 | } |
| 1048 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1049 | void AccessContext::ResolvePreviousAccess(AccessAddressType type, const ResourceAccessRange &range, |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1050 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 1051 | const ResourceAccessStateFunction *previous_barrier) const { |
| 1052 | if (prev_.size() == 0) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1053 | if (range.non_empty() && infill_state) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1054 | // Fill the empty poritions of descent_map with the default_state with the barrier function applied (iff present) |
| 1055 | ResourceAccessState state_copy; |
| 1056 | if (previous_barrier) { |
| 1057 | assert(bool(*previous_barrier)); |
| 1058 | state_copy = *infill_state; |
| 1059 | (*previous_barrier)(&state_copy); |
| 1060 | infill_state = &state_copy; |
| 1061 | } |
| 1062 | sparse_container::update_range_value(*descent_map, range, *infill_state, |
| 1063 | sparse_container::value_precedence::prefer_dest); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1064 | } |
| 1065 | } else { |
| 1066 | // Look for something to fill the gap further along. |
| 1067 | for (const auto &prev_dep : prev_) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1068 | const ApplyTrackbackStackAction barrier_action(prev_dep.barriers, previous_barrier); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1069 | 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] | 1070 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1071 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1072 | } |
| 1073 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1074 | // Non-lazy import of all accesses, WaitEvents needs this. |
| 1075 | void AccessContext::ResolvePreviousAccesses() { |
| 1076 | ResourceAccessState default_state; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1077 | if (!prev_.size()) return; // If no previous contexts, nothing to do |
| 1078 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1079 | for (const auto address_type : kAddressTypes) { |
| 1080 | ResolvePreviousAccess(address_type, kFullRange, &GetAccessStateMap(address_type), &default_state); |
| 1081 | } |
| 1082 | } |
| 1083 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1084 | AccessAddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
| 1085 | return (image.fragment_encoder->IsLinearImage()) ? AccessAddressType::kLinear : AccessAddressType::kIdealized; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1086 | } |
| 1087 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1088 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1089 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_NONE_EXT) |
| 1090 | ? SYNC_ACCESS_INDEX_NONE |
| 1091 | : ((load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 1092 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1093 | return stage_access; |
| 1094 | } |
| 1095 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1096 | const auto stage_access = |
| 1097 | (load_op == VK_ATTACHMENT_LOAD_OP_NONE_EXT) |
| 1098 | ? SYNC_ACCESS_INDEX_NONE |
| 1099 | : ((load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 1100 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1101 | return stage_access; |
| 1102 | } |
| 1103 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1104 | // Caller must manage returned pointer |
| 1105 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1106 | uint32_t subpass, const AttachmentViewGenVector &attachment_views) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1107 | auto *proxy = new AccessContext(context); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1108 | proxy->UpdateAttachmentResolveAccess(rp_state, attachment_views, subpass, kInvalidTag); |
| 1109 | proxy->UpdateAttachmentStoreAccess(rp_state, attachment_views, subpass, kInvalidTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1110 | return proxy; |
| 1111 | } |
| 1112 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1113 | template <typename BarrierAction> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1114 | void AccessContext::ResolveAccessRange(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1115 | BarrierAction &barrier_action, ResourceAccessRangeMap *descent_map, |
| 1116 | const ResourceAccessState *infill_state) const { |
| 1117 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1118 | if (!attachment_gen) return; |
| 1119 | |
| 1120 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1121 | const AccessAddressType address_type = view_gen.GetAddressType(); |
| 1122 | for (; range_gen->non_empty(); ++range_gen) { |
| 1123 | ResolveAccessRange(address_type, *range_gen, barrier_action, descent_map, infill_state); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1124 | } |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 1125 | } |
| 1126 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 1127 | template <typename ResolveOp> |
| 1128 | void AccessContext::ResolveFromContext(ResolveOp &&resolve_op, const AccessContext &from_context, |
| 1129 | const ResourceAccessState *infill_state, bool recur_to_infill) { |
| 1130 | for (auto address_type : kAddressTypes) { |
| 1131 | from_context.ResolveAccessRange(address_type, kFullRange, resolve_op, &GetAccessStateMap(address_type), infill_state, |
| 1132 | recur_to_infill); |
| 1133 | } |
| 1134 | } |
| 1135 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1136 | // 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] | 1137 | 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] | 1138 | const VkRect2D &render_area, uint32_t subpass, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1139 | const AttachmentViewGenVector &attachment_views, CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1140 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1141 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 1142 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 1143 | // those affects have not been recorded yet. |
| 1144 | // |
| 1145 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 1146 | // to apply and only copy then, if this proves a hot spot. |
| 1147 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 1148 | TrackBack proxy_track_back; |
| 1149 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1150 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 1151 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1152 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 1153 | |
| 1154 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1155 | assert(track_back); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1156 | if (prev_needs_proxy) { |
| 1157 | if (!proxy_for_prev) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1158 | proxy_for_prev.reset( |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1159 | CreateStoreResolveProxyContext(*track_back->source_subpass, rp_state, transition.prev_pass, attachment_views)); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1160 | proxy_track_back = *track_back; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1161 | proxy_track_back.source_subpass = proxy_for_prev.get(); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1162 | } |
| 1163 | track_back = &proxy_track_back; |
| 1164 | } |
| 1165 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1166 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1167 | const char *func_name = CommandTypeString(cmd_type); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1168 | if (hazard.tag == kInvalidTag) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1169 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1170 | rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1171 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1172 | " image layout transition (old_layout: %s, new_layout: %s) after store/resolve operation in subpass %" PRIu32, |
| 1173 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1174 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), transition.prev_pass); |
| 1175 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1176 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1177 | rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1178 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1179 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 1180 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1181 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1182 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1183 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | return skip; |
| 1187 | } |
| 1188 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1189 | 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] | 1190 | const VkRect2D &render_area, uint32_t subpass, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1191 | const AttachmentViewGenVector &attachment_views, CMD_TYPE cmd_type) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1192 | bool skip = false; |
| 1193 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1194 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1195 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1196 | if (subpass == rp_state.attachment_first_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1197 | const auto &view_gen = attachment_views[i]; |
| 1198 | if (!view_gen.IsValid()) continue; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1199 | const auto &ci = attachment_ci[i]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1200 | |
| 1201 | // Need check in the following way |
| 1202 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 1203 | // vs. transition |
| 1204 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 1205 | // for each aspect loaded. |
| 1206 | |
| 1207 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1208 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1209 | const bool is_color = !(has_depth || has_stencil); |
| 1210 | |
| 1211 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1212 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1213 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1214 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1215 | const char *aspect = nullptr; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1216 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1217 | bool checked_stencil = false; |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1218 | if (is_color && (load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1219 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, load_index, SyncOrdering::kColorAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1220 | aspect = "color"; |
| 1221 | } else { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1222 | if (has_depth && (load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1223 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_index, |
| 1224 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1225 | aspect = "depth"; |
| 1226 | } |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1227 | if (!hazard.hazard && has_stencil && (stencil_load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1228 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, stencil_load_index, |
| 1229 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1230 | aspect = "stencil"; |
| 1231 | checked_stencil = true; |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1236 | const char *func_name = CommandTypeString(cmd_type); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1237 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1238 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1239 | if (hazard.tag == kInvalidTag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1240 | // Hazard vs. ILT |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1241 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1242 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1243 | " aspect %s during load with loadOp %s.", |
| 1244 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string); |
| 1245 | } else { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1246 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1247 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1248 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1249 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1250 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | } |
| 1255 | return skip; |
| 1256 | } |
| 1257 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1258 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 1259 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 1260 | // store is part of the same Next/End operation. |
| 1261 | // The latter is handled in layout transistion validation directly |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1262 | 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] | 1263 | const VkRect2D &render_area, uint32_t subpass, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1264 | const AttachmentViewGenVector &attachment_views, CMD_TYPE cmd_type) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1265 | bool skip = false; |
| 1266 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1267 | |
| 1268 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1269 | if (subpass == rp_state.attachment_last_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1270 | const AttachmentViewGen &view_gen = attachment_views[i]; |
| 1271 | if (!view_gen.IsValid()) continue; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1272 | const auto &ci = attachment_ci[i]; |
| 1273 | |
| 1274 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1275 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 1276 | // sake, we treat DONT_CARE as writing. |
| 1277 | const bool has_depth = FormatHasDepth(ci.format); |
| 1278 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1279 | const bool is_color = !(has_depth || has_stencil); |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1280 | 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] | 1281 | if (!has_stencil && !store_op_stores) continue; |
| 1282 | |
| 1283 | HazardResult hazard; |
| 1284 | const char *aspect = nullptr; |
| 1285 | bool checked_stencil = false; |
| 1286 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1287 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1288 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1289 | aspect = "color"; |
| 1290 | } else { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1291 | 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] | 1292 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1293 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1294 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1295 | aspect = "depth"; |
| 1296 | } |
| 1297 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1298 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1299 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1300 | aspect = "stencil"; |
| 1301 | checked_stencil = true; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | if (hazard.hazard) { |
| 1306 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 1307 | 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] | 1308 | skip |= exec_context.GetSyncState().LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 1309 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1310 | " %s aspect during store with %s %s. Access info %s", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1311 | CommandTypeString(cmd_type), string_SyncHazard(hazard.hazard), subpass, |
| 1312 | i, aspect, op_type_string, store_op_string, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 1313 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | } |
| 1317 | return skip; |
| 1318 | } |
| 1319 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1320 | 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] | 1321 | const VkRect2D &render_area, const AttachmentViewGenVector &attachment_views, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1322 | CMD_TYPE cmd_type, uint32_t subpass) const { |
| 1323 | ValidateResolveAction validate_action(rp_state.renderPass(), subpass, *this, exec_context, cmd_type); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1324 | ResolveOperation(validate_action, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1325 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1326 | } |
| 1327 | |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 1328 | void AccessContext::AddAsyncContext(const AccessContext *context) { async_.emplace_back(context); } |
| 1329 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1330 | class HazardDetector { |
| 1331 | SyncStageAccessIndex usage_index_; |
| 1332 | |
| 1333 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1334 | 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] | 1335 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1336 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1337 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1338 | explicit HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1339 | }; |
| 1340 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1341 | class HazardDetectorWithOrdering { |
| 1342 | const SyncStageAccessIndex usage_index_; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1343 | const SyncOrdering ordering_rule_; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1344 | |
| 1345 | public: |
| 1346 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1347 | return pos->second.DetectHazard(usage_index_, ordering_rule_); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1348 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1349 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1350 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1351 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1352 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, SyncOrdering ordering) : usage_index_(usage), ordering_rule_(ordering) {} |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1353 | }; |
| 1354 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1355 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1356 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1357 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1358 | const auto base_address = ResourceBaseAddress(buffer); |
| 1359 | HazardDetector detector(usage_index); |
| 1360 | return DetectHazard(AccessAddressType::kLinear, detector, (range + base_address), DetectOptions::kDetectAll); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 1361 | } |
| 1362 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1363 | template <typename Detector> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1364 | HazardResult AccessContext::DetectHazard(Detector &detector, const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1365 | DetectOptions options) const { |
| 1366 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1367 | if (!attachment_gen) return HazardResult(); |
| 1368 | |
| 1369 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1370 | const auto address_type = view_gen.GetAddressType(); |
| 1371 | for (; range_gen->non_empty(); ++range_gen) { |
| 1372 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1373 | if (hazard.hazard) return hazard; |
| 1374 | } |
| 1375 | |
| 1376 | return HazardResult(); |
| 1377 | } |
| 1378 | |
| 1379 | template <typename Detector> |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1380 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1381 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1382 | const VkExtent3D &extent, bool is_depth_sliced, DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1383 | if (!SimpleBinding(image)) return HazardResult(); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1384 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1385 | 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] | 1386 | base_address, is_depth_sliced); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1387 | const auto address_type = ImageAddressType(image); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1388 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1389 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1390 | if (hazard.hazard) return hazard; |
| 1391 | } |
| 1392 | return HazardResult(); |
| 1393 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1394 | template <typename Detector> |
| 1395 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1396 | const VkImageSubresourceRange &subresource_range, bool is_depth_sliced, |
| 1397 | DetectOptions options) const { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1398 | if (!SimpleBinding(image)) return HazardResult(); |
| 1399 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1400 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address, |
| 1401 | is_depth_sliced); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1402 | const auto address_type = ImageAddressType(image); |
| 1403 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1404 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1405 | if (hazard.hazard) return hazard; |
| 1406 | } |
| 1407 | return HazardResult(); |
| 1408 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1409 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1410 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1411 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1412 | const VkExtent3D &extent, bool is_depth_sliced) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1413 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1414 | subresource.layerCount}; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1415 | HazardDetector detector(current_usage); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1416 | 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] | 1417 | } |
| 1418 | |
| 1419 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1420 | const VkImageSubresourceRange &subresource_range, bool is_depth_sliced) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1421 | HazardDetector detector(current_usage); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1422 | return DetectHazard(detector, image, subresource_range, is_depth_sliced, DetectOptions::kDetectAll); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1423 | } |
| 1424 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1425 | HazardResult AccessContext::DetectHazard(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1426 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) const { |
| 1427 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
| 1428 | return DetectHazard(detector, view_gen, gen_type, DetectOptions::kDetectAll); |
| 1429 | } |
| 1430 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1431 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1432 | const VkImageSubresourceRange &subresource_range, SyncOrdering ordering_rule, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1433 | const VkOffset3D &offset, const VkExtent3D &extent, bool is_depth_sliced) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1434 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1435 | 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] | 1436 | } |
| 1437 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1438 | class BarrierHazardDetector { |
| 1439 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1440 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1441 | SyncStageAccessFlags src_access_scope) |
| 1442 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1443 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1444 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1445 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1446 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1447 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1448 | // 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] | 1449 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | private: |
| 1453 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1454 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1455 | SyncStageAccessFlags src_access_scope_; |
| 1456 | }; |
| 1457 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1458 | class EventBarrierHazardDetector { |
| 1459 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1460 | EventBarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1461 | SyncStageAccessFlags src_access_scope, const SyncEventState::ScopeMap &event_scope, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1462 | ResourceUsageTag scope_tag) |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1463 | : usage_index_(usage_index), |
| 1464 | src_exec_scope_(src_exec_scope), |
| 1465 | src_access_scope_(src_access_scope), |
| 1466 | event_scope_(event_scope), |
| 1467 | scope_pos_(event_scope.cbegin()), |
| 1468 | scope_end_(event_scope.cend()), |
| 1469 | scope_tag_(scope_tag) {} |
| 1470 | |
| 1471 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1472 | // TODO NOTE: This is almost the slowest way to do this... need to intelligently walk this... |
| 1473 | // Need to find a more efficient sync, since we know pos->first is strictly increasing call to call |
| 1474 | // NOTE: "cached_lower_bound_impl" with upgrades could do this. |
| 1475 | if (scope_pos_ == scope_end_) return HazardResult(); |
| 1476 | if (!scope_pos_->first.intersects(pos->first)) { |
| 1477 | event_scope_.lower_bound(pos->first); |
| 1478 | if ((scope_pos_ == scope_end_) || !scope_pos_->first.intersects(pos->first)) return HazardResult(); |
| 1479 | } |
| 1480 | |
| 1481 | // Some portion of this pos is in the event_scope, so check for a barrier hazard |
| 1482 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_, scope_tag_); |
| 1483 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1484 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1485 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1486 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
| 1487 | } |
| 1488 | |
| 1489 | private: |
| 1490 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1491 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1492 | SyncStageAccessFlags src_access_scope_; |
| 1493 | const SyncEventState::ScopeMap &event_scope_; |
| 1494 | SyncEventState::ScopeMap::const_iterator scope_pos_; |
| 1495 | SyncEventState::ScopeMap::const_iterator scope_end_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1496 | const ResourceUsageTag scope_tag_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1497 | }; |
| 1498 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1499 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1500 | const SyncStageAccessFlags &src_access_scope, |
| 1501 | const VkImageSubresourceRange &subresource_range, |
| 1502 | const SyncEventState &sync_event, DetectOptions options) const { |
| 1503 | // It's not particularly DRY to get the address type in this function as well as lower down, but we have to select the |
| 1504 | // first access scope map to use, and there's no easy way to plumb it in below. |
| 1505 | const auto address_type = ImageAddressType(image); |
| 1506 | const auto &event_scope = sync_event.FirstScope(address_type); |
| 1507 | |
| 1508 | EventBarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope, |
| 1509 | event_scope, sync_event.first_scope_tag); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1510 | return DetectHazard(detector, image, subresource_range, false, options); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1513 | HazardResult AccessContext::DetectImageBarrierHazard(const AttachmentViewGen &view_gen, const SyncBarrier &barrier, |
| 1514 | DetectOptions options) const { |
| 1515 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, barrier.src_exec_scope.exec_scope, |
| 1516 | barrier.src_access_scope); |
| 1517 | return DetectHazard(detector, view_gen, AttachmentViewGen::Gen::kViewSubresource, options); |
| 1518 | } |
| 1519 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1520 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1521 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1522 | const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1523 | const DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1524 | 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] | 1525 | return DetectHazard(detector, image, subresource_range, false, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1528 | HazardResult AccessContext::DetectImageBarrierHazard(const SyncImageMemoryBarrier &image_barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1529 | 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] | 1530 | image_barrier.barrier.src_access_scope, image_barrier.range, kDetectAll); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1531 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1532 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1533 | template <typename Flags, typename Map> |
| 1534 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1535 | SyncStageAccessFlags scope = 0; |
| 1536 | for (const auto &bit_scope : map) { |
| 1537 | if (flag_mask < bit_scope.first) break; |
| 1538 | |
| 1539 | if (flag_mask & bit_scope.first) { |
| 1540 | scope |= bit_scope.second; |
| 1541 | } |
| 1542 | } |
| 1543 | return scope; |
| 1544 | } |
| 1545 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1546 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags2KHR stages) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1547 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1548 | } |
| 1549 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1550 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags2KHR accesses) { |
| 1551 | return AccessScopeImpl(sync_utils::ExpandAccessFlags(accesses), syncStageAccessMaskByAccessBit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1552 | } |
| 1553 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1554 | // Getting from stage mask and access mask to stage/access masks is something we need to be good at... |
| 1555 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags2KHR stages, VkAccessFlags2KHR accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1556 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1557 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1558 | // 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] | 1559 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1560 | } |
| 1561 | |
| 1562 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1563 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1564 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1565 | // that do incrementalupdates |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1566 | assert(accesses); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1567 | auto pos = accesses->lower_bound(range); |
| 1568 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1569 | // The range is empty, fill it with a default value. |
| 1570 | pos = action.Infill(accesses, pos, range); |
| 1571 | } else if (range.begin < pos->first.begin) { |
| 1572 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1573 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1574 | } else if (pos->first.begin < range.begin) { |
| 1575 | // Trim the beginning if needed |
| 1576 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1577 | ++pos; |
| 1578 | } |
| 1579 | |
| 1580 | const auto the_end = accesses->end(); |
| 1581 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1582 | if (pos->first.end > range.end) { |
| 1583 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1584 | } |
| 1585 | |
| 1586 | pos = action(accesses, pos); |
| 1587 | if (pos == the_end) break; |
| 1588 | |
| 1589 | auto next = pos; |
| 1590 | ++next; |
| 1591 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1592 | // Need to infill if next is disjoint |
| 1593 | 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] | 1594 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1595 | next = action.Infill(accesses, next, new_range); |
| 1596 | } |
| 1597 | pos = next; |
| 1598 | } |
| 1599 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1600 | |
| 1601 | // Give a comparable interface for range generators and ranges |
| 1602 | template <typename Action> |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 1603 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, ResourceAccessRange *range) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1604 | assert(range); |
| 1605 | UpdateMemoryAccessState(accesses, *range, action); |
| 1606 | } |
| 1607 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1608 | template <typename Action, typename RangeGen> |
| 1609 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, RangeGen *range_gen_arg) { |
| 1610 | assert(range_gen_arg); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1611 | 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] | 1612 | for (; range_gen->non_empty(); ++range_gen) { |
| 1613 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1614 | } |
| 1615 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1616 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1617 | template <typename Action, typename RangeGen> |
| 1618 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, const RangeGen &range_gen_prebuilt) { |
| 1619 | RangeGen range_gen(range_gen_prebuilt); // RangeGenerators can be expensive to create from scratch... initialize from built |
| 1620 | for (; range_gen->non_empty(); ++range_gen) { |
| 1621 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1622 | } |
| 1623 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1624 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1625 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1626 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1627 | // this is only called on gaps, and never returns a gap. |
| 1628 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1629 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1630 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1631 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1632 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1633 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1634 | auto &access_state = pos->second; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1635 | access_state.Update(usage, ordering_rule, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1636 | return pos; |
| 1637 | } |
| 1638 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1639 | UpdateMemoryAccessStateFunctor(AccessAddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1640 | SyncOrdering ordering_rule_, ResourceUsageTag tag_) |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1641 | : type(type_), context(context_), usage(usage_), ordering_rule(ordering_rule_), tag(tag_) {} |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1642 | const AccessAddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1643 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1644 | const SyncStageAccessIndex usage; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1645 | const SyncOrdering ordering_rule; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1646 | const ResourceUsageTag tag; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1647 | }; |
| 1648 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1649 | // The barrier operation for pipeline and subpass dependencies` |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1650 | struct PipelineBarrierOp { |
| 1651 | SyncBarrier barrier; |
| 1652 | bool layout_transition; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1653 | ResourceAccessState::QueueScopeOps scope; |
| 1654 | PipelineBarrierOp(QueueId queue_id, const SyncBarrier &barrier_, bool layout_transition_) |
| 1655 | : barrier(barrier_), layout_transition(layout_transition_), scope(queue_id) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1656 | PipelineBarrierOp(const PipelineBarrierOp &) = default; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1657 | 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] | 1658 | }; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1659 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 1660 | // Batch barrier ops don't modify in place, and thus don't need to hold pending state, and also are *never* layout transitions. |
| 1661 | struct BatchBarrierOp : public PipelineBarrierOp { |
| 1662 | void operator()(ResourceAccessState *access_state) const { |
| 1663 | access_state->ApplyBarrier(scope, barrier, layout_transition); |
| 1664 | access_state->ApplyPendingBarriers(kInvalidTag); // There can't be any need for this tag |
| 1665 | } |
| 1666 | BatchBarrierOp(QueueId queue_id, const SyncBarrier &barrier_) : PipelineBarrierOp(queue_id, barrier_, false) {} |
| 1667 | }; |
| 1668 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1669 | // The barrier operation for wait events |
| 1670 | struct WaitEventBarrierOp { |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 1671 | ResourceAccessState::EventScopeOps scope_ops; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1672 | SyncBarrier barrier; |
| 1673 | bool layout_transition; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 1674 | // WIP Integrate Queue scoping into event scope operations |
| 1675 | WaitEventBarrierOp(const QueueId scope_queue, const ResourceUsageTag scope_tag_, const SyncBarrier &barrier_, |
| 1676 | bool layout_transition_) |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 1677 | : scope_ops(scope_tag_), barrier(barrier_), layout_transition(layout_transition_) {} |
| 1678 | 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] | 1679 | }; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1680 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1681 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1682 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1683 | // of a collection is known/present. |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1684 | template <typename BarrierOp, typename OpVector = std::vector<BarrierOp>> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1685 | class ApplyBarrierOpsFunctor { |
| 1686 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1687 | using Iterator = ResourceAccessRangeMap::iterator; |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1688 | // Only called with a gap, and pos at the lower_bound(range) |
| 1689 | inline Iterator Infill(ResourceAccessRangeMap *accesses, const Iterator &pos, const ResourceAccessRange &range) const { |
| 1690 | if (!infill_default_) { |
| 1691 | return pos; |
| 1692 | } |
| 1693 | ResourceAccessState default_state; |
| 1694 | auto inserted = accesses->insert(pos, std::make_pair(range, default_state)); |
| 1695 | return inserted; |
| 1696 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1697 | |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1698 | Iterator operator()(ResourceAccessRangeMap *accesses, const Iterator &pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1699 | auto &access_state = pos->second; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1700 | for (const auto &op : barrier_ops_) { |
| 1701 | op(&access_state); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1702 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1703 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1704 | if (resolve_) { |
| 1705 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1706 | // another walk |
| 1707 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1708 | } |
| 1709 | return pos; |
| 1710 | } |
| 1711 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1712 | // 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] | 1713 | ApplyBarrierOpsFunctor(bool resolve, typename OpVector::size_type size_hint, ResourceUsageTag tag) |
| 1714 | : resolve_(resolve), infill_default_(false), barrier_ops_(), tag_(tag) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1715 | barrier_ops_.reserve(size_hint); |
| 1716 | } |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1717 | void EmplaceBack(const BarrierOp &op) { |
| 1718 | barrier_ops_.emplace_back(op); |
| 1719 | infill_default_ |= op.layout_transition; |
| 1720 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1721 | |
| 1722 | private: |
| 1723 | bool resolve_; |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1724 | bool infill_default_; |
| 1725 | OpVector barrier_ops_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1726 | const ResourceUsageTag tag_; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1727 | }; |
| 1728 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1729 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1730 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1731 | template <typename BarrierOp> |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1732 | class ApplyBarrierFunctor : public ApplyBarrierOpsFunctor<BarrierOp, small_vector<BarrierOp, 1>> { |
| 1733 | using Base = ApplyBarrierOpsFunctor<BarrierOp, small_vector<BarrierOp, 1>>; |
| 1734 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1735 | public: |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 1736 | 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] | 1737 | }; |
| 1738 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1739 | // This functor resolves the pendinging state. |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1740 | class ResolvePendingBarrierFunctor : public ApplyBarrierOpsFunctor<NoopBarrierAction, small_vector<NoopBarrierAction, 1>> { |
| 1741 | using Base = ApplyBarrierOpsFunctor<NoopBarrierAction, small_vector<NoopBarrierAction, 1>>; |
| 1742 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1743 | public: |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1744 | ResolvePendingBarrierFunctor(ResourceUsageTag tag) : Base(true, 0, tag) {} |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1745 | }; |
| 1746 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1747 | void AccessContext::UpdateAccessState(AccessAddressType type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1748 | const ResourceAccessRange &range, const ResourceUsageTag tag) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1749 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1750 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1751 | } |
| 1752 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1753 | 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] | 1754 | const ResourceAccessRange &range, const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1755 | if (!SimpleBinding(buffer)) return; |
| 1756 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1757 | UpdateAccessState(AccessAddressType::kLinear, current_usage, ordering_rule, range + base_address, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1758 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1759 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1760 | 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] | 1761 | const VkImageSubresourceRange &subresource_range, const ResourceUsageTag &tag) { |
| 1762 | if (!SimpleBinding(image)) return; |
| 1763 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1764 | 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] | 1765 | const auto address_type = ImageAddressType(image); |
| 1766 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1767 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
| 1768 | } |
| 1769 | 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] | 1770 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1771 | const VkExtent3D &extent, const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1772 | if (!SimpleBinding(image)) return; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1773 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1774 | 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] | 1775 | base_address, false); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1776 | const auto address_type = ImageAddressType(image); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1777 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1778 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1779 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1780 | |
| 1781 | void AccessContext::UpdateAccessState(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1782 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, const ResourceUsageTag tag) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1783 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1784 | if (!gen) return; |
| 1785 | subresource_adapter::ImageRangeGenerator range_gen(*gen); |
| 1786 | const auto address_type = view_gen.GetAddressType(); |
| 1787 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1788 | ApplyUpdateAction(address_type, action, &range_gen); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1789 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1790 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1791 | 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] | 1792 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1793 | const VkExtent3D &extent, const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1794 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1795 | subresource.layerCount}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1796 | UpdateAccessState(image, current_usage, ordering_rule, subresource_range, offset, extent, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1797 | } |
| 1798 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1799 | template <typename Action, typename RangeGen> |
| 1800 | void AccessContext::ApplyUpdateAction(AccessAddressType address_type, const Action &action, RangeGen *range_gen_arg) { |
| 1801 | assert(range_gen_arg); // Old Google C++ styleguide require non-const object pass by * not &, but this isn't an optional arg. |
| 1802 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, range_gen_arg); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1806 | void AccessContext::ApplyUpdateAction(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, const Action &action) { |
| 1807 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1808 | if (!gen) return; |
| 1809 | UpdateMemoryAccessState(&GetAccessStateMap(view_gen.GetAddressType()), action, *gen); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1810 | } |
| 1811 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1812 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, |
| 1813 | const AttachmentViewGenVector &attachment_views, uint32_t subpass, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1814 | const ResourceUsageTag tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1815 | UpdateStateResolveAction update(*this, tag); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1816 | ResolveOperation(update, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1817 | } |
| 1818 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1819 | 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] | 1820 | uint32_t subpass, const ResourceUsageTag tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1821 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1822 | |
| 1823 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1824 | if (rp_state.attachment_last_subpass[i] == subpass) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1825 | const auto &view_gen = attachment_views[i]; |
| 1826 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1827 | |
| 1828 | const auto &ci = attachment_ci[i]; |
| 1829 | const bool has_depth = FormatHasDepth(ci.format); |
| 1830 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1831 | const bool is_color = !(has_depth || has_stencil); |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1832 | 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] | 1833 | |
| 1834 | if (is_color && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1835 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1836 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1837 | } else { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1838 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1839 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1840 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1841 | } |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1842 | 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] | 1843 | if (has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1844 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1845 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1846 | } |
| 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | } |
| 1851 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1852 | template <typename Action> |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1853 | void AccessContext::ApplyToContext(const Action &barrier_action) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1854 | // 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] | 1855 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1856 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), kFullRange, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1861 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1862 | auto &context = contexts[subpass_index]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1863 | ApplyTrackbackStackAction barrier_action(context.GetDstExternalTrackBack().barriers); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1864 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1865 | context.ResolveAccessRange(address_type, kFullRange, barrier_action, &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 1870 | // Caller must ensure that lifespan of this is less than from |
| 1871 | void AccessContext::ImportAsyncContexts(const AccessContext &from) { async_ = from.async_; } |
| 1872 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1873 | // Suitable only for *subpass* access contexts |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1874 | HazardResult AccessContext::DetectSubpassTransitionHazard(const TrackBack &track_back, const AttachmentViewGen &attach_view) const { |
| 1875 | if (!attach_view.IsValid()) return HazardResult(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1876 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1877 | // 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] | 1878 | assert(track_back.source_subpass); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1879 | |
| 1880 | // 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] | 1881 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1882 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1883 | HazardResult hazard = track_back.source_subpass->DetectImageBarrierHazard(attach_view, merged_barrier, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1884 | if (!hazard.hazard) { |
| 1885 | // The Async hazard check is against the current context's async set. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1886 | hazard = DetectImageBarrierHazard(attach_view, merged_barrier, kDetectAsync); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1887 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1888 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1889 | return hazard; |
| 1890 | } |
| 1891 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1892 | void AccessContext::RecordLayoutTransitions(const RENDER_PASS_STATE &rp_state, uint32_t subpass, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1893 | const AttachmentViewGenVector &attachment_views, const ResourceUsageTag tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1894 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1895 | const ResourceAccessState empty_infill; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1896 | for (const auto &transition : transitions) { |
| 1897 | const auto prev_pass = transition.prev_pass; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1898 | const auto &view_gen = attachment_views[transition.attachment]; |
| 1899 | if (!view_gen.IsValid()) continue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1900 | |
| 1901 | const auto *trackback = GetTrackBackFromSubpass(prev_pass); |
| 1902 | assert(trackback); |
| 1903 | |
| 1904 | // Import the attachments into the current context |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 1905 | const auto *prev_context = trackback->source_subpass; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1906 | assert(prev_context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1907 | const auto address_type = view_gen.GetAddressType(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1908 | auto &target_map = GetAccessStateMap(address_type); |
| 1909 | ApplySubpassTransitionBarriersAction barrier_action(trackback->barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1910 | prev_context->ResolveAccessRange(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action, &target_map, |
| 1911 | &empty_infill); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1912 | } |
| 1913 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1914 | // If there were no transitions skip this global map walk |
| 1915 | if (transitions.size()) { |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1916 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1917 | ApplyToContext(apply_pending_action); |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1918 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1919 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1920 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1921 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, CMD_TYPE cmd_type) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1922 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1923 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1924 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 1925 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1926 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1927 | return skip; |
| 1928 | } |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1929 | const char *caller_name = CommandTypeString(cmd_type); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1930 | |
| 1931 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1932 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1933 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1934 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1935 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1936 | for (const auto &stage_state : pipe->stage_state) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 1937 | const auto raster_state = pipe->RasterizationState(); |
| 1938 | 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] | 1939 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1940 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1941 | for (const auto &set_binding : stage_state.descriptor_uses) { |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 1942 | 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] | 1943 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1944 | set_binding.first.binding); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1945 | const auto descriptor_type = binding_it.GetType(); |
| 1946 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1947 | auto array_idx = 0; |
| 1948 | |
| 1949 | if (binding_it.IsVariableDescriptorCount()) { |
| 1950 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1951 | } |
| 1952 | SyncStageAccessIndex sync_index = |
| 1953 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1954 | |
| 1955 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1956 | uint32_t index = i - index_range.start; |
| 1957 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1958 | switch (descriptor->GetClass()) { |
| 1959 | case DescriptorClass::ImageSampler: |
| 1960 | case DescriptorClass::Image: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1961 | if (descriptor->Invalid()) { |
| 1962 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1963 | } |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1964 | |
| 1965 | // NOTE: ImageSamplerDescriptor inherits from ImageDescriptor, so this cast works for both types. |
| 1966 | const auto *image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 1967 | const auto *img_view_state = image_descriptor->GetImageViewState(); |
| 1968 | VkImageLayout image_layout = image_descriptor->GetImageLayout(); |
| 1969 | |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1970 | HazardResult hazard; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 1971 | // NOTE: 2D ImageViews of VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT Images are not allowed in |
| 1972 | // Descriptors, so we do not have to worry about depth slicing here. |
| 1973 | // See: VUID 00343 |
| 1974 | assert(!img_view_state->IsDepthSliced()); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1975 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1976 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1977 | |
| 1978 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1979 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1980 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1981 | // Input attachments are subject to raster ordering rules |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1982 | hazard = |
| 1983 | current_context_->DetectHazard(*img_state, sync_index, subresource_range, SyncOrdering::kRaster, |
| 1984 | offset, extent, img_view_state->IsDepthSliced()); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1985 | } else { |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 1986 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
| 1987 | img_view_state->IsDepthSliced()); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1988 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1989 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1990 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1991 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1992 | img_view_state->image_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1993 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 1994 | ", index %" PRIu32 ". Access info %s.", |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 1995 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1996 | sync_state_->report_data->FormatHandle(img_view_state->image_view()).c_str(), |
| 1997 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 1998 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1999 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 2000 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2001 | set_binding.first.binding, index, FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2002 | } |
| 2003 | break; |
| 2004 | } |
| 2005 | case DescriptorClass::TexelBuffer: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2006 | const auto *texel_descriptor = static_cast<const TexelDescriptor *>(descriptor); |
| 2007 | if (texel_descriptor->Invalid()) { |
| 2008 | continue; |
| 2009 | } |
| 2010 | const auto *buf_view_state = texel_descriptor->GetBufferViewState(); |
| 2011 | const auto *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2012 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2013 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 2014 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2015 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2016 | buf_view_state->buffer_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2017 | "%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] | 2018 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2019 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view()).c_str(), |
| 2020 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 2021 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2022 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2023 | string_VkDescriptorType(descriptor_type), set_binding.first.binding, index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2024 | FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2025 | } |
| 2026 | break; |
| 2027 | } |
| 2028 | case DescriptorClass::GeneralBuffer: { |
| 2029 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2030 | if (buffer_descriptor->Invalid()) { |
| 2031 | continue; |
| 2032 | } |
| 2033 | const auto *buf_state = buffer_descriptor->GetBufferState(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2034 | const ResourceAccessRange range = |
| 2035 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2036 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 2037 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2038 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2039 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2040 | "%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] | 2041 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2042 | sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 2043 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 2044 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 2045 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2046 | string_VkDescriptorType(descriptor_type), set_binding.first.binding, index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2047 | FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2048 | } |
| 2049 | break; |
| 2050 | } |
| 2051 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2052 | default: |
| 2053 | break; |
| 2054 | } |
| 2055 | } |
| 2056 | } |
| 2057 | } |
| 2058 | return skip; |
| 2059 | } |
| 2060 | |
| 2061 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2062 | const ResourceUsageTag tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2063 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2064 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2065 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2066 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2067 | return; |
| 2068 | } |
| 2069 | |
| 2070 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 2071 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 2072 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2073 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 2074 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2075 | for (const auto &stage_state : pipe->stage_state) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2076 | const auto raster_state = pipe->RasterizationState(); |
| 2077 | 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] | 2078 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2079 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2080 | for (const auto &set_binding : stage_state.descriptor_uses) { |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 2081 | 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] | 2082 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2083 | set_binding.first.binding); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2084 | const auto descriptor_type = binding_it.GetType(); |
| 2085 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 2086 | auto array_idx = 0; |
| 2087 | |
| 2088 | if (binding_it.IsVariableDescriptorCount()) { |
| 2089 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 2090 | } |
| 2091 | SyncStageAccessIndex sync_index = |
| 2092 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 2093 | |
| 2094 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 2095 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 2096 | switch (descriptor->GetClass()) { |
| 2097 | case DescriptorClass::ImageSampler: |
| 2098 | case DescriptorClass::Image: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2099 | // NOTE: ImageSamplerDescriptor inherits from ImageDescriptor, so this cast works for both types. |
| 2100 | const auto *image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 2101 | if (image_descriptor->Invalid()) { |
| 2102 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2103 | } |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2104 | const auto *img_view_state = image_descriptor->GetImageViewState(); |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 2105 | // NOTE: 2D ImageViews of VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT Images are not allowed in |
| 2106 | // Descriptors, so we do not have to worry about depth slicing here. |
| 2107 | // See: VUID 00343 |
| 2108 | assert(!img_view_state->IsDepthSliced()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2109 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2110 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2111 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 2112 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 2113 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kRaster, |
| 2114 | img_view_state->normalized_subresource_range, offset, extent, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2115 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2116 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kNonAttachment, |
| 2117 | img_view_state->normalized_subresource_range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2118 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2119 | break; |
| 2120 | } |
| 2121 | case DescriptorClass::TexelBuffer: { |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2122 | const auto *texel_descriptor = static_cast<const TexelDescriptor *>(descriptor); |
| 2123 | if (texel_descriptor->Invalid()) { |
| 2124 | continue; |
| 2125 | } |
| 2126 | const auto *buf_view_state = texel_descriptor->GetBufferViewState(); |
| 2127 | const auto *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2128 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2129 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2130 | break; |
| 2131 | } |
| 2132 | case DescriptorClass::GeneralBuffer: { |
| 2133 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 2134 | if (buffer_descriptor->Invalid()) { |
| 2135 | continue; |
| 2136 | } |
| 2137 | const auto *buf_state = buffer_descriptor->GetBufferState(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2138 | const ResourceAccessRange range = |
| 2139 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2140 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2141 | break; |
| 2142 | } |
| 2143 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2144 | default: |
| 2145 | break; |
| 2146 | } |
| 2147 | } |
| 2148 | } |
| 2149 | } |
| 2150 | } |
| 2151 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2152 | 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] | 2153 | bool skip = false; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2154 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2155 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2156 | return skip; |
| 2157 | } |
| 2158 | |
| 2159 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2160 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2161 | const auto &binding_descriptions_size = pipe->vertex_input_state->binding_descriptions.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2162 | |
| 2163 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2164 | const auto &binding_description = pipe->vertex_input_state->binding_descriptions[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2165 | if (binding_description.binding < binding_buffers_size) { |
| 2166 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2167 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2168 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2169 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2170 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2171 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2172 | 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] | 2173 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2174 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2175 | 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] | 2176 | CommandTypeString(cmd_type), string_SyncHazard(hazard.hazard), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2177 | sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 2178 | 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] | 2179 | } |
| 2180 | } |
| 2181 | } |
| 2182 | return skip; |
| 2183 | } |
| 2184 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2185 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag tag) { |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2186 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2187 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2188 | return; |
| 2189 | } |
| 2190 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2191 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2192 | const auto &binding_descriptions_size = pipe->vertex_input_state->binding_descriptions.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2193 | |
| 2194 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2195 | const auto &binding_description = pipe->vertex_input_state->binding_descriptions[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2196 | if (binding_description.binding < binding_buffers_size) { |
| 2197 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2198 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2199 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2200 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2201 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2202 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2203 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ, |
| 2204 | SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | } |
| 2208 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2209 | 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] | 2210 | bool skip = false; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2211 | 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] | 2212 | return skip; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2213 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2214 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2215 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2216 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2217 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2218 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2219 | 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] | 2220 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2221 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2222 | 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] | 2223 | CommandTypeString(cmd_type), string_SyncHazard(hazard.hazard), |
| 2224 | sync_state_->report_data->FormatHandle(index_buf_state->buffer()).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2225 | 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] | 2226 | } |
| 2227 | |
| 2228 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2229 | // We will detect more accurate range in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2230 | skip |= ValidateDrawVertex(UINT32_MAX, 0, cmd_type); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2231 | return skip; |
| 2232 | } |
| 2233 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2234 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag tag) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2235 | 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] | 2236 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2237 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2238 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2239 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2240 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2241 | 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] | 2242 | |
| 2243 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2244 | // We will detect more accurate range in the future. |
| 2245 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 2246 | } |
| 2247 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2248 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(CMD_TYPE cmd_type) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2249 | bool skip = false; |
| 2250 | if (!current_renderpass_context_) return skip; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2251 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(GetExecutionContext(), *cb_state_.get(), cmd_type); |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2252 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2253 | } |
| 2254 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2255 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2256 | if (current_renderpass_context_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2257 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), tag); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2258 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2259 | } |
| 2260 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2261 | QueueId CommandBufferAccessContext::GetQueueId() const { return QueueSyncState::kQueueIdInvalid; } |
| 2262 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2263 | 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] | 2264 | const VkRect2D &render_area, |
| 2265 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2266 | // Create an access context the current renderpass. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2267 | const auto barrier_tag = NextCommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
| 2268 | const auto load_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kLoadOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2269 | 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] | 2270 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2271 | current_renderpass_context_->RecordBeginRenderPass(barrier_tag, load_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2272 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2273 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2274 | } |
| 2275 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2276 | ResourceUsageTag CommandBufferAccessContext::RecordNextSubpass(const CMD_TYPE cmd_type) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2277 | assert(current_renderpass_context_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2278 | if (!current_renderpass_context_) return NextCommandTag(cmd_type); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2279 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2280 | auto store_tag = NextCommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kStoreOp); |
| 2281 | auto barrier_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
| 2282 | auto load_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kLoadOp); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2283 | |
| 2284 | current_renderpass_context_->RecordNextSubpass(store_tag, barrier_tag, load_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2285 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2286 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2287 | } |
| 2288 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2289 | ResourceUsageTag CommandBufferAccessContext::RecordEndRenderPass(const CMD_TYPE cmd_type) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2290 | assert(current_renderpass_context_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2291 | if (!current_renderpass_context_) return NextCommandTag(cmd_type); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2292 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2293 | auto store_tag = NextCommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kStoreOp); |
| 2294 | auto barrier_tag = NextSubcommandTag(cmd_type, ResourceUsageRecord::SubcommandType::kSubpassTransition); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2295 | |
| 2296 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, store_tag, barrier_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2297 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2298 | current_renderpass_context_ = nullptr; |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2299 | return barrier_tag; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2300 | } |
| 2301 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2302 | void CommandBufferAccessContext::RecordDestroyEvent(VkEvent event) { |
| 2303 | // Erase is okay with the key not being |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 2304 | auto event_state = sync_state_->Get<EVENT_STATE>(event); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2305 | if (event_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 2306 | GetCurrentEventsContext()->Destroy(event_state.get()); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2307 | } |
| 2308 | } |
| 2309 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2310 | // The is the recorded cb context |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2311 | bool CommandBufferAccessContext::ValidateFirstUse(CommandExecutionContext *proxy_context, const char *func_name, |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2312 | uint32_t index) const { |
| 2313 | assert(proxy_context); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2314 | SyncEventsContext *const events_context = proxy_context->GetCurrentEventsContext(); |
| 2315 | AccessContext *const access_context = proxy_context->GetCurrentAccessContext(); |
| 2316 | const QueueId queue_id = proxy_context->GetQueueId(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2317 | const ResourceUsageTag base_tag = proxy_context->GetTagLimit(); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2318 | bool skip = false; |
| 2319 | ResourceUsageRange tag_range = {0, 0}; |
| 2320 | const AccessContext *recorded_context = GetCurrentAccessContext(); |
| 2321 | assert(recorded_context); |
| 2322 | HazardResult hazard; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2323 | 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] | 2324 | uint32_t index) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2325 | const auto handle = exec_context.Handle(); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2326 | const auto recorded_handle = cb_state_->commandBuffer(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2327 | const auto *report_data = sync_state_->report_data; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2328 | return sync_state_->LogError(handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2329 | "%s: Hazard %s for entry %" PRIu32 ", %s, Recorded access info %s. Access info %s.", func_name, |
| 2330 | string_SyncHazard(hazard.hazard), index, report_data->FormatHandle(recorded_handle).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2331 | FormatUsage(*hazard.recorded_access).c_str(), exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2332 | }; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2333 | const ReplayTrackbackBarriersAction *replay_context = nullptr; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2334 | for (const auto &sync_op : sync_ops_) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2335 | // we update the range to any include layout transition first use writes, |
| 2336 | // as they are stored along with the source scope (as effective barrier) when recorded |
| 2337 | tag_range.end = sync_op.tag + 1; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 2338 | 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] | 2339 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2340 | hazard = recorded_context->DetectFirstUseHazard(tag_range, *access_context, replay_context); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2341 | if (hazard.hazard) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2342 | skip |= log_msg(hazard, *proxy_context, func_name, index); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2343 | } |
| 2344 | // 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] | 2345 | // Record the barrier into the proxy context. |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2346 | 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] | 2347 | replay_context = sync_op.sync_op->GetReplayTrackback(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2348 | tag_range.begin = tag_range.end; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2349 | } |
| 2350 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2351 | // Renderpasses may not cross command buffer boundaries |
| 2352 | assert(replay_context == nullptr); |
| 2353 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2354 | // and anything after the last syncop |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2355 | tag_range.end = ResourceUsageRecord::kMaxIndex; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2356 | hazard = recorded_context->DetectFirstUseHazard(tag_range, *access_context, replay_context); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2357 | if (hazard.hazard) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2358 | skip |= log_msg(hazard, *proxy_context, func_name, index); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | return skip; |
| 2362 | } |
| 2363 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2364 | void CommandBufferAccessContext::RecordExecutedCommandBuffer(const CommandBufferAccessContext &recorded_cb_context) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2365 | SyncEventsContext *const events_context = GetCurrentEventsContext(); |
| 2366 | AccessContext *const access_context = GetCurrentAccessContext(); |
| 2367 | const QueueId queue_id = GetQueueId(); |
| 2368 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2369 | const AccessContext *recorded_context = recorded_cb_context.GetCurrentAccessContext(); |
| 2370 | assert(recorded_context); |
| 2371 | |
| 2372 | // Just run through the barriers ignoring the usage from the recorded context, as Resolve will overwrite outdated state |
| 2373 | const ResourceUsageTag base_tag = GetTagLimit(); |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2374 | for (const auto &sync_op : recorded_cb_context.GetSyncOps()) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2375 | // we update the range to any include layout transition first use writes, |
| 2376 | // 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] | 2377 | 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] | 2378 | } |
| 2379 | |
| 2380 | ResourceUsageRange tag_range = ImportRecordedAccessLog(recorded_cb_context); |
| 2381 | 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] | 2382 | ResolveExecutedCommandBuffer(*recorded_context, tag_range.begin); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2383 | } |
| 2384 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 2385 | void CommandBufferAccessContext::ResolveExecutedCommandBuffer(const AccessContext &recorded_context, ResourceUsageTag offset) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2386 | auto tag_offset = [offset](ResourceAccessState *access) { access->OffsetTag(offset); }; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 2387 | GetCurrentAccessContext()->ResolveFromContext(tag_offset, recorded_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2388 | } |
| 2389 | |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2390 | ResourceUsageRange CommandExecutionContext::ImportRecordedAccessLog(const CommandBufferAccessContext &recorded_context) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2391 | // The execution references ensure lifespan for the referenced child CB's... |
| 2392 | ResourceUsageRange tag_range(GetTagLimit(), 0); |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2393 | InsertRecordedAccessLogEntries(recorded_context); |
| 2394 | tag_range.end = GetTagLimit(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2395 | return tag_range; |
| 2396 | } |
| 2397 | |
John Zulauf | 3c788ef | 2022-02-22 12:12:30 -0700 | [diff] [blame] | 2398 | void CommandBufferAccessContext::InsertRecordedAccessLogEntries(const CommandBufferAccessContext &recorded_context) { |
| 2399 | cbs_referenced_.emplace(recorded_context.GetCBStateShared()); |
| 2400 | access_log_.insert(access_log_.end(), recorded_context.access_log_.cbegin(), recorded_context.access_log_.end()); |
| 2401 | } |
| 2402 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2403 | ResourceUsageTag CommandBufferAccessContext::NextSubcommandTag(CMD_TYPE command, ResourceUsageRecord::SubcommandType subcommand) { |
| 2404 | ResourceUsageTag next = access_log_.size(); |
| 2405 | access_log_.emplace_back(command, command_number_, subcommand, ++subcommand_number_, cb_state_.get(), reset_count_); |
| 2406 | return next; |
| 2407 | } |
| 2408 | |
| 2409 | ResourceUsageTag CommandBufferAccessContext::NextCommandTag(CMD_TYPE command, ResourceUsageRecord::SubcommandType subcommand) { |
| 2410 | command_number_++; |
| 2411 | subcommand_number_ = 0; |
| 2412 | ResourceUsageTag next = access_log_.size(); |
| 2413 | access_log_.emplace_back(command, command_number_, subcommand, subcommand_number_, cb_state_.get(), reset_count_); |
| 2414 | return next; |
| 2415 | } |
| 2416 | |
| 2417 | ResourceUsageTag CommandBufferAccessContext::NextIndexedCommandTag(CMD_TYPE command, uint32_t index) { |
| 2418 | if (index == 0) { |
| 2419 | return NextCommandTag(command, ResourceUsageRecord::SubcommandType::kIndex); |
| 2420 | } |
| 2421 | return NextSubcommandTag(command, ResourceUsageRecord::SubcommandType::kIndex); |
| 2422 | } |
| 2423 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2424 | void CommandBufferAccessContext::RecordSyncOp(SyncOpPointer &&sync_op) { |
| 2425 | auto tag = sync_op->Record(this); |
| 2426 | // As renderpass operations can have side effects on the command buffer access context, |
| 2427 | // update the sync operation to record these if any. |
| 2428 | if (current_renderpass_context_) { |
| 2429 | const auto &rpc = *current_renderpass_context_; |
| 2430 | sync_op->SetReplayContext(rpc.GetCurrentSubpass(), rpc.GetReplayContext()); |
| 2431 | } |
| 2432 | sync_ops_.emplace_back(tag, std::move(sync_op)); |
| 2433 | } |
| 2434 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2435 | class HazardDetectFirstUse { |
| 2436 | public: |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2437 | HazardDetectFirstUse(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range, |
| 2438 | const ReplayTrackbackBarriersAction *replay_barrier) |
| 2439 | : recorded_use_(recorded_use), tag_range_(tag_range), replay_barrier_(replay_barrier) {} |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2440 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2441 | if (replay_barrier_) { |
| 2442 | // Intentional copy to apply the replay barrier |
| 2443 | auto access = pos->second; |
| 2444 | (*replay_barrier_)(&access); |
| 2445 | return access.DetectHazard(recorded_use_, tag_range_); |
| 2446 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2447 | return pos->second.DetectHazard(recorded_use_, tag_range_); |
| 2448 | } |
| 2449 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
| 2450 | return pos->second.DetectAsyncHazard(recorded_use_, tag_range_, start_tag); |
| 2451 | } |
| 2452 | |
| 2453 | private: |
| 2454 | const ResourceAccessState &recorded_use_; |
| 2455 | const ResourceUsageRange &tag_range_; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2456 | const ReplayTrackbackBarriersAction *replay_barrier_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2457 | }; |
| 2458 | |
| 2459 | // This is called with the *recorded* command buffers access context, with the *active* access context pass in, againsts which |
| 2460 | // hazards will be detected |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2461 | HazardResult AccessContext::DetectFirstUseHazard(const ResourceUsageRange &tag_range, const AccessContext &access_context, |
| 2462 | const ReplayTrackbackBarriersAction *replay_barrier) const { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2463 | HazardResult hazard; |
| 2464 | for (const auto address_type : kAddressTypes) { |
| 2465 | const auto &recorded_access_map = GetAccessStateMap(address_type); |
| 2466 | for (const auto &recorded_access : recorded_access_map) { |
| 2467 | // Cull any entries not in the current tag range |
| 2468 | if (!recorded_access.second.FirstAccessInTagRange(tag_range)) continue; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2469 | HazardDetectFirstUse detector(recorded_access.second, tag_range, replay_barrier); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2470 | hazard = access_context.DetectHazard(address_type, detector, recorded_access.first, DetectOptions::kDetectAll); |
| 2471 | if (hazard.hazard) break; |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | return hazard; |
| 2476 | } |
| 2477 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2478 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const CommandExecutionContext &exec_context, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2479 | const CMD_BUFFER_STATE &cmd_buffer, CMD_TYPE cmd_type) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2480 | bool skip = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2481 | const auto &sync_state = exec_context.GetSyncState(); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2482 | const auto *pipe = cmd_buffer.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2483 | if (!pipe) { |
| 2484 | return skip; |
| 2485 | } |
| 2486 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2487 | const auto raster_state = pipe->RasterizationState(); |
| 2488 | if (raster_state && raster_state->rasterizerDiscardEnable) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2489 | return skip; |
| 2490 | } |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2491 | const char *caller_name = CommandTypeString(cmd_type); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2492 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2493 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2494 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2495 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2496 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2497 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2498 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2499 | if (location >= subpass.colorAttachmentCount || |
| 2500 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2501 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2502 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2503 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2504 | if (!view_gen.IsValid()) continue; |
| 2505 | HazardResult hazard = |
| 2506 | current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2507 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2508 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2509 | const VkImageView view_handle = view_gen.GetViewState()->image_view(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2510 | skip |= sync_state.LogError(view_handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2511 | "%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] | 2512 | caller_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2513 | sync_state.report_data->FormatHandle(view_handle).c_str(), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2514 | sync_state.report_data->FormatHandle(cmd_buffer.commandBuffer()).c_str(), |
| 2515 | cmd_buffer.activeSubpass, location, exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2516 | } |
| 2517 | } |
| 2518 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2519 | |
| 2520 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2521 | // 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] | 2522 | const auto ds_state = pipe->DepthStencilState(); |
| 2523 | const uint32_t depth_stencil_attachment = GetSubpassDepthStencilAttachmentIndex(ds_state, subpass.pDepthStencilAttachment); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2524 | |
| 2525 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2526 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2527 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2528 | bool depth_write = false, stencil_write = false; |
| 2529 | |
| 2530 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2531 | 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] | 2532 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2533 | depth_write = true; |
| 2534 | } |
| 2535 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2536 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2537 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2538 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2539 | if (!FormatIsDepthOnly(view_state.create_info.format) && ds_state->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2540 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2541 | stencil_write = true; |
| 2542 | } |
| 2543 | |
| 2544 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2545 | if (depth_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2546 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2547 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2548 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2549 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2550 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2551 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2552 | "%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] | 2553 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2554 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2555 | 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] | 2556 | exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2557 | } |
| 2558 | } |
| 2559 | if (stencil_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2560 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2561 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2562 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2563 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2564 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2565 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2566 | "%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] | 2567 | caller_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2568 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2569 | 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] | 2570 | exec_context.FormatHazard(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2571 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2572 | } |
| 2573 | } |
| 2574 | return skip; |
| 2575 | } |
| 2576 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2577 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd_buffer, const ResourceUsageTag tag) { |
| 2578 | const auto *pipe = cmd_buffer.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2579 | if (!pipe) { |
| 2580 | return; |
| 2581 | } |
| 2582 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2583 | const auto *raster_state = pipe->RasterizationState(); |
| 2584 | if (raster_state && raster_state->rasterizerDiscardEnable) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2585 | return; |
| 2586 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2587 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2588 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2589 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2590 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2591 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2592 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2593 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2594 | if (location >= subpass.colorAttachmentCount || |
| 2595 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2596 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2597 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2598 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2599 | current_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2600 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment, |
| 2601 | tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2602 | } |
| 2603 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2604 | |
| 2605 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2606 | // 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] | 2607 | const auto *ds_state = pipe->DepthStencilState(); |
| 2608 | const uint32_t depth_stencil_attachment = GetSubpassDepthStencilAttachmentIndex(ds_state, subpass.pDepthStencilAttachment); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2609 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2610 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2611 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2612 | bool depth_write = false, stencil_write = false; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2613 | const bool has_depth = 0 != (view_state.normalized_subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 2614 | 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] | 2615 | |
| 2616 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2617 | if (has_depth && !FormatIsStencilOnly(view_state.create_info.format) && ds_state->depthTestEnable && |
| 2618 | ds_state->depthWriteEnable && IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2619 | depth_write = true; |
| 2620 | } |
| 2621 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2622 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2623 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2624 | // PHASE1 TODO: These validation should be in core_checks. |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2625 | if (has_stencil && !FormatIsDepthOnly(view_state.create_info.format) && ds_state->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2626 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2627 | stencil_write = true; |
| 2628 | } |
| 2629 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2630 | if (depth_write || stencil_write) { |
| 2631 | const auto ds_gentype = view_gen.GetDepthStencilRenderAreaGenType(depth_write, stencil_write); |
| 2632 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2633 | current_context.UpdateAccessState(view_gen, ds_gentype, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2634 | SyncOrdering::kDepthStencilAttachment, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2635 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2636 | } |
| 2637 | } |
| 2638 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2639 | bool RenderPassAccessContext::ValidateNextSubpass(const CommandExecutionContext &exec_context, CMD_TYPE cmd_type) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2640 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2641 | bool skip = false; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2642 | 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] | 2643 | current_subpass_); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2644 | skip |= CurrentContext().ValidateStoreOperation(exec_context, *rp_state_, render_area_, current_subpass_, attachment_views_, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2645 | cmd_type); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2646 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2647 | const auto next_subpass = current_subpass_ + 1; |
ziga-lunarg | 31a3e77 | 2022-03-22 11:48:46 +0100 | [diff] [blame] | 2648 | if (next_subpass >= subpass_contexts_.size()) { |
| 2649 | return skip; |
| 2650 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2651 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2652 | skip |= |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2653 | 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] | 2654 | if (!skip) { |
| 2655 | // To avoid complex (and buggy) duplication of the affect of layout transitions on load operations, we'll record them |
| 2656 | // on a copy of the (empty) next context. |
| 2657 | // Note: The resource access map should be empty so hopefully this copy isn't too horrible from a perf POV. |
| 2658 | AccessContext temp_context(next_context); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2659 | temp_context.RecordLayoutTransitions(*rp_state_, next_subpass, attachment_views_, kInvalidTag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2660 | skip |= |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2661 | 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] | 2662 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2663 | return skip; |
| 2664 | } |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2665 | bool RenderPassAccessContext::ValidateEndRenderPass(const CommandExecutionContext &exec_context, CMD_TYPE cmd_type) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2666 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2667 | bool skip = false; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2668 | 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] | 2669 | current_subpass_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2670 | skip |= CurrentContext().ValidateStoreOperation(exec_context, *rp_state_, render_area_, current_subpass_, attachment_views_, |
| 2671 | cmd_type); |
| 2672 | skip |= ValidateFinalSubpassLayoutTransitions(exec_context, cmd_type); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2673 | return skip; |
| 2674 | } |
| 2675 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2676 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy() const { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2677 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, attachment_views_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2678 | } |
| 2679 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2680 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const CommandExecutionContext &exec_context, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2681 | CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2682 | bool skip = false; |
| 2683 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2684 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2685 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2686 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2687 | // to apply and only copy then, if this proves a hot spot. |
| 2688 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2689 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2690 | // Validate the "finalLayout" transitions to external |
| 2691 | // Get them from where there we're hidding in the extra entry. |
| 2692 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2693 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2694 | const auto &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2695 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2696 | assert(trackback.source_subpass); // Transitions are given implicit transitions if the StateTracker is working correctly |
| 2697 | auto *context = trackback.source_subpass; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2698 | |
| 2699 | if (transition.prev_pass == current_subpass_) { |
| 2700 | if (!proxy_for_current) { |
| 2701 | // 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] | 2702 | proxy_for_current.reset(CreateStoreResolveProxy()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2703 | } |
| 2704 | context = proxy_for_current.get(); |
| 2705 | } |
| 2706 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2707 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2708 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2709 | auto hazard = context->DetectImageBarrierHazard(view_gen, merged_barrier, AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2710 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 2711 | const char *func_name = CommandTypeString(cmd_type); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2712 | if (hazard.tag == kInvalidTag) { |
| 2713 | // Hazard vs. ILT |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2714 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2715 | rp_state_->renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 2716 | "%s: Hazard %s vs. store/resolve operations in subpass %" PRIu32 " for attachment %" PRIu32 |
| 2717 | " final image layout transition (old_layout: %s, new_layout: %s).", |
| 2718 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2719 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout)); |
| 2720 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2721 | skip |= exec_context.GetSyncState().LogError( |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2722 | rp_state_->renderPass(), string_SyncHazardVUID(hazard.hazard), |
| 2723 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
| 2724 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 2725 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2726 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 2727 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 2728 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2729 | } |
| 2730 | } |
| 2731 | return skip; |
| 2732 | } |
| 2733 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2734 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2735 | // Add layout transitions... |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2736 | subpass_contexts_[current_subpass_].RecordLayoutTransitions(*rp_state_, current_subpass_, attachment_views_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2737 | } |
| 2738 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2739 | void RenderPassAccessContext::RecordLoadOperations(const ResourceUsageTag tag) { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2740 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2741 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2742 | |
| 2743 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2744 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2745 | const AttachmentViewGen &view_gen = attachment_views_[i]; |
| 2746 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2747 | |
| 2748 | const auto &ci = attachment_ci[i]; |
| 2749 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2750 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2751 | const bool is_color = !(has_depth || has_stencil); |
| 2752 | |
| 2753 | if (is_color) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2754 | const SyncStageAccessIndex load_op = ColorLoadUsage(ci.loadOp); |
| 2755 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2756 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, load_op, |
| 2757 | SyncOrdering::kColorAttachment, tag); |
| 2758 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2759 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2760 | if (has_depth) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2761 | const SyncStageAccessIndex load_op = DepthStencilLoadUsage(ci.loadOp); |
| 2762 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2763 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_op, |
| 2764 | SyncOrdering::kDepthStencilAttachment, tag); |
| 2765 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2766 | } |
| 2767 | if (has_stencil) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2768 | const SyncStageAccessIndex load_op = DepthStencilLoadUsage(ci.stencilLoadOp); |
| 2769 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2770 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, load_op, |
| 2771 | SyncOrdering::kDepthStencilAttachment, tag); |
| 2772 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2773 | } |
| 2774 | } |
| 2775 | } |
| 2776 | } |
| 2777 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2778 | AttachmentViewGenVector RenderPassAccessContext::CreateAttachmentViewGen( |
| 2779 | const VkRect2D &render_area, const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
| 2780 | AttachmentViewGenVector view_gens; |
| 2781 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2782 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2783 | view_gens.reserve(attachment_views.size()); |
| 2784 | for (const auto *view : attachment_views) { |
| 2785 | view_gens.emplace_back(view, offset, extent); |
| 2786 | } |
| 2787 | return view_gens; |
| 2788 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2789 | RenderPassAccessContext::RenderPassAccessContext(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2790 | VkQueueFlags queue_flags, |
| 2791 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2792 | const AccessContext *external_context) |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2793 | : 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] | 2794 | // 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] | 2795 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2796 | replay_context_ = std::make_shared<ReplayRenderpassContext>(); |
| 2797 | auto &replay_subpass_contexts = replay_context_->subpass_contexts; |
| 2798 | replay_subpass_contexts.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2799 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2800 | 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] | 2801 | 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] | 2802 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2803 | attachment_views_ = CreateAttachmentViewGen(render_area, attachment_views); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2804 | } |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2805 | void RenderPassAccessContext::RecordBeginRenderPass(const ResourceUsageTag barrier_tag, const ResourceUsageTag load_tag) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2806 | assert(0 == current_subpass_); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2807 | subpass_contexts_[current_subpass_].SetStartTag(barrier_tag); |
| 2808 | RecordLayoutTransitions(barrier_tag); |
| 2809 | RecordLoadOperations(load_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2810 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2811 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2812 | void RenderPassAccessContext::RecordNextSubpass(const ResourceUsageTag store_tag, const ResourceUsageTag barrier_tag, |
| 2813 | const ResourceUsageTag load_tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2814 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2815 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
| 2816 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2817 | |
ziga-lunarg | 31a3e77 | 2022-03-22 11:48:46 +0100 | [diff] [blame] | 2818 | if (current_subpass_ + 1 >= subpass_contexts_.size()) { |
| 2819 | return; |
| 2820 | } |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 2821 | // Move to the next sub-command for the new subpass. The resolve and store are logically part of the previous |
| 2822 | // 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] | 2823 | current_subpass_++; |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2824 | subpass_contexts_[current_subpass_].SetStartTag(barrier_tag); |
| 2825 | RecordLayoutTransitions(barrier_tag); |
| 2826 | RecordLoadOperations(load_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2827 | } |
| 2828 | |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2829 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const ResourceUsageTag store_tag, |
| 2830 | const ResourceUsageTag barrier_tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2831 | // Add the resolve and store accesses |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2832 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
| 2833 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, store_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2834 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2835 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2836 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2837 | |
| 2838 | // Add the "finalLayout" transitions to external |
| 2839 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2840 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2841 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2842 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2843 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2844 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2845 | const AttachmentViewGen &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2846 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2847 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.source_subpass); |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 2848 | ApplyBarrierOpsFunctor<PipelineBarrierOp> barrier_action(true /* resolve */, last_trackback.barriers.size(), barrier_tag); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2849 | for (const auto &barrier : last_trackback.barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2850 | barrier_action.EmplaceBack(PipelineBarrierOp(QueueSyncState::kQueueIdInvalid, barrier, true)); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2851 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2852 | external_context->ApplyUpdateAction(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2853 | } |
| 2854 | } |
| 2855 | |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2856 | SyncExecScope SyncExecScope::MakeSrc(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param, |
| 2857 | const VkPipelineStageFlags2KHR disabled_feature_mask) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2858 | SyncExecScope result; |
| 2859 | result.mask_param = mask_param; |
John Zulauf | 06f6f1e | 2022-04-19 15:28:11 -0600 | [diff] [blame] | 2860 | 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] | 2861 | result.exec_scope = sync_utils::WithEarlierPipelineStages(result.expanded_mask); |
Jeremy Gebben | 87fd042 | 2022-06-08 15:43:47 -0600 | [diff] [blame] | 2862 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2863 | return result; |
| 2864 | } |
| 2865 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2866 | SyncExecScope SyncExecScope::MakeDst(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2867 | SyncExecScope result; |
| 2868 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2869 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2870 | result.exec_scope = sync_utils::WithLaterPipelineStages(result.expanded_mask); |
Jeremy Gebben | 87fd042 | 2022-06-08 15:43:47 -0600 | [diff] [blame] | 2871 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2872 | return result; |
| 2873 | } |
| 2874 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 2875 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst) |
| 2876 | : src_exec_scope(src), src_access_scope(0), dst_exec_scope(dst), dst_access_scope(0) {} |
| 2877 | |
| 2878 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst, const SyncBarrier::AllAccess &) |
| 2879 | : 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] | 2880 | |
| 2881 | template <typename Barrier> |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 2882 | SyncBarrier::SyncBarrier(const Barrier &barrier, const SyncExecScope &src, const SyncExecScope &dst) |
| 2883 | : src_exec_scope(src), |
| 2884 | src_access_scope(SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask)), |
| 2885 | dst_exec_scope(dst), |
| 2886 | dst_access_scope(SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask)) {} |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2887 | |
| 2888 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &subpass) { |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2889 | const auto barrier = lvl_find_in_chain<VkMemoryBarrier2KHR>(subpass.pNext); |
| 2890 | if (barrier) { |
| 2891 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier->srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2892 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2893 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier->srcAccessMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2894 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2895 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier->dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2896 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2897 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier->dstAccessMask); |
| 2898 | |
| 2899 | } else { |
| 2900 | auto src = SyncExecScope::MakeSrc(queue_flags, subpass.srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2901 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2902 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, subpass.srcAccessMask); |
| 2903 | |
| 2904 | auto dst = SyncExecScope::MakeDst(queue_flags, subpass.dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2905 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2906 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, subpass.dstAccessMask); |
| 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | template <typename Barrier> |
| 2911 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const Barrier &barrier) { |
| 2912 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 2913 | src_exec_scope = src.exec_scope; |
| 2914 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
| 2915 | |
| 2916 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2917 | dst_exec_scope = dst.exec_scope; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2918 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2919 | } |
| 2920 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2921 | // Apply a list of barriers, without resolving pending state, useful for subpass layout transitions |
| 2922 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2923 | const UntaggedScopeOps scope; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2924 | for (const auto &barrier : barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2925 | ApplyBarrier(scope, barrier, layout_transition); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2929 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2930 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2931 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2932 | void ResourceAccessState::ApplyBarriersImmediate(const std::vector<SyncBarrier> &barriers) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2933 | 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] | 2934 | assert(pending_write_barriers.none()); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2935 | assert(!pending_write_dep_chain); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2936 | const UntaggedScopeOps scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2937 | for (const auto &barrier : barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 2938 | ApplyBarrier(scope, barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2939 | } |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 2940 | ApplyPendingBarriers(kInvalidTag); // There can't be any need for this tag |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2941 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2942 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2943 | HazardResult hazard; |
| 2944 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2945 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2946 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2947 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2948 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2949 | } |
| 2950 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2951 | // Write operation: |
| 2952 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2953 | // If reads exists -- test only against them because either: |
| 2954 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2955 | // * 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 |
| 2956 | // the current write happens after the reads, so just test the write against the reades |
| 2957 | // Otherwise test against last_write |
| 2958 | // |
| 2959 | // Look for casus belli for WAR |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2960 | if (last_reads.size()) { |
| 2961 | for (const auto &read_access : last_reads) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2962 | if (IsReadHazard(usage_stage, read_access)) { |
| 2963 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2964 | break; |
| 2965 | } |
| 2966 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2967 | } else if (last_write.any() && IsWriteHazard(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2968 | // Write-After-Write check -- if we have a previous write to test against |
| 2969 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2970 | } |
| 2971 | } |
| 2972 | return hazard; |
| 2973 | } |
| 2974 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2975 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrdering ordering_rule) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2976 | const auto &ordering = GetOrderingRules(ordering_rule); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2977 | return DetectHazard(usage_index, ordering); |
| 2978 | } |
| 2979 | |
| 2980 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const OrderingBarrier &ordering) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2981 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 2982 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2983 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2984 | const auto usage_stage = PipelineStageBit(usage_index); |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2985 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
| 2986 | const bool last_write_is_ordered = (last_write & ordering.access_scope).any(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2987 | if (IsRead(usage_bit)) { |
| 2988 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 2989 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 2990 | if (is_raw_hazard) { |
| 2991 | // NOTE: we know last_write is non-zero |
| 2992 | // See if the ordering rules save us from the simple RAW check above |
| 2993 | // First check to see if the current usage is covered by the ordering rules |
| 2994 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 2995 | const bool usage_is_ordered = |
| 2996 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 2997 | if (usage_is_ordered) { |
| 2998 | // Now see of the most recent write (or a subsequent read) are ordered |
| 2999 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(ordering)); |
| 3000 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3001 | } |
| 3002 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3003 | if (is_raw_hazard) { |
| 3004 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 3005 | } |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 3006 | } else if (usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION) { |
| 3007 | // For Image layout transitions, the barrier represents the first synchronization/access scope of the layout transition |
| 3008 | return DetectBarrierHazard(usage_index, ordering.exec_scope, ordering.access_scope); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3009 | } else { |
| 3010 | // Only check for WAW if there are no reads since last_write |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3011 | bool usage_write_is_ordered = (usage_bit & ordering.access_scope).any(); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3012 | if (last_reads.size()) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3013 | // Look for any WAR hazards outside the ordered set of stages |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3014 | VkPipelineStageFlags2KHR ordered_stages = 0; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3015 | if (usage_write_is_ordered) { |
| 3016 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
| 3017 | ordered_stages = GetOrderedStages(ordering); |
| 3018 | } |
| 3019 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 3020 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3021 | for (const auto &read_access : last_reads) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3022 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 3023 | if (IsReadHazard(usage_stage, read_access)) { |
| 3024 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3025 | break; |
| 3026 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3027 | } |
| 3028 | } |
John Zulauf | 2a344ca | 2021-09-09 17:07:19 -0600 | [diff] [blame] | 3029 | } else if (last_write.any() && !(last_write_is_ordered && usage_write_is_ordered)) { |
| 3030 | bool ilt_ilt_hazard = false; |
| 3031 | if ((usage_index == SYNC_IMAGE_LAYOUT_TRANSITION) && (usage_bit == last_write)) { |
| 3032 | // ILT after ILT is a special case where we check the 2nd access scope of the first ILT against the first access |
| 3033 | // scope of the second ILT, which has been passed (smuggled?) in the ordering barrier |
| 3034 | ilt_ilt_hazard = !(write_barriers & ordering.access_scope).any(); |
| 3035 | } |
| 3036 | if (ilt_ilt_hazard || IsWriteHazard(usage_bit)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3037 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3038 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 3039 | } |
| 3040 | } |
| 3041 | return hazard; |
| 3042 | } |
| 3043 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3044 | HazardResult ResourceAccessState::DetectHazard(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range) const { |
| 3045 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3046 | using Size = FirstAccesses::size_type; |
| 3047 | const auto &recorded_accesses = recorded_use.first_accesses_; |
| 3048 | Size count = recorded_accesses.size(); |
| 3049 | if (count) { |
| 3050 | const auto &last_access = recorded_accesses.back(); |
| 3051 | bool do_write_last = IsWrite(last_access.usage_index); |
| 3052 | if (do_write_last) --count; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3053 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3054 | for (Size i = 0; i < count; ++count) { |
| 3055 | const auto &first = recorded_accesses[i]; |
| 3056 | // Skip and quit logic |
| 3057 | if (first.tag < tag_range.begin) continue; |
| 3058 | if (first.tag >= tag_range.end) { |
| 3059 | do_write_last = false; // ignore last since we know it can't be in tag_range |
| 3060 | break; |
| 3061 | } |
| 3062 | |
| 3063 | hazard = DetectHazard(first.usage_index, first.ordering_rule); |
| 3064 | if (hazard.hazard) { |
| 3065 | hazard.AddRecordedAccess(first); |
| 3066 | break; |
| 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | if (do_write_last && tag_range.includes(last_access.tag)) { |
| 3071 | // Writes are a bit special... both for the "most recent" access logic, and layout transition specific logic |
| 3072 | OrderingBarrier barrier = GetOrderingRules(last_access.ordering_rule); |
| 3073 | if (last_access.usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION) { |
| 3074 | // Or in the layout first access scope as a barrier... IFF the usage is an ILT |
| 3075 | // this was saved off in the "apply barriers" logic to simplify ILT access checks as they straddle |
| 3076 | // the barrier that applies them |
| 3077 | barrier |= recorded_use.first_write_layout_ordering_; |
| 3078 | } |
| 3079 | // Any read stages present in the recorded context (this) are most recent to the write, and thus mask those stages in |
| 3080 | // the active context |
| 3081 | if (recorded_use.first_read_stages_) { |
| 3082 | // we need to ignore the first use read stage in the active context (so we add them to the ordering rule), |
| 3083 | // reads in the active context are not "most recent" as all recorded context operations are *after* them |
| 3084 | // This supresses only RAW checks for stages present in the recorded context, but not those only present in the |
| 3085 | // active context. |
| 3086 | barrier.exec_scope |= recorded_use.first_read_stages_; |
| 3087 | // if there are any first use reads, we suppress WAW by injecting the active context write in the ordering rule |
| 3088 | barrier.access_scope |= FlagBit(last_access.usage_index); |
| 3089 | } |
| 3090 | hazard = DetectHazard(last_access.usage_index, barrier); |
| 3091 | if (hazard.hazard) { |
| 3092 | hazard.AddRecordedAccess(last_access); |
| 3093 | } |
| 3094 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3095 | } |
| 3096 | return hazard; |
| 3097 | } |
| 3098 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3099 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3100 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index, const ResourceUsageTag start_tag) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3101 | HazardResult hazard; |
| 3102 | auto usage = FlagBit(usage_index); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 3103 | // Async checks need to not go back further than the start of the subpass, as we only want to find hazards between the async |
| 3104 | // subpasses. Anything older than that should have been checked at the start of each subpass, taking into account all of |
| 3105 | // the raster ordering rules. |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3106 | if (IsRead(usage)) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3107 | if (last_write.any() && (write_tag >= start_tag)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3108 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3109 | } |
| 3110 | } else { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3111 | if (last_write.any() && (write_tag >= start_tag)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3112 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3113 | } else if (last_reads.size() > 0) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 3114 | // 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] | 3115 | for (const auto &read_access : last_reads) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3116 | if (read_access.tag >= start_tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3117 | 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] | 3118 | break; |
| 3119 | } |
| 3120 | } |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 3121 | } |
| 3122 | } |
| 3123 | return hazard; |
| 3124 | } |
| 3125 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3126 | HazardResult ResourceAccessState::DetectAsyncHazard(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range, |
| 3127 | ResourceUsageTag start_tag) const { |
| 3128 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3129 | for (const auto &first : recorded_use.first_accesses_) { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3130 | // Skip and quit logic |
| 3131 | if (first.tag < tag_range.begin) continue; |
| 3132 | if (first.tag >= tag_range.end) break; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3133 | |
| 3134 | hazard = DetectAsyncHazard(first.usage_index, start_tag); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3135 | if (hazard.hazard) { |
| 3136 | hazard.AddRecordedAccess(first); |
| 3137 | break; |
| 3138 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3139 | } |
| 3140 | return hazard; |
| 3141 | } |
| 3142 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3143 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3144 | const SyncStageAccessFlags &src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3145 | // Only supporting image layout transitions for now |
| 3146 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 3147 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3148 | // only test for WAW if there no intervening read operations. |
| 3149 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3150 | if (last_reads.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3151 | // Look at the reads if any |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3152 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3153 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3154 | 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] | 3155 | break; |
| 3156 | } |
| 3157 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3158 | } else if (last_write.any() && IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 3159 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3160 | } |
| 3161 | |
| 3162 | return hazard; |
| 3163 | } |
| 3164 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3165 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3166 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3167 | const ResourceUsageTag event_tag) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3168 | // Only supporting image layout transitions for now |
| 3169 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 3170 | HazardResult hazard; |
| 3171 | // only test for WAW if there no intervening read operations. |
| 3172 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 3173 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3174 | if (last_reads.size()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3175 | // Look at the reads if any... if reads exist, they are either the resaon the access is in the event |
| 3176 | // first scope, or they are a hazard. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3177 | for (const auto &read_access : last_reads) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3178 | if (read_access.tag < event_tag) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3179 | // The read is in the events first synchronization scope, so we use a barrier hazard check |
| 3180 | // If the read stage is not in the src sync scope |
| 3181 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 3182 | // then the barrier access is unsafe (R/W after R) |
| 3183 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
| 3184 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3185 | break; |
| 3186 | } |
| 3187 | } else { |
| 3188 | // The read not in the event first sync scope and so is a hazard vs. the layout transition |
| 3189 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3190 | } |
| 3191 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3192 | } else if (last_write.any()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3193 | // if there are no reads, the write is either the reason the access is in the event scope... they are a hazard |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3194 | if (write_tag < event_tag) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3195 | // The write is in the first sync scope of the event (sync their aren't any reads to be the reason) |
| 3196 | // So do a normal barrier hazard check |
| 3197 | if (IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 3198 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3199 | } |
| 3200 | } else { |
| 3201 | // The write isn't in scope, and is thus a hazard to the layout transistion for wait |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3202 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3203 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3204 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3205 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3206 | return hazard; |
| 3207 | } |
| 3208 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3209 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 3210 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 3211 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 3212 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3213 | if (write_tag < other.write_tag) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3214 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 3215 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3216 | *this = other; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3217 | } else if (other.write_tag == write_tag) { |
| 3218 | // 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] | 3219 | // dependency chaining logic or any stage expansion) |
| 3220 | write_barriers |= other.write_barriers; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3221 | pending_write_barriers |= other.pending_write_barriers; |
| 3222 | pending_layout_transition |= other.pending_layout_transition; |
| 3223 | pending_write_dep_chain |= other.pending_write_dep_chain; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3224 | pending_layout_ordering_ |= other.pending_layout_ordering_; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3225 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3226 | // Merge the read states |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3227 | const auto pre_merge_count = last_reads.size(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3228 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3229 | 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] | 3230 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3231 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3232 | // 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] | 3233 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 3234 | // but we should wait on profiling data for that. |
| 3235 | 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] | 3236 | auto &my_read = last_reads[my_read_index]; |
| 3237 | if (other_read.stage == my_read.stage) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3238 | if (my_read.tag < other_read.tag) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3239 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3240 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3241 | my_read.tag = other_read.tag; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3242 | my_read.queue = other_read.queue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3243 | my_read.pending_dep_chain = other_read.pending_dep_chain; |
| 3244 | // TODO: Phase 2 -- review the state merge logic to avoid false positive from overwriting the barriers |
| 3245 | // May require tracking more than one access per stage. |
| 3246 | my_read.barriers = other_read.barriers; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3247 | my_read.sync_stages = other_read.sync_stages; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3248 | if (my_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3249 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 3250 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3251 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3252 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3253 | } else if (other_read.tag == my_read.tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3254 | // The read tags match so merge the barriers |
| 3255 | my_read.barriers |= other_read.barriers; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3256 | my_read.sync_stages |= other_read.sync_stages; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3257 | my_read.pending_dep_chain |= other_read.pending_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3258 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3259 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3260 | break; |
| 3261 | } |
| 3262 | } |
| 3263 | } else { |
| 3264 | // The other read stage doesn't exist in this, so add it. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3265 | last_reads.emplace_back(other_read); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3266 | last_read_stages |= other_read.stage; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3267 | if (other_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3268 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3269 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3270 | } |
| 3271 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3272 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3273 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 3274 | // ignore it. |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3275 | |
| 3276 | // Merge first access information by making a copy of this first_access and reconstructing with a shuffle |
| 3277 | // of the copy and other into this using the update first logic. |
| 3278 | // NOTE: All sorts of additional cleverness could be put into short circuts. (for example back is write and is before front |
| 3279 | // of the other first_accesses... ) |
| 3280 | if (!(first_accesses_ == other.first_accesses_) && !other.first_accesses_.empty()) { |
| 3281 | FirstAccesses firsts(std::move(first_accesses_)); |
| 3282 | first_accesses_.clear(); |
| 3283 | first_read_stages_ = 0U; |
| 3284 | auto a = firsts.begin(); |
| 3285 | auto a_end = firsts.end(); |
| 3286 | for (auto &b : other.first_accesses_) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3287 | // TODO: Determine whether some tag offset will be needed for PHASE II |
| 3288 | while ((a != a_end) && (a->tag < b.tag)) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3289 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3290 | ++a; |
| 3291 | } |
| 3292 | UpdateFirst(b.tag, b.usage_index, b.ordering_rule); |
| 3293 | } |
| 3294 | for (; a != a_end; ++a) { |
| 3295 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3296 | } |
| 3297 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3298 | } |
| 3299 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3300 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, SyncOrdering ordering_rule, const ResourceUsageTag tag) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3301 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 3302 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3303 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3304 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 3305 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 3306 | const auto usage_stage = PipelineStageBit(usage_index); |
| 3307 | if (usage_stage & last_read_stages) { |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3308 | const auto not_usage_stage = ~usage_stage; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3309 | for (auto &read_access : last_reads) { |
| 3310 | if (read_access.stage == usage_stage) { |
| 3311 | read_access.Set(usage_stage, usage_bit, 0, tag); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3312 | } else if (read_access.barriers & usage_stage) { |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3313 | // 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] | 3314 | read_access.sync_stages |= usage_stage; |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3315 | } else { |
| 3316 | // If the current access is *NOT* barriered to this stage it needs to be cleared. |
| 3317 | // Note: this is possible because semaphores can *clear* effective barriers, so the assumption |
| 3318 | // that sync_stages is a subset of barriers may not apply. |
| 3319 | read_access.sync_stages &= not_usage_stage; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3320 | } |
| 3321 | } |
| 3322 | } else { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3323 | for (auto &read_access : last_reads) { |
| 3324 | if (read_access.barriers & usage_stage) { |
| 3325 | read_access.sync_stages |= usage_stage; |
| 3326 | } |
| 3327 | } |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3328 | last_reads.emplace_back(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3329 | last_read_stages |= usage_stage; |
| 3330 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3331 | |
| 3332 | // 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] | 3333 | if (usage_stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3334 | // TODO Revisit re: multiple reads for a given stage |
| 3335 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3336 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3337 | } else { |
| 3338 | // Assume write |
| 3339 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3340 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3341 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3342 | UpdateFirst(tag, usage_index, ordering_rule); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3343 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3344 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3345 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 3346 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 3347 | // We can overwrite them as *this* write is now after them. |
| 3348 | // |
| 3349 | // 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] | 3350 | void ResourceAccessState::SetWrite(const SyncStageAccessFlags &usage_bit, const ResourceUsageTag tag) { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3351 | ClearRead(); |
| 3352 | ClearWrite(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3353 | write_tag = tag; |
| 3354 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3355 | } |
| 3356 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3357 | void ResourceAccessState::ClearWrite() { |
| 3358 | read_execution_barriers = VK_PIPELINE_STAGE_2_NONE; |
| 3359 | input_attachment_read = false; // Denotes no outstanding input attachment read after the last write. |
| 3360 | write_barriers.reset(); |
| 3361 | write_dependency_chain = VK_PIPELINE_STAGE_2_NONE; |
| 3362 | last_write.reset(); |
| 3363 | |
| 3364 | write_tag = 0; |
| 3365 | write_queue = QueueSyncState::kQueueIdInvalid; |
| 3366 | } |
| 3367 | |
| 3368 | void ResourceAccessState::ClearRead() { |
| 3369 | last_reads.clear(); |
| 3370 | last_read_stages = VK_PIPELINE_STAGE_2_NONE; |
| 3371 | } |
| 3372 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3373 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 3374 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 3375 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 3376 | // 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] | 3377 | template <typename ScopeOps> |
| 3378 | void ResourceAccessState::ApplyBarrier(ScopeOps &&scope, const SyncBarrier &barrier, bool layout_transition) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3379 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 3380 | // applying the memory barriers |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 3381 | // 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] | 3382 | // 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] | 3383 | // vs. this layout transition DetectBarrierHazard should report it. We treat the layout |
| 3384 | // 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] | 3385 | if (layout_transition || scope.WriteInScope(barrier, *this)) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3386 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3387 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3388 | if (layout_transition) { |
| 3389 | pending_layout_ordering_ |= OrderingBarrier(barrier.src_exec_scope.exec_scope, barrier.src_access_scope); |
| 3390 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3391 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3392 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 3393 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3394 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3395 | if (!pending_layout_transition) { |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3396 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/chains |
| 3397 | // 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] | 3398 | VkPipelineStageFlags2 stages_in_scope = VK_PIPELINE_STAGE_2_NONE; |
| 3399 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3400 | for (auto &read_access : last_reads) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3401 | // 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] | 3402 | if (scope.ReadInScope(barrier, read_access)) { |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3403 | // We'll apply the barrier in the next loop, because it's DRY'r to do it one place. |
| 3404 | stages_in_scope |= read_access.stage; |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | for (auto &read_access : last_reads) { |
| 3409 | if (0 != ((read_access.stage | read_access.sync_stages) & stages_in_scope)) { |
| 3410 | // If this stage, or any stage known to be synchronized after it are in scope, apply the barrier to this read |
| 3411 | // NOTE: Forwarding barriers to known prior stages changes the sync_stages from shallow to deep, because the |
| 3412 | // 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] | 3413 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3414 | } |
| 3415 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3416 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3417 | } |
| 3418 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3419 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag tag) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3420 | if (pending_layout_transition) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3421 | // 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] | 3422 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3423 | UpdateFirst(tag, SYNC_IMAGE_LAYOUT_TRANSITION, SyncOrdering::kNonAttachment); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3424 | TouchupFirstForLayoutTransition(tag, pending_layout_ordering_); |
| 3425 | pending_layout_ordering_ = OrderingBarrier(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3426 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3427 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3428 | |
| 3429 | // Apply the accumulate execution barriers (and thus update chaining information) |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3430 | // 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] | 3431 | for (auto &read_access : last_reads) { |
| 3432 | read_access.barriers |= read_access.pending_dep_chain; |
| 3433 | read_execution_barriers |= read_access.barriers; |
| 3434 | read_access.pending_dep_chain = 0; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 3438 | write_dependency_chain |= pending_write_dep_chain; |
| 3439 | write_barriers |= pending_write_barriers; |
| 3440 | pending_write_dep_chain = 0; |
| 3441 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3442 | } |
| 3443 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3444 | // Assumes signal queue != wait queue |
| 3445 | void ResourceAccessState::ApplySemaphore(const SemaphoreScope &signal, const SemaphoreScope wait) { |
| 3446 | // Semaphores only guarantee the first scope of the signal is before the second scope of the wait. |
| 3447 | // If any access isn't in the first scope, there are no guarantees, thus those barriers are cleared |
| 3448 | assert(signal.queue != wait.queue); |
| 3449 | for (auto &read_access : last_reads) { |
| 3450 | if (read_access.ReadInQueueScopeOrChain(signal.queue, signal.exec_scope)) { |
| 3451 | // Deflects WAR on wait queue |
| 3452 | read_access.barriers = wait.exec_scope; |
| 3453 | } else { |
| 3454 | // Leave sync stages alone. Update method will clear unsynchronized stages on subsequent reads as needed. |
| 3455 | read_access.barriers = VK_PIPELINE_STAGE_2_NONE; |
| 3456 | } |
| 3457 | } |
| 3458 | if (WriteInQueueSourceScopeOrChain(signal.queue, signal.exec_scope, signal.valid_accesses)) { |
| 3459 | // Will deflect RAW wait queue, WAW needs a chained barrier on wait queue |
| 3460 | read_execution_barriers = wait.exec_scope; |
| 3461 | write_barriers = wait.valid_accesses; |
| 3462 | } else { |
| 3463 | read_execution_barriers = VK_PIPELINE_STAGE_2_NONE; |
| 3464 | write_barriers.reset(); |
| 3465 | } |
| 3466 | write_dependency_chain = read_execution_barriers; |
| 3467 | } |
| 3468 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3469 | bool ResourceAccessState::QueueTagPredicate::operator()(QueueId usage_queue, ResourceUsageTag usage_tag) { |
| 3470 | return (queue == usage_queue) && (tag <= usage_tag); |
| 3471 | } |
| 3472 | |
| 3473 | bool ResourceAccessState::QueuePredicate::operator()(QueueId usage_queue, ResourceUsageTag) { return queue == usage_queue; } |
| 3474 | |
| 3475 | bool ResourceAccessState::TagPredicate::operator()(QueueId, ResourceUsageTag usage_tag) { return tag <= usage_tag; } |
| 3476 | |
| 3477 | // Return if the resulting state is "empty" |
| 3478 | template <typename Pred> |
| 3479 | bool ResourceAccessState::ApplyQueueTagWait(Pred &&queue_tag_test) { |
| 3480 | VkPipelineStageFlags2KHR sync_reads = VK_PIPELINE_STAGE_2_NONE; |
| 3481 | |
| 3482 | // Use the predicate to build a mask of the read stages we are synchronizing |
| 3483 | // 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] | 3484 | for (auto &read_access : last_reads) { |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3485 | if (queue_tag_test(read_access.queue, read_access.tag)) { |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3486 | // If we know this stage is before any stage we syncing, or if the predicate tells us that we are waited for.. |
| 3487 | sync_reads |= read_access.stage; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3488 | } |
| 3489 | } |
| 3490 | |
John Zulauf | 434c4e6 | 2022-05-19 16:03:56 -0600 | [diff] [blame] | 3491 | // Now that we know the reads directly in scopejust need to go over the list again to pick up the "known earlier" stages. |
| 3492 | // NOTE: sync_stages is "deep" catching all stages synchronized after it because we forward barriers |
| 3493 | uint32_t unsync_count = 0; |
| 3494 | for (auto &read_access : last_reads) { |
| 3495 | if (0 != ((read_access.stage | read_access.sync_stages) & sync_reads)) { |
| 3496 | // This is redundant in the "stage" case, but avoids a second branch to get an accurate count |
| 3497 | sync_reads |= read_access.stage; |
| 3498 | } else { |
| 3499 | ++unsync_count; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3500 | } |
| 3501 | } |
| 3502 | |
| 3503 | if (unsync_count) { |
| 3504 | if (sync_reads) { |
| 3505 | // When have some remaining unsynchronized reads, we have to rewrite the last_reads array. |
| 3506 | ReadStates unsync_reads; |
| 3507 | unsync_reads.reserve(unsync_count); |
| 3508 | VkPipelineStageFlags2KHR unsync_read_stages = VK_PIPELINE_STAGE_2_NONE; |
| 3509 | for (auto &read_access : last_reads) { |
| 3510 | if (0 == (read_access.stage & sync_reads)) { |
| 3511 | unsync_reads.emplace_back(read_access); |
| 3512 | unsync_read_stages |= read_access.stage; |
| 3513 | } |
| 3514 | } |
| 3515 | last_read_stages = unsync_read_stages; |
| 3516 | last_reads = std::move(unsync_reads); |
| 3517 | } |
| 3518 | } else { |
| 3519 | // Nothing remains (or it was empty to begin with) |
| 3520 | ClearRead(); |
| 3521 | } |
| 3522 | |
| 3523 | bool all_clear = last_reads.size() == 0; |
| 3524 | if (last_write.any()) { |
| 3525 | if (queue_tag_test(write_queue, write_tag) || sync_reads) { |
| 3526 | // Clear any predicated write, or any the write from any any access with synchronized reads. |
| 3527 | // This could drop RAW detection, but only if the synchronized reads were RAW hazards, and given |
| 3528 | // MRR approach to reporting, this is consistent with other drops, especially since fixing the |
| 3529 | // RAW wit the sync_reads stages would preclude a subsequent RAW. |
| 3530 | ClearWrite(); |
| 3531 | } else { |
| 3532 | all_clear = false; |
| 3533 | } |
| 3534 | } |
| 3535 | return all_clear; |
| 3536 | } |
| 3537 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3538 | bool ResourceAccessState::FirstAccessInTagRange(const ResourceUsageRange &tag_range) const { |
| 3539 | if (!first_accesses_.size()) return false; |
| 3540 | const ResourceUsageRange first_access_range = {first_accesses_.front().tag, first_accesses_.back().tag + 1}; |
| 3541 | return tag_range.intersects(first_access_range); |
| 3542 | } |
| 3543 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3544 | void ResourceAccessState::OffsetTag(ResourceUsageTag offset) { |
| 3545 | if (last_write.any()) write_tag += offset; |
| 3546 | for (auto &read_access : last_reads) { |
| 3547 | read_access.tag += offset; |
| 3548 | } |
| 3549 | for (auto &first : first_accesses_) { |
| 3550 | first.tag += offset; |
| 3551 | } |
| 3552 | } |
| 3553 | |
| 3554 | ResourceAccessState::ResourceAccessState() |
| 3555 | : write_barriers(~SyncStageAccessFlags(0)), |
| 3556 | write_dependency_chain(0), |
| 3557 | write_tag(), |
| 3558 | write_queue(QueueSyncState::kQueueIdInvalid), |
| 3559 | last_write(0), |
| 3560 | input_attachment_read(false), |
| 3561 | last_read_stages(0), |
| 3562 | read_execution_barriers(0), |
| 3563 | pending_write_dep_chain(0), |
| 3564 | pending_layout_transition(false), |
| 3565 | pending_write_barriers(0), |
| 3566 | pending_layout_ordering_(), |
| 3567 | first_accesses_(), |
| 3568 | first_read_stages_(0U), |
| 3569 | first_write_layout_ordering_() {} |
| 3570 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3571 | // 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] | 3572 | VkPipelineStageFlags2KHR ResourceAccessState::GetReadBarriers(const SyncStageAccessFlags &usage_bit) const { |
| 3573 | VkPipelineStageFlags2KHR barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3574 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3575 | for (const auto &read_access : last_reads) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3576 | if ((read_access.access & usage_bit).any()) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3577 | barriers = read_access.barriers; |
| 3578 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3579 | } |
| 3580 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3581 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3582 | return barriers; |
| 3583 | } |
| 3584 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3585 | void ResourceAccessState::SetQueueId(QueueId id) { |
| 3586 | for (auto &read_access : last_reads) { |
| 3587 | if (read_access.queue == QueueSyncState::kQueueIdInvalid) { |
| 3588 | read_access.queue = id; |
| 3589 | } |
| 3590 | } |
| 3591 | if (last_write.any() && (write_queue == QueueSyncState::kQueueIdInvalid)) { |
| 3592 | write_queue = id; |
| 3593 | } |
| 3594 | } |
| 3595 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 3596 | bool ResourceAccessState::WriteInChain(VkPipelineStageFlags2KHR src_exec_scope) const { |
| 3597 | return 0 != (write_dependency_chain & src_exec_scope); |
| 3598 | } |
| 3599 | |
| 3600 | bool ResourceAccessState::WriteInScope(const SyncStageAccessFlags &src_access_scope) const { |
| 3601 | return (src_access_scope & last_write).any(); |
| 3602 | } |
| 3603 | |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3604 | bool ResourceAccessState::WriteInSourceScopeOrChain(VkPipelineStageFlags2KHR src_exec_scope, |
| 3605 | SyncStageAccessFlags src_access_scope) const { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 3606 | return WriteInChain(src_exec_scope) || WriteInScope(src_access_scope); |
| 3607 | } |
| 3608 | |
| 3609 | bool ResourceAccessState::WriteInQueueSourceScopeOrChain(QueueId queue, VkPipelineStageFlags2KHR src_exec_scope, |
| 3610 | SyncStageAccessFlags src_access_scope) const { |
| 3611 | return WriteInChain(src_exec_scope) || ((queue == write_queue) && WriteInScope(src_access_scope)); |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | bool ResourceAccessState::WriteInEventScope(const SyncStageAccessFlags &src_access_scope, ResourceUsageTag scope_tag) const { |
| 3615 | // The scope logic for events is, if we're asking, the resource usage was flagged as "in the first execution scope" at |
| 3616 | // the time of the SetEvent, thus all we need check is whether the access is the same one (i.e. before the scope tag |
| 3617 | // in order to know if it's in the excecution scope |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 3618 | return (write_tag < scope_tag) && WriteInScope(src_access_scope); |
John Zulauf | b757830 | 2022-05-19 13:50:18 -0600 | [diff] [blame] | 3619 | } |
| 3620 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3621 | bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlags2KHR usage_stage, const SyncStageAccessFlags &usage) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3622 | assert(IsRead(usage)); |
| 3623 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 3624 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 3625 | // any reads that happen after. |
| 3626 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 3627 | // 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] | 3628 | return last_write.any() && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3629 | } |
| 3630 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3631 | VkPipelineStageFlags2KHR ResourceAccessState::GetOrderedStages(const OrderingBarrier &ordering) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3632 | // Whether the stage are in the ordering scope only matters if the current write is ordered |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3633 | VkPipelineStageFlags2KHR ordered_stages = last_read_stages & ordering.exec_scope; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3634 | // Special input attachment handling as always (not encoded in exec_scop) |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3635 | 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] | 3636 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3637 | // 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] | 3638 | ordered_stages |= VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | return ordered_stages; |
| 3642 | } |
| 3643 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3644 | void ResourceAccessState::UpdateFirst(const ResourceUsageTag tag, SyncStageAccessIndex usage_index, SyncOrdering ordering_rule) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3645 | // Only record until we record a write. |
| 3646 | if (first_accesses_.empty() || IsRead(first_accesses_.back().usage_index)) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3647 | const VkPipelineStageFlags2KHR usage_stage = IsRead(usage_index) ? PipelineStageBit(usage_index) : 0U; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3648 | if (0 == (usage_stage & first_read_stages_)) { |
| 3649 | // 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] | 3650 | // We always need to know what stages were found prior to write |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3651 | first_read_stages_ |= usage_stage; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3652 | if (0 == (read_execution_barriers & usage_stage)) { |
| 3653 | // If this stage isn't masked then we add it (since writes map to usage_stage 0, this also records writes) |
| 3654 | first_accesses_.emplace_back(tag, usage_index, ordering_rule); |
| 3655 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3656 | } |
| 3657 | } |
| 3658 | } |
| 3659 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3660 | void ResourceAccessState::TouchupFirstForLayoutTransition(ResourceUsageTag tag, const OrderingBarrier &layout_ordering) { |
| 3661 | // Only call this after recording an image layout transition |
| 3662 | assert(first_accesses_.size()); |
| 3663 | if (first_accesses_.back().tag == tag) { |
| 3664 | // 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] | 3665 | assert(first_accesses_.back().usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3666 | first_write_layout_ordering_ = layout_ordering; |
| 3667 | } |
| 3668 | } |
| 3669 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3670 | ResourceAccessState::ReadState::ReadState(VkPipelineStageFlags2KHR stage_, SyncStageAccessFlags access_, |
| 3671 | VkPipelineStageFlags2KHR barriers_, ResourceUsageTag tag_) |
| 3672 | : stage(stage_), |
| 3673 | access(access_), |
| 3674 | barriers(barriers_), |
| 3675 | sync_stages(VK_PIPELINE_STAGE_2_NONE), |
| 3676 | tag(tag_), |
| 3677 | queue(QueueSyncState::kQueueIdInvalid), |
| 3678 | pending_dep_chain(VK_PIPELINE_STAGE_2_NONE) {} |
| 3679 | |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 3680 | void ResourceAccessState::ReadState::Set(VkPipelineStageFlags2KHR stage_, const SyncStageAccessFlags &access_, |
| 3681 | VkPipelineStageFlags2KHR barriers_, ResourceUsageTag tag_) { |
| 3682 | stage = stage_; |
| 3683 | access = access_; |
| 3684 | barriers = barriers_; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3685 | sync_stages = VK_PIPELINE_STAGE_2_NONE; |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 3686 | tag = tag_; |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3687 | 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] | 3688 | } |
| 3689 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 3690 | // Scope test including "queue submission order" effects. Specifically, accesses from a different queue are not |
| 3691 | // considered to be in "queue submission order" with barriers, events, or semaphore signalling, but any barriers |
| 3692 | // that have bee applied (via semaphore) to those accesses can be chained off of. |
| 3693 | bool ResourceAccessState::ReadState::ReadInQueueScopeOrChain(QueueId scope_queue, VkPipelineStageFlags2 exec_scope) const { |
| 3694 | VkPipelineStageFlags2 effective_stages = barriers | ((scope_queue == queue) ? stage : VK_PIPELINE_STAGE_2_NONE); |
| 3695 | return (exec_scope & effective_stages) != 0; |
| 3696 | } |
| 3697 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3698 | ResourceUsageRange SyncValidator::ReserveGlobalTagRange(size_t tag_count) const { |
| 3699 | ResourceUsageRange reserve; |
| 3700 | reserve.begin = tag_limit_.fetch_add(tag_count); |
| 3701 | reserve.end = reserve.begin + tag_count; |
| 3702 | return reserve; |
| 3703 | } |
| 3704 | |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 3705 | const QueueSyncState *SyncValidator::GetQueueSyncState(VkQueue queue) const { |
| 3706 | return GetMappedPlainFromShared(queue_sync_states_, queue); |
| 3707 | } |
| 3708 | |
| 3709 | QueueSyncState *SyncValidator::GetQueueSyncState(VkQueue queue) { return GetMappedPlainFromShared(queue_sync_states_, queue); } |
| 3710 | |
| 3711 | std::shared_ptr<const QueueSyncState> SyncValidator::GetQueueSyncStateShared(VkQueue queue) const { |
| 3712 | return GetMapped(queue_sync_states_, queue, []() { return std::shared_ptr<QueueSyncState>(); }); |
| 3713 | } |
| 3714 | |
| 3715 | std::shared_ptr<QueueSyncState> SyncValidator::GetQueueSyncStateShared(VkQueue queue) { |
| 3716 | return GetMapped(queue_sync_states_, queue, []() { return std::shared_ptr<QueueSyncState>(); }); |
| 3717 | } |
| 3718 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3719 | template <typename BatchSet, typename Predicate> |
| 3720 | static BatchSet GetQueueLastBatchSnapshotImpl(const SyncValidator::QueueSyncStatesMap &queues, Predicate &&pred) { |
| 3721 | BatchSet snapshot; |
| 3722 | for (auto &queue : queues) { |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3723 | auto batch = queue.second->LastBatch(); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3724 | if (batch && pred(batch)) snapshot.emplace(std::move(batch)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3725 | } |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 3726 | return snapshot; |
| 3727 | } |
| 3728 | |
| 3729 | template <typename Predicate> |
| 3730 | QueueBatchContext::ConstBatchSet SyncValidator::GetQueueLastBatchSnapshot(Predicate &&pred) const { |
| 3731 | return GetQueueLastBatchSnapshotImpl<QueueBatchContext::ConstBatchSet, Predicate>(queue_sync_states_, |
| 3732 | std::forward<Predicate>(pred)); |
| 3733 | } |
| 3734 | |
| 3735 | template <typename Predicate> |
| 3736 | QueueBatchContext::BatchSet SyncValidator::GetQueueLastBatchSnapshot(Predicate &&pred) { |
| 3737 | return GetQueueLastBatchSnapshotImpl<QueueBatchContext::BatchSet, Predicate>(queue_sync_states_, std::forward<Predicate>(pred)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3738 | } |
| 3739 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3740 | bool SignaledSemaphores::SignalSemaphore(const std::shared_ptr<const SEMAPHORE_STATE> &sem_state, |
| 3741 | const std::shared_ptr<QueueBatchContext> &batch, |
| 3742 | const VkSemaphoreSubmitInfo &signal_info) { |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3743 | assert(batch); |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3744 | const SyncExecScope exec_scope = |
| 3745 | SyncExecScope::MakeSrc(batch->GetQueueFlags(), signal_info.stageMask, VK_PIPELINE_STAGE_2_HOST_BIT); |
| 3746 | const VkSemaphore sem = sem_state->semaphore(); |
| 3747 | auto signal_it = signaled_.find(sem); |
| 3748 | std::shared_ptr<Signal> insert_signal; |
| 3749 | if (signal_it == signaled_.end()) { |
| 3750 | if (prev_) { |
| 3751 | auto prev_sig = GetMapped(prev_->signaled_, sem_state->semaphore(), []() { return std::shared_ptr<Signal>(); }); |
| 3752 | if (prev_sig) { |
| 3753 | // The is an invalid signal, as this semaphore is already signaled... copy the prev state (as prev_ is const) |
| 3754 | insert_signal = std::make_shared<Signal>(*prev_sig); |
| 3755 | } |
| 3756 | } |
| 3757 | auto insert_pair = signaled_.emplace(sem, std::move(insert_signal)); |
| 3758 | signal_it = insert_pair.first; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 3759 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3760 | |
| 3761 | bool success = false; |
| 3762 | if (!signal_it->second) { |
| 3763 | signal_it->second = std::make_shared<Signal>(sem_state, batch, exec_scope); |
| 3764 | success = true; |
| 3765 | } |
| 3766 | |
| 3767 | return success; |
| 3768 | } |
| 3769 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 3770 | std::shared_ptr<const SignaledSemaphores::Signal> SignaledSemaphores::Unsignal(VkSemaphore sem) { |
| 3771 | std::shared_ptr<const Signal> unsignaled; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3772 | const auto found_it = signaled_.find(sem); |
| 3773 | if (found_it != signaled_.end()) { |
| 3774 | // Move the unsignaled singal out from the signaled list, but keep the shared_ptr as the caller needs the contents for |
| 3775 | // a bit. |
| 3776 | unsignaled = std::move(found_it->second); |
| 3777 | if (!prev_) { |
| 3778 | // No parent, not need to keep the entry |
| 3779 | // IFF (prev_) leave the entry in the leaf table as we use it to export unsignal to prev_ during record phase |
| 3780 | signaled_.erase(found_it); |
| 3781 | } |
| 3782 | } else if (prev_) { |
| 3783 | // We can't unsignal prev_ because it's const * by design. |
| 3784 | // We put in an empty placeholder |
| 3785 | signaled_.emplace(sem, std::shared_ptr<Signal>()); |
| 3786 | unsignaled = GetPrev(sem); |
| 3787 | } |
| 3788 | // NOTE: No else clause. Because if we didn't find it, and there's no previous, this indicates an error, |
| 3789 | // but CoreChecks should have reported it |
| 3790 | |
| 3791 | // 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] | 3792 | return unsignaled; |
| 3793 | } |
| 3794 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3795 | void SignaledSemaphores::Import(VkSemaphore sem, std::shared_ptr<Signal> &&from) { |
| 3796 | // Overwrite the s tate with the last state from this |
| 3797 | if (from) { |
| 3798 | assert(sem == from->sem_state->semaphore()); |
| 3799 | signaled_[sem] = std::move(from); |
| 3800 | } else { |
| 3801 | signaled_.erase(sem); |
| 3802 | } |
| 3803 | } |
| 3804 | |
| 3805 | void SignaledSemaphores::Reset() { |
| 3806 | signaled_.clear(); |
| 3807 | prev_ = nullptr; |
| 3808 | } |
| 3809 | |
John Zulauf | ea943c5 | 2022-02-22 11:05:17 -0700 | [diff] [blame] | 3810 | std::shared_ptr<CommandBufferAccessContext> SyncValidator::AccessContextFactory(VkCommandBuffer command_buffer) { |
| 3811 | // If we don't have one, make it. |
| 3812 | auto cb_state = Get<CMD_BUFFER_STATE>(command_buffer); |
| 3813 | assert(cb_state.get()); |
| 3814 | auto queue_flags = cb_state->GetQueueFlags(); |
| 3815 | return std::make_shared<CommandBufferAccessContext>(*this, cb_state, queue_flags); |
| 3816 | } |
| 3817 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 3818 | std::shared_ptr<CommandBufferAccessContext> SyncValidator::GetAccessContextShared(VkCommandBuffer command_buffer) { |
John Zulauf | ea943c5 | 2022-02-22 11:05:17 -0700 | [diff] [blame] | 3819 | return GetMappedInsert(cb_access_state, command_buffer, |
| 3820 | [this, command_buffer]() { return AccessContextFactory(command_buffer); }); |
| 3821 | } |
| 3822 | |
| 3823 | std::shared_ptr<const CommandBufferAccessContext> SyncValidator::GetAccessContextShared(VkCommandBuffer command_buffer) const { |
| 3824 | return GetMapped(cb_access_state, command_buffer, []() { return std::shared_ptr<CommandBufferAccessContext>(); }); |
| 3825 | } |
| 3826 | |
| 3827 | const CommandBufferAccessContext *SyncValidator::GetAccessContext(VkCommandBuffer command_buffer) const { |
| 3828 | return GetMappedPlainFromShared(cb_access_state, command_buffer); |
| 3829 | } |
| 3830 | |
| 3831 | CommandBufferAccessContext *SyncValidator::GetAccessContext(VkCommandBuffer command_buffer) { |
| 3832 | return GetAccessContextShared(command_buffer).get(); |
| 3833 | } |
| 3834 | |
| 3835 | CommandBufferAccessContext *SyncValidator::GetAccessContextNoInsert(VkCommandBuffer command_buffer) { |
| 3836 | return GetMappedPlainFromShared(cb_access_state, command_buffer); |
| 3837 | } |
| 3838 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3839 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3840 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 3841 | if (access_context) { |
| 3842 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3846 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 3847 | auto access_found = cb_access_state.find(command_buffer); |
| 3848 | if (access_found != cb_access_state.end()) { |
| 3849 | access_found->second->Reset(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3850 | access_found->second->MarkDestroyed(); |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3851 | cb_access_state.erase(access_found); |
| 3852 | } |
| 3853 | } |
| 3854 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3855 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3856 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 3857 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3858 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3859 | assert(cb_context); |
| 3860 | if (!cb_context) return skip; |
| 3861 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3862 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3863 | // If we have no previous accesses, we have no hazards |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3864 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 3865 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3866 | |
| 3867 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3868 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3869 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3870 | 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] | 3871 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3872 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3873 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3874 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3875 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3876 | cb_context->FormatHazard(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3877 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3878 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3879 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3880 | 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] | 3881 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3882 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3883 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3884 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3885 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 3886 | cb_context->FormatHazard(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3887 | } |
| 3888 | } |
| 3889 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3890 | } |
| 3891 | return skip; |
| 3892 | } |
| 3893 | |
| 3894 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3895 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3896 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3897 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3898 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3899 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3900 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3901 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 3902 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3903 | |
| 3904 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3905 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3906 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3907 | 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] | 3908 | 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] | 3909 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3910 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3911 | 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] | 3912 | 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] | 3913 | } |
| 3914 | } |
| 3915 | } |
| 3916 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3917 | void SyncValidator::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 3918 | // Clear out events from the command buffer contexts |
| 3919 | for (auto &cb_context : cb_access_state) { |
| 3920 | cb_context.second->RecordDestroyEvent(event); |
| 3921 | } |
| 3922 | } |
| 3923 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3924 | bool SyncValidator::ValidateCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos, |
| 3925 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3926 | bool skip = false; |
| 3927 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3928 | assert(cb_context); |
| 3929 | if (!cb_context) return skip; |
| 3930 | const auto *context = cb_context->GetCurrentAccessContext(); |
| 3931 | |
| 3932 | // If we have no previous accesses, we have no hazards |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3933 | auto src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3934 | auto dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3935 | |
| 3936 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3937 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3938 | if (src_buffer) { |
| 3939 | 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] | 3940 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3941 | if (hazard.hazard) { |
| 3942 | // TODO -- add tag information to log msg when useful. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 3943 | skip |= |
| 3944 | LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3945 | "%s(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 3946 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
| 3947 | region, cb_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3948 | } |
| 3949 | } |
| 3950 | if (dst_buffer && !skip) { |
| 3951 | 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] | 3952 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3953 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 3954 | skip |= |
| 3955 | LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3956 | "%s(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 3957 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
| 3958 | region, cb_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3959 | } |
| 3960 | } |
| 3961 | if (skip) break; |
| 3962 | } |
| 3963 | return skip; |
| 3964 | } |
| 3965 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3966 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3967 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 3968 | return ValidateCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2KHR); |
| 3969 | } |
| 3970 | |
| 3971 | bool SyncValidator::PreCallValidateCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos) const { |
| 3972 | return ValidateCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2); |
| 3973 | } |
| 3974 | |
| 3975 | void SyncValidator::RecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos, CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3976 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3977 | assert(cb_context); |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3978 | const auto tag = cb_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3979 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3980 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3981 | auto src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3982 | auto dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3983 | |
| 3984 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3985 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3986 | if (src_buffer) { |
| 3987 | 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] | 3988 | 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] | 3989 | } |
| 3990 | if (dst_buffer) { |
| 3991 | 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] | 3992 | 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] | 3993 | } |
| 3994 | } |
| 3995 | } |
| 3996 | |
Tony-LunarG | ef03547 | 2021-11-02 10:23:33 -0600 | [diff] [blame] | 3997 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 3998 | RecordCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2KHR); |
| 3999 | } |
| 4000 | |
| 4001 | void SyncValidator::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfos) { |
| 4002 | RecordCmdCopyBuffer2(commandBuffer, pCopyBufferInfos, CMD_COPYBUFFER2); |
| 4003 | } |
| 4004 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4005 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4006 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4007 | const VkImageCopy *pRegions) const { |
| 4008 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4009 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4010 | assert(cb_access_context); |
| 4011 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4012 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4013 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4014 | assert(context); |
| 4015 | if (!context) return skip; |
| 4016 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4017 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4018 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4019 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4020 | const auto ©_region = pRegions[region]; |
| 4021 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4022 | 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] | 4023 | copy_region.srcOffset, copy_region.extent, false); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4024 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4025 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4026 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4027 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4028 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4029 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4030 | } |
| 4031 | |
| 4032 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4033 | 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] | 4034 | copy_region.dstOffset, copy_region.extent, false); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4035 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4036 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4037 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4038 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4039 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4040 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 4041 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4042 | } |
| 4043 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4044 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4045 | return skip; |
| 4046 | } |
| 4047 | |
| 4048 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4049 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4050 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4051 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4052 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 4053 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4054 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4055 | assert(context); |
| 4056 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4057 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4058 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4059 | |
| 4060 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4061 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4062 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4063 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4064 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 4065 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4066 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4067 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
ziga-lunarg | 7374651 | 2022-03-23 23:08:17 +0100 | [diff] [blame] | 4068 | copy_region.dstSubresource, copy_region.dstOffset, copy_region.extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4069 | } |
| 4070 | } |
| 4071 | } |
| 4072 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4073 | bool SyncValidator::ValidateCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo, |
| 4074 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4075 | bool skip = false; |
| 4076 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4077 | assert(cb_access_context); |
| 4078 | if (!cb_access_context) return skip; |
| 4079 | |
| 4080 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4081 | assert(context); |
| 4082 | if (!context) return skip; |
| 4083 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4084 | auto src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 4085 | auto dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4086 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4087 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 4088 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 4089 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4090 | 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] | 4091 | copy_region.srcOffset, copy_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4092 | if (hazard.hazard) { |
| 4093 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4094 | "%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] | 4095 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4096 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4097 | } |
| 4098 | } |
| 4099 | |
| 4100 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4101 | 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] | 4102 | copy_region.dstOffset, copy_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4103 | if (hazard.hazard) { |
| 4104 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4105 | "%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] | 4106 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4107 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4108 | } |
| 4109 | if (skip) break; |
| 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | return skip; |
| 4114 | } |
| 4115 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4116 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 4117 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 4118 | return ValidateCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2KHR); |
| 4119 | } |
| 4120 | |
| 4121 | bool SyncValidator::PreCallValidateCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) const { |
| 4122 | return ValidateCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2); |
| 4123 | } |
| 4124 | |
| 4125 | void SyncValidator::RecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo, CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4126 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4127 | assert(cb_access_context); |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4128 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4129 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4130 | assert(context); |
| 4131 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4132 | auto src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 4133 | auto dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4134 | |
| 4135 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 4136 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 4137 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4138 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4139 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4140 | } |
| 4141 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4142 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
ziga-lunarg | 7374651 | 2022-03-23 23:08:17 +0100 | [diff] [blame] | 4143 | copy_region.dstSubresource, copy_region.dstOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4144 | } |
| 4145 | } |
| 4146 | } |
| 4147 | |
Tony-LunarG | b61514a | 2021-11-02 12:36:51 -0600 | [diff] [blame] | 4148 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 4149 | RecordCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2KHR); |
| 4150 | } |
| 4151 | |
| 4152 | void SyncValidator::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) { |
| 4153 | RecordCmdCopyImage2(commandBuffer, pCopyImageInfo, CMD_COPYIMAGE2); |
| 4154 | } |
| 4155 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4156 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 4157 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 4158 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4159 | uint32_t bufferMemoryBarrierCount, |
| 4160 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4161 | uint32_t imageMemoryBarrierCount, |
| 4162 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 4163 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4164 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4165 | assert(cb_access_context); |
| 4166 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 4167 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4168 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 4169 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 4170 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 4171 | pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 4172 | skip = pipeline_barrier.Validate(*cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4173 | return skip; |
| 4174 | } |
| 4175 | |
| 4176 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 4177 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 4178 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4179 | uint32_t bufferMemoryBarrierCount, |
| 4180 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4181 | uint32_t imageMemoryBarrierCount, |
| 4182 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4183 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4184 | assert(cb_access_context); |
| 4185 | if (!cb_access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4186 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 4187 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), |
| 4188 | srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, |
| 4189 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 4190 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4191 | } |
| 4192 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4193 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 4194 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 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 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 4201 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 4202 | return skip; |
| 4203 | } |
| 4204 | |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 4205 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2(VkCommandBuffer commandBuffer, |
| 4206 | const VkDependencyInfo *pDependencyInfo) const { |
| 4207 | bool skip = false; |
| 4208 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4209 | assert(cb_access_context); |
| 4210 | if (!cb_access_context) return skip; |
| 4211 | |
| 4212 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 4213 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 4214 | return skip; |
| 4215 | } |
| 4216 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4217 | void SyncValidator::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) { |
| 4218 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4219 | assert(cb_access_context); |
| 4220 | if (!cb_access_context) return; |
| 4221 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 4222 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), |
| 4223 | *pDependencyInfo); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4224 | } |
| 4225 | |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 4226 | void SyncValidator::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer, const VkDependencyInfo *pDependencyInfo) { |
| 4227 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4228 | assert(cb_access_context); |
| 4229 | if (!cb_access_context) return; |
| 4230 | |
| 4231 | cb_access_context->RecordSyncOp<SyncOpPipelineBarrier>(CMD_PIPELINEBARRIER2, *this, cb_access_context->GetQueueFlags(), |
| 4232 | *pDependencyInfo); |
| 4233 | } |
| 4234 | |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 4235 | void SyncValidator::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4236 | // The state tracker sets up the device state |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 4237 | StateTracker::CreateDevice(pCreateInfo); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4238 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 4239 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 4240 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4241 | // TODO: Find a good way to do this hooklessly. |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 4242 | SetCommandBufferResetCallback([this](VkCommandBuffer command_buffer) -> void { ResetCommandBufferCallback(command_buffer); }); |
| 4243 | SetCommandBufferFreeCallback([this](VkCommandBuffer command_buffer) -> void { FreeCommandBufferCallback(command_buffer); }); |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 4244 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 4245 | QueueId queue_id = QueueSyncState::kQueueIdBase; |
| 4246 | 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] | 4247 | 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] | 4248 | 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] | 4249 | queue_sync_states_.emplace(std::make_pair(queue_state->Queue(), std::move(queue_sync_state))); |
| 4250 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4251 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4252 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4253 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4254 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4255 | bool skip = false; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4256 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4257 | if (cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4258 | SyncOpBeginRenderPass sync_op(cmd_type, *this, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4259 | skip = sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4260 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4261 | return skip; |
| 4262 | } |
| 4263 | |
| 4264 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4265 | VkSubpassContents contents) const { |
| 4266 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4267 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4268 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4269 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4270 | return skip; |
| 4271 | } |
| 4272 | |
| 4273 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4274 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4275 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4276 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4277 | return skip; |
| 4278 | } |
| 4279 | |
| 4280 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4281 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4282 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4283 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4284 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4285 | return skip; |
| 4286 | } |
| 4287 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4288 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 4289 | VkResult result) { |
| 4290 | // The state tracker sets up the command buffer state |
| 4291 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 4292 | |
| 4293 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 4294 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 4295 | assert(cb_access_context); |
| 4296 | cb_access_context->Reset(); |
| 4297 | } |
| 4298 | |
| 4299 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4300 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd_type) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4301 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4302 | if (cb_context) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4303 | cb_context->RecordSyncOp<SyncOpBeginRenderPass>(cmd_type, *this, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4304 | } |
| 4305 | } |
| 4306 | |
| 4307 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4308 | VkSubpassContents contents) { |
| 4309 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4310 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4311 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4312 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4316 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 4317 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4318 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4322 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4323 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 4324 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4325 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4326 | } |
| 4327 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4328 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4329 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4330 | bool skip = false; |
| 4331 | |
| 4332 | auto cb_context = GetAccessContext(commandBuffer); |
| 4333 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4334 | if (!cb_context) return skip; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4335 | SyncOpNextSubpass sync_op(cmd_type, *this, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4336 | return sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 4340 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4341 | // Convert to a NextSubpass2 |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4342 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4343 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4344 | auto subpass_end_info = LvlInitStruct<VkSubpassEndInfo>(); |
| 4345 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, &subpass_end_info, CMD_NEXTSUBPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4346 | return skip; |
| 4347 | } |
| 4348 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4349 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4350 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4351 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4352 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4353 | return skip; |
| 4354 | } |
| 4355 | |
| 4356 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4357 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 4358 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4359 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4360 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4364 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd_type) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4365 | auto cb_context = GetAccessContext(commandBuffer); |
| 4366 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4367 | if (!cb_context) return; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4368 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4369 | cb_context->RecordSyncOp<SyncOpNextSubpass>(cmd_type, *this, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 4373 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 4374 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4375 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4376 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4380 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 4381 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4382 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4383 | } |
| 4384 | |
| 4385 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 4386 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 4387 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4388 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2KHR); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4389 | } |
| 4390 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4391 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4392 | CMD_TYPE cmd_type) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4393 | bool skip = false; |
| 4394 | |
| 4395 | auto cb_context = GetAccessContext(commandBuffer); |
| 4396 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4397 | if (!cb_context) return skip; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4398 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4399 | SyncOpEndRenderPass sync_op(cmd_type, *this, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4400 | skip |= sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4401 | return skip; |
| 4402 | } |
| 4403 | |
| 4404 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 4405 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4406 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4407 | return skip; |
| 4408 | } |
| 4409 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4410 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4411 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4412 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4413 | return skip; |
| 4414 | } |
| 4415 | |
| 4416 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4417 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4418 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4419 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4420 | return skip; |
| 4421 | } |
| 4422 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4423 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
| 4424 | CMD_TYPE cmd_type) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4425 | // Resolve the all subpass contexts to the command buffer contexts |
| 4426 | auto cb_context = GetAccessContext(commandBuffer); |
| 4427 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 4428 | if (!cb_context) return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4429 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4430 | cb_context->RecordSyncOp<SyncOpEndRenderPass>(cmd_type, *this, pSubpassEndInfo); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 4431 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4432 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 4433 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 4434 | // updates to a resource which do not conflict at the byte level. |
| 4435 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 4436 | // TODO: Add programatic control over suppression heuristics |
| 4437 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 4438 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 4439 | } |
| 4440 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4441 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4442 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4443 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 4447 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4448 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4452 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2KHR); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 4453 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 4454 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4455 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4456 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4457 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4458 | VkImageLayout dstImageLayout, uint32_t regionCount, const RegionType *pRegions, |
| 4459 | CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4460 | bool skip = false; |
| 4461 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4462 | assert(cb_access_context); |
| 4463 | if (!cb_access_context) return skip; |
| 4464 | |
| 4465 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4466 | assert(context); |
| 4467 | if (!context) return skip; |
| 4468 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4469 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 4470 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4471 | |
| 4472 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4473 | const auto ©_region = pRegions[region]; |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4474 | HazardResult hazard; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4475 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4476 | if (src_buffer) { |
| 4477 | ResourceAccessRange src_range = |
| 4478 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4479 | hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4480 | if (hazard.hazard) { |
| 4481 | // PHASE1 TODO -- add tag information to log msg when useful. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4482 | skip |= |
| 4483 | LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4484 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 4485 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
| 4486 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4487 | } |
| 4488 | } |
| 4489 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4490 | hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.imageSubresource, |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 4491 | copy_region.imageOffset, copy_region.imageExtent, false); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4492 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4493 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4494 | "%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] | 4495 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4496 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4497 | } |
| 4498 | if (skip) break; |
| 4499 | } |
| 4500 | if (skip) break; |
| 4501 | } |
| 4502 | return skip; |
| 4503 | } |
| 4504 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4505 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4506 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4507 | const VkBufferImageCopy *pRegions) const { |
| 4508 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4509 | CMD_COPYBUFFERTOIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4510 | } |
| 4511 | |
| 4512 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 4513 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 4514 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4515 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4516 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2KHR); |
| 4517 | } |
| 4518 | |
| 4519 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, |
| 4520 | const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) const { |
| 4521 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4522 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 4523 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4524 | } |
| 4525 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4526 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4527 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4528 | VkImageLayout dstImageLayout, uint32_t regionCount, const RegionType *pRegions, |
| 4529 | CMD_TYPE cmd_type) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4530 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4531 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4532 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4533 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4534 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4535 | assert(context); |
| 4536 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4537 | auto src_buffer = Get<BUFFER_STATE>(srcBuffer); |
| 4538 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4539 | |
| 4540 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4541 | const auto ©_region = pRegions[region]; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4542 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4543 | if (src_buffer) { |
| 4544 | ResourceAccessRange src_range = |
| 4545 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4546 | 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] | 4547 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4548 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4549 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4550 | } |
| 4551 | } |
| 4552 | } |
| 4553 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4554 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4555 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4556 | const VkBufferImageCopy *pRegions) { |
| 4557 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4558 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, CMD_COPYBUFFERTOIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 4562 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 4563 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 4564 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4565 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
Tony Barbour | 845d29b | 2021-11-09 11:43:14 -0700 | [diff] [blame] | 4566 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2KHR); |
| 4567 | } |
| 4568 | |
| 4569 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, |
| 4570 | const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) { |
| 4571 | StateTracker::PreCallRecordCmdCopyBufferToImage2(commandBuffer, pCopyBufferToImageInfo); |
| 4572 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4573 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 4574 | pCopyBufferToImageInfo->pRegions, CMD_COPYBUFFERTOIMAGE2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4575 | } |
| 4576 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4577 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4578 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4579 | VkBuffer dstBuffer, uint32_t regionCount, const RegionType *pRegions, |
| 4580 | CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4581 | bool skip = false; |
| 4582 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4583 | assert(cb_access_context); |
| 4584 | if (!cb_access_context) return skip; |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4585 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4586 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4587 | assert(context); |
| 4588 | if (!context) return skip; |
| 4589 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4590 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4591 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 4592 | 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] | 4593 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4594 | const auto ©_region = pRegions[region]; |
| 4595 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4596 | 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] | 4597 | copy_region.imageOffset, copy_region.imageExtent, false); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4598 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4599 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4600 | "%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] | 4601 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4602 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4603 | } |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4604 | if (dst_mem) { |
| 4605 | ResourceAccessRange dst_range = |
| 4606 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4607 | hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4608 | if (hazard.hazard) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4609 | skip |= |
| 4610 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4611 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", CommandTypeString(cmd_type), |
| 4612 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
| 4613 | cb_access_context->FormatHazard(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4614 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4615 | } |
| 4616 | } |
| 4617 | if (skip) break; |
| 4618 | } |
| 4619 | return skip; |
| 4620 | } |
| 4621 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4622 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 4623 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 4624 | const VkBufferImageCopy *pRegions) const { |
| 4625 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4626 | CMD_COPYIMAGETOBUFFER); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4627 | } |
| 4628 | |
| 4629 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4630 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 4631 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4632 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4633 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2KHR); |
| 4634 | } |
| 4635 | |
| 4636 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, |
| 4637 | const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) const { |
| 4638 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4639 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 4640 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4641 | } |
| 4642 | |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4643 | template <typename RegionType> |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4644 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
sfricke-samsung | 71f04e3 | 2022-03-16 01:21:21 -0500 | [diff] [blame] | 4645 | VkBuffer dstBuffer, uint32_t regionCount, const RegionType *pRegions, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4646 | CMD_TYPE cmd_type) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4647 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4648 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4649 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4650 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4651 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4652 | assert(context); |
| 4653 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4654 | auto src_image = Get<IMAGE_STATE>(srcImage); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4655 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 4656 | 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] | 4657 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4658 | |
| 4659 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4660 | const auto ©_region = pRegions[region]; |
| 4661 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4662 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4663 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4664 | if (dst_buffer) { |
| 4665 | ResourceAccessRange dst_range = |
| 4666 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4667 | 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] | 4668 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4669 | } |
| 4670 | } |
| 4671 | } |
| 4672 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4673 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4674 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 4675 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4676 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, CMD_COPYIMAGETOBUFFER); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4680 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 4681 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 4682 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4683 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
Tony-LunarG | af3632a | 2021-11-10 15:51:57 -0700 | [diff] [blame] | 4684 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2KHR); |
| 4685 | } |
| 4686 | |
| 4687 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, |
| 4688 | const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) { |
| 4689 | StateTracker::PreCallRecordCmdCopyImageToBuffer2(commandBuffer, pCopyImageToBufferInfo); |
| 4690 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4691 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 4692 | pCopyImageToBufferInfo->pRegions, CMD_COPYIMAGETOBUFFER2); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4693 | } |
| 4694 | |
| 4695 | template <typename RegionType> |
| 4696 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4697 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4698 | const RegionType *pRegions, VkFilter filter, CMD_TYPE cmd_type) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4699 | bool skip = false; |
| 4700 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4701 | assert(cb_access_context); |
| 4702 | if (!cb_access_context) return skip; |
| 4703 | |
| 4704 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4705 | assert(context); |
| 4706 | if (!context) return skip; |
| 4707 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4708 | const char *caller_name = CommandTypeString(cmd_type); |
| 4709 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4710 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4711 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4712 | |
| 4713 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4714 | const auto &blit_region = pRegions[region]; |
| 4715 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4716 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4717 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4718 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4719 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4720 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4721 | 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] | 4722 | auto hazard = |
| 4723 | 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] | 4724 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4725 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4726 | "%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] | 4727 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4728 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4729 | } |
| 4730 | } |
| 4731 | |
| 4732 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4733 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4734 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4735 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4736 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4737 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4738 | 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] | 4739 | auto hazard = |
| 4740 | 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] | 4741 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4742 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4743 | "%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] | 4744 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4745 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4746 | } |
| 4747 | if (skip) break; |
| 4748 | } |
| 4749 | } |
| 4750 | |
| 4751 | return skip; |
| 4752 | } |
| 4753 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4754 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4755 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4756 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 4757 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4758 | CMD_BLITIMAGE); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 4762 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 4763 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4764 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4765 | pBlitImageInfo->filter, CMD_BLITIMAGE2KHR); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4766 | } |
| 4767 | |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4768 | bool SyncValidator::PreCallValidateCmdBlitImage2(VkCommandBuffer commandBuffer, |
| 4769 | const VkBlitImageInfo2 *pBlitImageInfo) const { |
| 4770 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4771 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4772 | pBlitImageInfo->filter, CMD_BLITIMAGE2); |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4773 | } |
| 4774 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4775 | template <typename RegionType> |
| 4776 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4777 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4778 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4779 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4780 | assert(cb_access_context); |
| 4781 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4782 | assert(context); |
| 4783 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4784 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 4785 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4786 | |
| 4787 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4788 | const auto &blit_region = pRegions[region]; |
| 4789 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4790 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4791 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4792 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4793 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4794 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4795 | 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] | 4796 | context->UpdateAccessState(*src_image, SYNC_BLIT_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4797 | blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4798 | } |
| 4799 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4800 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4801 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4802 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4803 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4804 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4805 | 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] | 4806 | context->UpdateAccessState(*dst_image, SYNC_BLIT_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4807 | blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4808 | } |
| 4809 | } |
| 4810 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4811 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4812 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4813 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4814 | const VkImageBlit *pRegions, VkFilter filter) { |
| 4815 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4816 | assert(cb_access_context); |
| 4817 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 4818 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4819 | pRegions, filter); |
| 4820 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 4821 | } |
| 4822 | |
| 4823 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 4824 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 4825 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4826 | assert(cb_access_context); |
| 4827 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 4828 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4829 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4830 | pBlitImageInfo->filter, tag); |
| 4831 | } |
| 4832 | |
Tony-LunarG | 542ae91 | 2021-11-04 16:06:44 -0600 | [diff] [blame] | 4833 | void SyncValidator::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) { |
| 4834 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 4835 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4836 | assert(cb_access_context); |
| 4837 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2); |
| 4838 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4839 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4840 | pBlitImageInfo->filter, tag); |
| 4841 | } |
| 4842 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4843 | bool SyncValidator::ValidateIndirectBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4844 | VkCommandBuffer commandBuffer, const VkDeviceSize struct_size, const VkBuffer buffer, |
| 4845 | const VkDeviceSize offset, const uint32_t drawCount, const uint32_t stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4846 | CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4847 | bool skip = false; |
| 4848 | if (drawCount == 0) return skip; |
| 4849 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4850 | const char *caller_name = CommandTypeString(cmd_type); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4851 | auto buf_state = Get<BUFFER_STATE>(buffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4852 | VkDeviceSize size = struct_size; |
| 4853 | if (drawCount == 1 || stride == size) { |
| 4854 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4855 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4856 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4857 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4858 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4859 | "%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] | 4860 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 4861 | cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4862 | } |
| 4863 | } else { |
| 4864 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4865 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4866 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4867 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4868 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4869 | "%s: Hazard %s for indirect %s in %s. Access info %s.", caller_name, |
| 4870 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(buffer).c_str(), |
| 4871 | report_data->FormatHandle(commandBuffer).c_str(), cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4872 | break; |
| 4873 | } |
| 4874 | } |
| 4875 | } |
| 4876 | return skip; |
| 4877 | } |
| 4878 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 4879 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag tag, const VkDeviceSize struct_size, |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4880 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 4881 | uint32_t stride) { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4882 | auto buf_state = Get<BUFFER_STATE>(buffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4883 | VkDeviceSize size = struct_size; |
| 4884 | if (drawCount == 1 || stride == size) { |
| 4885 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4886 | const ResourceAccessRange range = MakeRange(offset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4887 | 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] | 4888 | } else { |
| 4889 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4890 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4891 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, |
| 4892 | tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4893 | } |
| 4894 | } |
| 4895 | } |
| 4896 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4897 | bool SyncValidator::ValidateCountBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4898 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4899 | CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4900 | bool skip = false; |
| 4901 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4902 | auto count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4903 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4904 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4905 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4906 | skip |= LogError(count_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4907 | "%s: Hazard %s for countBuffer %s in %s. Access info %s.", CommandTypeString(cmd_type), |
| 4908 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(buffer).c_str(), |
| 4909 | report_data->FormatHandle(commandBuffer).c_str(), cb_context.FormatHazard(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4910 | } |
| 4911 | return skip; |
| 4912 | } |
| 4913 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 4914 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag tag, VkBuffer buffer, VkDeviceSize offset) { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4915 | auto count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4916 | const ResourceAccessRange range = MakeRange(offset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4917 | 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] | 4918 | } |
| 4919 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4920 | 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] | 4921 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4922 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4923 | assert(cb_access_context); |
| 4924 | if (!cb_access_context) return skip; |
| 4925 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4926 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4927 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4928 | } |
| 4929 | |
| 4930 | 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] | 4931 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4932 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4933 | assert(cb_access_context); |
| 4934 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4935 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4936 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4937 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4938 | |
| 4939 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4940 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4941 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4942 | assert(cb_access_context); |
| 4943 | if (!cb_access_context) return skip; |
| 4944 | |
| 4945 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4946 | assert(context); |
| 4947 | if (!context) return skip; |
| 4948 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4949 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, CMD_DISPATCHINDIRECT); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4950 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4951 | 1, sizeof(VkDispatchIndirectCommand), CMD_DISPATCHINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4952 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4956 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4957 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4958 | assert(cb_access_context); |
| 4959 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 4960 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4961 | assert(context); |
| 4962 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4963 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 4964 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4965 | } |
| 4966 | |
| 4967 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4968 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4969 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4970 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4971 | assert(cb_access_context); |
| 4972 | if (!cb_access_context) return skip; |
| 4973 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4974 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAW); |
| 4975 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, CMD_DRAW); |
| 4976 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAW); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4977 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4981 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4982 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4983 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4984 | assert(cb_access_context); |
| 4985 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4986 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4987 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4988 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 4989 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4993 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4994 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4995 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4996 | assert(cb_access_context); |
| 4997 | if (!cb_access_context) return skip; |
| 4998 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 4999 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAWINDEXED); |
| 5000 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, CMD_DRAWINDEXED); |
| 5001 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAWINDEXED); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 5002 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 5006 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5007 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5008 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5009 | assert(cb_access_context); |
| 5010 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5011 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5012 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5013 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 5014 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5018 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5019 | bool skip = false; |
| 5020 | if (drawCount == 0) return skip; |
| 5021 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5022 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5023 | assert(cb_access_context); |
| 5024 | if (!cb_access_context) return skip; |
| 5025 | |
| 5026 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5027 | assert(context); |
| 5028 | if (!context) return skip; |
| 5029 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5030 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAWINDIRECT); |
| 5031 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAWINDIRECT); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5032 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5033 | drawCount, stride, CMD_DRAWINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5034 | |
| 5035 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 5036 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5037 | // We will validate the vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5038 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, CMD_DRAWINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5039 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5043 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5044 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5045 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5046 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5047 | assert(cb_access_context); |
| 5048 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 5049 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5050 | assert(context); |
| 5051 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5052 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5053 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5054 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5055 | |
| 5056 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 5057 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5058 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5059 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5063 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5064 | bool skip = false; |
| 5065 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5066 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5067 | assert(cb_access_context); |
| 5068 | if (!cb_access_context) return skip; |
| 5069 | |
| 5070 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5071 | assert(context); |
| 5072 | if (!context) return skip; |
| 5073 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5074 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, CMD_DRAWINDEXEDINDIRECT); |
| 5075 | skip |= cb_access_context->ValidateDrawSubpassAttachment(CMD_DRAWINDEXEDINDIRECT); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5076 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5077 | offset, drawCount, stride, CMD_DRAWINDEXEDINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5078 | |
| 5079 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 5080 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 5081 | // We will validate the index and vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5082 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, CMD_DRAWINDEXEDINDIRECT); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5083 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5087 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5088 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5089 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5090 | assert(cb_access_context); |
| 5091 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 5092 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5093 | assert(context); |
| 5094 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5095 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5096 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5097 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5098 | |
| 5099 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 5100 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 5101 | // 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] | 5102 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5106 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5107 | uint32_t stride, CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5108 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5109 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5110 | assert(cb_access_context); |
| 5111 | if (!cb_access_context) return skip; |
| 5112 | |
| 5113 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5114 | assert(context); |
| 5115 | if (!context) return skip; |
| 5116 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5117 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, cmd_type); |
| 5118 | skip |= cb_access_context->ValidateDrawSubpassAttachment(cmd_type); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5119 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5120 | maxDrawCount, stride, cmd_type); |
| 5121 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5122 | |
| 5123 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 5124 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5125 | // We will validate the vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5126 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5127 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5131 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5132 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5133 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5134 | CMD_DRAWINDIRECTCOUNT); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5135 | } |
| 5136 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5137 | void SyncValidator::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5138 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5139 | uint32_t stride, CMD_TYPE cmd_type) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5140 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5141 | assert(cb_access_context); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5142 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5143 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5144 | assert(context); |
| 5145 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5146 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5147 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5148 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 5149 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5150 | |
| 5151 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 5152 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 5153 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5154 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5155 | } |
| 5156 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5157 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5158 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5159 | uint32_t stride) { |
| 5160 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 5161 | stride); |
| 5162 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5163 | CMD_DRAWINDIRECTCOUNT); |
| 5164 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5165 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5166 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5167 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5168 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5169 | CMD_DRAWINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5170 | } |
| 5171 | |
| 5172 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5173 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5174 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5175 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 5176 | stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5177 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5178 | CMD_DRAWINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5179 | } |
| 5180 | |
| 5181 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5182 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5183 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5184 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5185 | CMD_DRAWINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5186 | } |
| 5187 | |
| 5188 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5189 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5190 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5191 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 5192 | stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5193 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5194 | CMD_DRAWINDIRECTCOUNTAMD); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5198 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5199 | uint32_t stride, CMD_TYPE cmd_type) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5200 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5201 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5202 | assert(cb_access_context); |
| 5203 | if (!cb_access_context) return skip; |
| 5204 | |
| 5205 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5206 | assert(context); |
| 5207 | if (!context) return skip; |
| 5208 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5209 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, cmd_type); |
| 5210 | skip |= cb_access_context->ValidateDrawSubpassAttachment(cmd_type); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5211 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5212 | offset, maxDrawCount, stride, cmd_type); |
| 5213 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5214 | |
| 5215 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 5216 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 5217 | // We will validate the index and vertex buffer in SubmitQueue in the future. |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5218 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5219 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5223 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5224 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5225 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5226 | CMD_DRAWINDEXEDINDIRECTCOUNT); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5227 | } |
| 5228 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5229 | void SyncValidator::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5230 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5231 | uint32_t stride, CMD_TYPE cmd_type) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5232 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5233 | assert(cb_access_context); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5234 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5235 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5236 | assert(context); |
| 5237 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5238 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 5239 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 5240 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 5241 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5242 | |
| 5243 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 5244 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 5245 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 5246 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5247 | } |
| 5248 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5249 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5250 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5251 | uint32_t maxDrawCount, uint32_t stride) { |
| 5252 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 5253 | maxDrawCount, stride); |
| 5254 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5255 | CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 5256 | } |
| 5257 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5258 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5259 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5260 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5261 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5262 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5263 | CMD_DRAWINDEXEDINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5264 | } |
| 5265 | |
| 5266 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5267 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5268 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5269 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 5270 | maxDrawCount, stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5271 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5272 | CMD_DRAWINDEXEDINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5276 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5277 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5278 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5279 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5280 | CMD_DRAWINDEXEDINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5284 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5285 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5286 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 5287 | maxDrawCount, stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 5288 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5289 | CMD_DRAWINDEXEDINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5293 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 5294 | const VkImageSubresourceRange *pRanges) const { |
| 5295 | bool skip = false; |
| 5296 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5297 | assert(cb_access_context); |
| 5298 | if (!cb_access_context) return skip; |
| 5299 | |
| 5300 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5301 | assert(context); |
| 5302 | if (!context) return skip; |
| 5303 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5304 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5305 | |
| 5306 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5307 | const auto &range = pRanges[index]; |
| 5308 | if (image_state) { |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5309 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5310 | if (hazard.hazard) { |
| 5311 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5312 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5313 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5314 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5315 | } |
| 5316 | } |
| 5317 | } |
| 5318 | return skip; |
| 5319 | } |
| 5320 | |
| 5321 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5322 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 5323 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5324 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5325 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5326 | assert(cb_access_context); |
| 5327 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 5328 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5329 | assert(context); |
| 5330 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5331 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5332 | |
| 5333 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5334 | const auto &range = pRanges[index]; |
| 5335 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5336 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5337 | } |
| 5338 | } |
| 5339 | } |
| 5340 | |
| 5341 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 5342 | VkImageLayout imageLayout, |
| 5343 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 5344 | const VkImageSubresourceRange *pRanges) const { |
| 5345 | bool skip = false; |
| 5346 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5347 | assert(cb_access_context); |
| 5348 | if (!cb_access_context) return skip; |
| 5349 | |
| 5350 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5351 | assert(context); |
| 5352 | if (!context) return skip; |
| 5353 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5354 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5355 | |
| 5356 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5357 | const auto &range = pRanges[index]; |
| 5358 | if (image_state) { |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 5359 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5360 | if (hazard.hazard) { |
| 5361 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5362 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5363 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5364 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5365 | } |
| 5366 | } |
| 5367 | } |
| 5368 | return skip; |
| 5369 | } |
| 5370 | |
| 5371 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 5372 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 5373 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5374 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5375 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5376 | assert(cb_access_context); |
| 5377 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 5378 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5379 | assert(context); |
| 5380 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5381 | auto image_state = Get<IMAGE_STATE>(image); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5382 | |
| 5383 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 5384 | const auto &range = pRanges[index]; |
| 5385 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5386 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5387 | } |
| 5388 | } |
| 5389 | } |
| 5390 | |
| 5391 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 5392 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 5393 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 5394 | VkQueryResultFlags flags) const { |
| 5395 | bool skip = false; |
| 5396 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5397 | assert(cb_access_context); |
| 5398 | if (!cb_access_context) return skip; |
| 5399 | |
| 5400 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5401 | assert(context); |
| 5402 | if (!context) return skip; |
| 5403 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5404 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5405 | |
| 5406 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5407 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5408 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5409 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5410 | skip |= |
| 5411 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5412 | "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] | 5413 | 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] | 5414 | } |
| 5415 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5416 | |
| 5417 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5418 | return skip; |
| 5419 | } |
| 5420 | |
| 5421 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 5422 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5423 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5424 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 5425 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5426 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5427 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5428 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5429 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5430 | assert(context); |
| 5431 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5432 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5433 | |
| 5434 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5435 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5436 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5437 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5438 | |
| 5439 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5443 | VkDeviceSize size, uint32_t data) const { |
| 5444 | bool skip = false; |
| 5445 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5446 | assert(cb_access_context); |
| 5447 | if (!cb_access_context) return skip; |
| 5448 | |
| 5449 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5450 | assert(context); |
| 5451 | if (!context) return skip; |
| 5452 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5453 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5454 | |
| 5455 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5456 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5457 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5458 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5459 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5460 | "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] | 5461 | 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] | 5462 | } |
| 5463 | } |
| 5464 | return skip; |
| 5465 | } |
| 5466 | |
| 5467 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5468 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5469 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5470 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5471 | assert(cb_access_context); |
| 5472 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 5473 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5474 | assert(context); |
| 5475 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5476 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5477 | |
| 5478 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5479 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5480 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5481 | } |
| 5482 | } |
| 5483 | |
| 5484 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 5485 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 5486 | const VkImageResolve *pRegions) const { |
| 5487 | bool skip = false; |
| 5488 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5489 | assert(cb_access_context); |
| 5490 | if (!cb_access_context) return skip; |
| 5491 | |
| 5492 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5493 | assert(context); |
| 5494 | if (!context) return skip; |
| 5495 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5496 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 5497 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5498 | |
| 5499 | for (uint32_t region = 0; region < regionCount; region++) { |
| 5500 | const auto &resolve_region = pRegions[region]; |
| 5501 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5502 | 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] | 5503 | resolve_region.srcOffset, resolve_region.extent, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5504 | if (hazard.hazard) { |
| 5505 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5506 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5507 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5508 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5509 | } |
| 5510 | } |
| 5511 | |
| 5512 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5513 | 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] | 5514 | resolve_region.dstOffset, resolve_region.extent, false); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5515 | if (hazard.hazard) { |
| 5516 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5517 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5518 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5519 | cb_access_context->FormatHazard(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5520 | } |
| 5521 | if (skip) break; |
| 5522 | } |
| 5523 | } |
| 5524 | |
| 5525 | return skip; |
| 5526 | } |
| 5527 | |
| 5528 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 5529 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 5530 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5531 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 5532 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5533 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5534 | assert(cb_access_context); |
| 5535 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 5536 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5537 | assert(context); |
| 5538 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 5539 | auto src_image = Get<IMAGE_STATE>(srcImage); |
| 5540 | auto dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5541 | |
| 5542 | for (uint32_t region = 0; region < regionCount; region++) { |
| 5543 | const auto &resolve_region = pRegions[region]; |
| 5544 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5545 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5546 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5547 | } |
| 5548 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5549 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5550 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5551 | } |
| 5552 | } |
| 5553 | } |
| 5554 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5555 | bool SyncValidator::ValidateCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2KHR *pResolveImageInfo, |
| 5556 | CMD_TYPE cmd_type) const { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5557 | bool skip = false; |
| 5558 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5559 | assert(cb_access_context); |
| 5560 | if (!cb_access_context) return skip; |
| 5561 | |
| 5562 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5563 | assert(context); |
| 5564 | if (!context) return skip; |
| 5565 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5566 | auto src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 5567 | auto dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5568 | |
| 5569 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 5570 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 5571 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5572 | 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] | 5573 | resolve_region.srcOffset, resolve_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5574 | if (hazard.hazard) { |
| 5575 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5576 | "%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] | 5577 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5578 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5579 | } |
| 5580 | } |
| 5581 | |
| 5582 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5583 | 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] | 5584 | resolve_region.dstOffset, resolve_region.extent, false); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5585 | if (hazard.hazard) { |
| 5586 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5587 | "%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] | 5588 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 5589 | region, cb_access_context->FormatHazard(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5590 | } |
| 5591 | if (skip) break; |
| 5592 | } |
| 5593 | } |
| 5594 | |
| 5595 | return skip; |
| 5596 | } |
| 5597 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5598 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 5599 | const VkResolveImageInfo2KHR *pResolveImageInfo) const { |
| 5600 | return ValidateCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2KHR); |
| 5601 | } |
| 5602 | |
| 5603 | bool SyncValidator::PreCallValidateCmdResolveImage2(VkCommandBuffer commandBuffer, |
| 5604 | const VkResolveImageInfo2 *pResolveImageInfo) const { |
| 5605 | return ValidateCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2); |
| 5606 | } |
| 5607 | |
| 5608 | void SyncValidator::RecordCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2KHR *pResolveImageInfo, |
| 5609 | CMD_TYPE cmd_type) { |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5610 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 5611 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5612 | assert(cb_access_context); |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5613 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5614 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5615 | assert(context); |
| 5616 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 5617 | auto src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 5618 | auto dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5619 | |
| 5620 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 5621 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 5622 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5623 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5624 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5625 | } |
| 5626 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5627 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5628 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5629 | } |
| 5630 | } |
| 5631 | } |
| 5632 | |
Tony-LunarG | 562fc10 | 2021-11-12 13:58:35 -0700 | [diff] [blame] | 5633 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 5634 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 5635 | RecordCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2KHR); |
| 5636 | } |
| 5637 | |
| 5638 | void SyncValidator::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer, const VkResolveImageInfo2 *pResolveImageInfo) { |
| 5639 | RecordCmdResolveImage2(commandBuffer, pResolveImageInfo, CMD_RESOLVEIMAGE2); |
| 5640 | } |
| 5641 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5642 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5643 | VkDeviceSize dataSize, const void *pData) const { |
| 5644 | bool skip = false; |
| 5645 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5646 | assert(cb_access_context); |
| 5647 | if (!cb_access_context) return skip; |
| 5648 | |
| 5649 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5650 | assert(context); |
| 5651 | if (!context) return skip; |
| 5652 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5653 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5654 | |
| 5655 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5656 | // VK_WHOLE_SIZE not allowed |
| 5657 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5658 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5659 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5660 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5661 | "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] | 5662 | 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] | 5663 | } |
| 5664 | } |
| 5665 | return skip; |
| 5666 | } |
| 5667 | |
| 5668 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5669 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5670 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5671 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5672 | assert(cb_access_context); |
| 5673 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 5674 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5675 | assert(context); |
| 5676 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5677 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5678 | |
| 5679 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5680 | // VK_WHOLE_SIZE not allowed |
| 5681 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5682 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5683 | } |
| 5684 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5685 | |
| 5686 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 5687 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 5688 | bool skip = false; |
| 5689 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5690 | assert(cb_access_context); |
| 5691 | if (!cb_access_context) return skip; |
| 5692 | |
| 5693 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5694 | assert(context); |
| 5695 | if (!context) return skip; |
| 5696 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5697 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5698 | |
| 5699 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5700 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5701 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5702 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5703 | skip |= |
| 5704 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5705 | "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] | 5706 | 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] | 5707 | } |
| 5708 | } |
| 5709 | return skip; |
| 5710 | } |
| 5711 | |
| 5712 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 5713 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5714 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5715 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5716 | assert(cb_access_context); |
| 5717 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 5718 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5719 | assert(context); |
| 5720 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 5721 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5722 | |
| 5723 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5724 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5725 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5726 | } |
| 5727 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5728 | |
| 5729 | bool SyncValidator::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
| 5730 | bool skip = false; |
| 5731 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5732 | assert(cb_context); |
| 5733 | if (!cb_context) return skip; |
| 5734 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5735 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5736 | return set_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | void SyncValidator::PostCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 5740 | StateTracker::PostCallRecordCmdSetEvent(commandBuffer, event, stageMask); |
| 5741 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5742 | assert(cb_context); |
| 5743 | if (!cb_context) return; |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5744 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5745 | } |
| 5746 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5747 | bool SyncValidator::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5748 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 5749 | bool skip = false; |
| 5750 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5751 | assert(cb_context); |
| 5752 | if (!cb_context || !pDependencyInfo) return skip; |
| 5753 | |
| 5754 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 5755 | return set_event_op.Validate(*cb_context); |
| 5756 | } |
| 5757 | |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5758 | bool SyncValidator::PreCallValidateCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5759 | const VkDependencyInfo *pDependencyInfo) const { |
| 5760 | bool skip = false; |
| 5761 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5762 | assert(cb_context); |
| 5763 | if (!cb_context || !pDependencyInfo) return skip; |
| 5764 | |
| 5765 | SyncOpSetEvent set_event_op(CMD_SETEVENT2, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 5766 | return set_event_op.Validate(*cb_context); |
| 5767 | } |
| 5768 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5769 | void SyncValidator::PostCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5770 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 5771 | StateTracker::PostCallRecordCmdSetEvent2KHR(commandBuffer, event, pDependencyInfo); |
| 5772 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5773 | assert(cb_context); |
| 5774 | if (!cb_context || !pDependencyInfo) return; |
| 5775 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5776 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
Tony-LunarG | c43525f | 2021-11-15 16:12:38 -0700 | [diff] [blame] | 5779 | void SyncValidator::PostCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5780 | const VkDependencyInfo *pDependencyInfo) { |
| 5781 | StateTracker::PostCallRecordCmdSetEvent2(commandBuffer, event, pDependencyInfo); |
| 5782 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5783 | assert(cb_context); |
| 5784 | if (!cb_context || !pDependencyInfo) return; |
| 5785 | |
| 5786 | cb_context->RecordSyncOp<SyncOpSetEvent>(CMD_SETEVENT2, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 5787 | } |
| 5788 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5789 | bool SyncValidator::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 5790 | VkPipelineStageFlags stageMask) const { |
| 5791 | bool skip = false; |
| 5792 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5793 | assert(cb_context); |
| 5794 | if (!cb_context) return skip; |
| 5795 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5796 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5797 | return reset_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | void SyncValidator::PostCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 5801 | StateTracker::PostCallRecordCmdResetEvent(commandBuffer, event, stageMask); |
| 5802 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5803 | assert(cb_context); |
| 5804 | if (!cb_context) return; |
| 5805 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5806 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5807 | } |
| 5808 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5809 | bool SyncValidator::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5810 | VkPipelineStageFlags2KHR stageMask) const { |
| 5811 | bool skip = false; |
| 5812 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5813 | assert(cb_context); |
| 5814 | if (!cb_context) return skip; |
| 5815 | |
| 5816 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5817 | return reset_event_op.Validate(*cb_context); |
| 5818 | } |
| 5819 | |
Tony-LunarG | a2662db | 2021-11-16 07:26:24 -0700 | [diff] [blame] | 5820 | bool SyncValidator::PreCallValidateCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 5821 | VkPipelineStageFlags2 stageMask) const { |
| 5822 | bool skip = false; |
| 5823 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5824 | assert(cb_context); |
| 5825 | if (!cb_context) return skip; |
| 5826 | |
| 5827 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5828 | return reset_event_op.Validate(*cb_context); |
| 5829 | } |
| 5830 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5831 | void SyncValidator::PostCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5832 | VkPipelineStageFlags2KHR stageMask) { |
| 5833 | StateTracker::PostCallRecordCmdResetEvent2KHR(commandBuffer, event, stageMask); |
| 5834 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5835 | assert(cb_context); |
| 5836 | if (!cb_context) return; |
| 5837 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5838 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5839 | } |
| 5840 | |
Tony-LunarG | a2662db | 2021-11-16 07:26:24 -0700 | [diff] [blame] | 5841 | void SyncValidator::PostCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2 stageMask) { |
| 5842 | StateTracker::PostCallRecordCmdResetEvent2(commandBuffer, event, stageMask); |
| 5843 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5844 | assert(cb_context); |
| 5845 | if (!cb_context) return; |
| 5846 | |
| 5847 | cb_context->RecordSyncOp<SyncOpResetEvent>(CMD_RESETEVENT2, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5848 | } |
| 5849 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5850 | bool SyncValidator::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5851 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5852 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5853 | uint32_t bufferMemoryBarrierCount, |
| 5854 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5855 | uint32_t imageMemoryBarrierCount, |
| 5856 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 5857 | bool skip = false; |
| 5858 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5859 | assert(cb_context); |
| 5860 | if (!cb_context) return skip; |
| 5861 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5862 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 5863 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 5864 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5865 | return wait_events_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5866 | } |
| 5867 | |
| 5868 | void SyncValidator::PostCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5869 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5870 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5871 | uint32_t bufferMemoryBarrierCount, |
| 5872 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5873 | uint32_t imageMemoryBarrierCount, |
| 5874 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 5875 | StateTracker::PostCallRecordCmdWaitEvents(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
| 5876 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 5877 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 5878 | |
| 5879 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5880 | assert(cb_context); |
| 5881 | if (!cb_context) return; |
| 5882 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5883 | cb_context->RecordSyncOp<SyncOpWaitEvents>( |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 5884 | CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5885 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5886 | } |
| 5887 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5888 | bool SyncValidator::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5889 | const VkDependencyInfoKHR *pDependencyInfos) const { |
| 5890 | bool skip = false; |
| 5891 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5892 | assert(cb_context); |
| 5893 | if (!cb_context) return skip; |
| 5894 | |
| 5895 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 5896 | skip |= wait_events_op.Validate(*cb_context); |
| 5897 | return skip; |
| 5898 | } |
| 5899 | |
| 5900 | void SyncValidator::PostCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5901 | const VkDependencyInfoKHR *pDependencyInfos) { |
| 5902 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 5903 | |
| 5904 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5905 | assert(cb_context); |
| 5906 | if (!cb_context) return; |
| 5907 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 5908 | cb_context->RecordSyncOp<SyncOpWaitEvents>(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, |
| 5909 | pDependencyInfos); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5910 | } |
| 5911 | |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 5912 | bool SyncValidator::PreCallValidateCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5913 | const VkDependencyInfo *pDependencyInfos) const { |
| 5914 | bool skip = false; |
| 5915 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5916 | assert(cb_context); |
| 5917 | if (!cb_context) return skip; |
| 5918 | |
| 5919 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 5920 | skip |= wait_events_op.Validate(*cb_context); |
| 5921 | return skip; |
| 5922 | } |
| 5923 | |
| 5924 | void SyncValidator::PostCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5925 | const VkDependencyInfo *pDependencyInfos) { |
| 5926 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 5927 | |
| 5928 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5929 | assert(cb_context); |
| 5930 | if (!cb_context) return; |
| 5931 | |
| 5932 | cb_context->RecordSyncOp<SyncOpWaitEvents>(CMD_WAITEVENTS2, *this, cb_context->GetQueueFlags(), eventCount, pEvents, |
| 5933 | pDependencyInfos); |
| 5934 | } |
| 5935 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5936 | void SyncEventState::ResetFirstScope() { |
| 5937 | for (const auto address_type : kAddressTypes) { |
| 5938 | first_scope[static_cast<size_t>(address_type)].clear(); |
| 5939 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 5940 | scope = SyncExecScope(); |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 5941 | first_scope_set = false; |
| 5942 | first_scope_tag = 0; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5943 | } |
| 5944 | |
| 5945 | // 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] | 5946 | SyncEventState::IgnoreReason SyncEventState::IsIgnoredByWait(CMD_TYPE cmd_type, VkPipelineStageFlags2KHR srcStageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5947 | IgnoreReason reason = NotIgnored; |
| 5948 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5949 | 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] | 5950 | reason = SetVsWait2; |
| 5951 | } else if ((last_command == CMD_RESETEVENT || last_command == CMD_RESETEVENT2KHR) && !HasBarrier(0U, 0U)) { |
| 5952 | reason = (last_command == CMD_RESETEVENT) ? ResetWaitRace : Reset2WaitRace; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5953 | } else if (unsynchronized_set) { |
| 5954 | reason = SetRace; |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 5955 | } else if (first_scope_set) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5956 | const VkPipelineStageFlags2KHR missing_bits = scope.mask_param & ~srcStageMask; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5957 | if (missing_bits) reason = MissingStageBits; |
| 5958 | } |
| 5959 | |
| 5960 | return reason; |
| 5961 | } |
| 5962 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5963 | bool SyncEventState::HasBarrier(VkPipelineStageFlags2KHR stageMask, VkPipelineStageFlags2KHR exec_scope_arg) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5964 | bool has_barrier = (last_command == CMD_NONE) || (stageMask & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) || |
| 5965 | (barriers & exec_scope_arg) || (barriers & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 5966 | return has_barrier; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5967 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5968 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 5969 | void SyncOpBase::SetReplayContext(uint32_t subpass, ReplayContextPtr &&replay) { |
| 5970 | subpass_ = subpass; |
| 5971 | replay_context_ = std::move(replay); |
| 5972 | } |
| 5973 | |
| 5974 | const ReplayTrackbackBarriersAction *SyncOpBase::GetReplayTrackback() const { |
| 5975 | if (replay_context_) { |
| 5976 | assert(subpass_ < replay_context_->subpass_contexts.size()); |
| 5977 | return &replay_context_->subpass_contexts[subpass_]; |
| 5978 | } |
| 5979 | return nullptr; |
| 5980 | } |
| 5981 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5982 | 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] | 5983 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5984 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5985 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5986 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5987 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 5988 | : SyncOpBase(cmd_type), barriers_(1) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5989 | auto &barrier_set = barriers_[0]; |
| 5990 | barrier_set.dependency_flags = dependencyFlags; |
| 5991 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, srcStageMask); |
| 5992 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, dstStageMask); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5993 | // 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] | 5994 | barrier_set.MakeMemoryBarriers(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, memoryBarrierCount, |
| 5995 | pMemoryBarriers); |
| 5996 | barrier_set.MakeBufferMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 5997 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
| 5998 | barrier_set.MakeImageMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 5999 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6000 | } |
| 6001 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6002 | 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] | 6003 | const VkDependencyInfoKHR *dep_infos) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6004 | : SyncOpBase(cmd_type), barriers_(event_count) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6005 | for (uint32_t i = 0; i < event_count; i++) { |
| 6006 | const auto &dep_info = dep_infos[i]; |
| 6007 | auto &barrier_set = barriers_[i]; |
| 6008 | barrier_set.dependency_flags = dep_info.dependencyFlags; |
| 6009 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 6010 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, stage_masks.src); |
| 6011 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, stage_masks.dst); |
| 6012 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
| 6013 | barrier_set.MakeMemoryBarriers(queue_flags, dep_info.dependencyFlags, dep_info.memoryBarrierCount, |
| 6014 | dep_info.pMemoryBarriers); |
| 6015 | barrier_set.MakeBufferMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.bufferMemoryBarrierCount, |
| 6016 | dep_info.pBufferMemoryBarriers); |
| 6017 | barrier_set.MakeImageMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.imageMemoryBarrierCount, |
| 6018 | dep_info.pImageMemoryBarriers); |
| 6019 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6020 | } |
| 6021 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6022 | 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] | 6023 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 6024 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 6025 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 6026 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 6027 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6028 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, |
| 6029 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 6030 | pImageMemoryBarriers) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6031 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6032 | 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] | 6033 | const VkDependencyInfoKHR &dep_info) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6034 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, 1, &dep_info) {} |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6035 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6036 | bool SyncOpPipelineBarrier::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6037 | bool skip = false; |
| 6038 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 6039 | assert(context); |
| 6040 | if (!context) return skip; |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 6041 | assert(barriers_.size() == 1); // PipelineBarriers only support a single barrier set. |
| 6042 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6043 | // Validate Image Layout transitions |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 6044 | const auto &barrier_set = barriers_[0]; |
| 6045 | for (const auto &image_barrier : barrier_set.image_memory_barriers) { |
| 6046 | if (image_barrier.new_layout == image_barrier.old_layout) continue; // Only interested in layout transitions at this point. |
| 6047 | const auto *image_state = image_barrier.image.get(); |
| 6048 | if (!image_state) continue; |
| 6049 | const auto hazard = context->DetectImageBarrierHazard(image_barrier); |
| 6050 | if (hazard.hazard) { |
| 6051 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 6052 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6053 | const auto image_handle = image_state->image(); |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 6054 | skip |= sync_state.LogError(image_handle, string_SyncHazardVUID(hazard.hazard), |
| 6055 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 6056 | string_SyncHazard(hazard.hazard), image_barrier.index, |
| 6057 | sync_state.report_data->FormatHandle(image_handle).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6058 | cb_context.FormatHazard(hazard).c_str()); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6059 | } |
| 6060 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6061 | return skip; |
| 6062 | } |
| 6063 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6064 | struct SyncOpPipelineBarrierFunctorFactory { |
| 6065 | using BarrierOpFunctor = PipelineBarrierOp; |
| 6066 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 6067 | using GlobalBarrierOpFunctor = PipelineBarrierOp; |
| 6068 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 6069 | using BufferRange = ResourceAccessRange; |
| 6070 | using ImageRange = subresource_adapter::ImageRangeGenerator; |
| 6071 | using GlobalRange = ResourceAccessRange; |
| 6072 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6073 | ApplyFunctor MakeApplyFunctor(QueueId queue_id, const SyncBarrier &barrier, bool layout_transition) const { |
| 6074 | return ApplyFunctor(BarrierOpFunctor(queue_id, barrier, layout_transition)); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6075 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 6076 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6077 | return GlobalApplyFunctor(true /* resolve */, size_hint, tag); |
| 6078 | } |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6079 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(QueueId queue_id, const SyncBarrier &barrier) const { |
| 6080 | return GlobalBarrierOpFunctor(queue_id, barrier, false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6081 | } |
| 6082 | |
| 6083 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range) const { |
| 6084 | if (!SimpleBinding(buffer)) return ResourceAccessRange(); |
| 6085 | const auto base_address = ResourceBaseAddress(buffer); |
| 6086 | return (range + base_address); |
| 6087 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 6088 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 6089 | if (!SimpleBinding(image)) return subresource_adapter::ImageRangeGenerator(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6090 | |
| 6091 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 6092 | 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] | 6093 | return range_gen; |
| 6094 | } |
| 6095 | GlobalRange MakeGlobalRangeGen(AccessAddressType) const { return kFullRange; } |
| 6096 | }; |
| 6097 | |
| 6098 | template <typename Barriers, typename FunctorFactory> |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6099 | void SyncOpBarriers::ApplyBarriers(const Barriers &barriers, const FunctorFactory &factory, const QueueId queue_id, |
| 6100 | const ResourceUsageTag tag, AccessContext *context) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6101 | for (const auto &barrier : barriers) { |
| 6102 | const auto *state = barrier.GetState(); |
| 6103 | if (state) { |
| 6104 | auto *const accesses = &context->GetAccessStateMap(GetAccessAddressType(*state)); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6105 | auto update_action = factory.MakeApplyFunctor(queue_id, barrier.barrier, barrier.IsLayoutTransition()); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6106 | auto range_gen = factory.MakeRangeGen(*state, barrier.Range()); |
| 6107 | UpdateMemoryAccessState(accesses, update_action, &range_gen); |
| 6108 | } |
| 6109 | } |
| 6110 | } |
| 6111 | |
| 6112 | template <typename Barriers, typename FunctorFactory> |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6113 | void SyncOpBarriers::ApplyGlobalBarriers(const Barriers &barriers, const FunctorFactory &factory, const QueueId queue_id, |
| 6114 | const ResourceUsageTag tag, AccessContext *access_context) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6115 | auto barriers_functor = factory.MakeGlobalApplyFunctor(barriers.size(), tag); |
| 6116 | for (const auto &barrier : barriers) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6117 | barriers_functor.EmplaceBack(factory.MakeGlobalBarrierOpFunctor(queue_id, barrier)); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6118 | } |
| 6119 | for (const auto address_type : kAddressTypes) { |
| 6120 | auto range_gen = factory.MakeGlobalRangeGen(address_type); |
| 6121 | UpdateMemoryAccessState(&(access_context->GetAccessStateMap(address_type)), barriers_functor, &range_gen); |
| 6122 | } |
| 6123 | } |
| 6124 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6125 | ResourceUsageTag SyncOpPipelineBarrier::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6126 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6127 | auto *events_context = cb_context->GetCurrentEventsContext(); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6128 | const QueueId queue_id = cb_context->GetQueueId(); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6129 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6130 | ReplayRecord(queue_id, tag, access_context, events_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6131 | return tag; |
| 6132 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6133 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6134 | void SyncOpPipelineBarrier::ReplayRecord(QueueId queue_id, const ResourceUsageTag tag, AccessContext *access_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6135 | SyncEventsContext *events_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6136 | SyncOpPipelineBarrierFunctorFactory factory; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6137 | // Pipeline barriers only have a single barrier set, unlike WaitEvents2 |
| 6138 | assert(barriers_.size() == 1); |
| 6139 | const auto &barrier_set = barriers_[0]; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6140 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, queue_id, tag, access_context); |
| 6141 | ApplyBarriers(barrier_set.image_memory_barriers, factory, queue_id, tag, access_context); |
| 6142 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, queue_id, tag, access_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6143 | if (barrier_set.single_exec_scope) { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6144 | events_context->ApplyBarrier(barrier_set.src_exec_scope, barrier_set.dst_exec_scope); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6145 | } else { |
| 6146 | for (const auto &barrier : barrier_set.memory_barriers) { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6147 | events_context->ApplyBarrier(barrier.src_exec_scope, barrier.dst_exec_scope); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6148 | } |
| 6149 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6150 | } |
| 6151 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6152 | bool SyncOpPipelineBarrier::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6153 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6154 | // No Validation for replay, as the layout transition accesses are checked directly, and the src*Mask ordering is captured |
| 6155 | // with first access information. |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6156 | return false; |
| 6157 | } |
| 6158 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6159 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(const SyncExecScope &src, const SyncExecScope &dst, |
| 6160 | VkDependencyFlags dependency_flags, uint32_t memory_barrier_count, |
| 6161 | const VkMemoryBarrier *barriers) { |
| 6162 | memory_barriers.reserve(std::max<uint32_t>(1, memory_barrier_count)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6163 | 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] | 6164 | const auto &barrier = barriers[barrier_index]; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6165 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6166 | memory_barriers.emplace_back(sync_barrier); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6167 | } |
| 6168 | if (0 == memory_barrier_count) { |
| 6169 | // If there are no global memory barriers, force an exec barrier |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6170 | memory_barriers.emplace_back(SyncBarrier(src, dst)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6171 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6172 | single_exec_scope = true; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6173 | } |
| 6174 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6175 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 6176 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 6177 | uint32_t barrier_count, const VkBufferMemoryBarrier *barriers) { |
| 6178 | buffer_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6179 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6180 | const auto &barrier = barriers[index]; |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6181 | auto buffer = sync_state.Get<BUFFER_STATE>(barrier.buffer); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6182 | if (buffer) { |
| 6183 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 6184 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 6185 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6186 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6187 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6188 | buffer_memory_barriers.emplace_back(); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6189 | } |
| 6190 | } |
| 6191 | } |
| 6192 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6193 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(VkQueueFlags queue_flags, VkDependencyFlags dependency_flags, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 6194 | uint32_t memory_barrier_count, const VkMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6195 | memory_barriers.reserve(memory_barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6196 | 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] | 6197 | const auto &barrier = barriers[barrier_index]; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6198 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 6199 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 6200 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6201 | memory_barriers.emplace_back(sync_barrier); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6202 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6203 | single_exec_scope = false; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6204 | } |
| 6205 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6206 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6207 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 6208 | const VkBufferMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6209 | buffer_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6210 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6211 | const auto &barrier = barriers[index]; |
| 6212 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 6213 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6214 | auto buffer = sync_state.Get<BUFFER_STATE>(barrier.buffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6215 | if (buffer) { |
| 6216 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 6217 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 6218 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6219 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6220 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6221 | buffer_memory_barriers.emplace_back(); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6222 | } |
| 6223 | } |
| 6224 | } |
| 6225 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6226 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 6227 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 6228 | uint32_t barrier_count, const VkImageMemoryBarrier *barriers) { |
| 6229 | image_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6230 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6231 | const auto &barrier = barriers[index]; |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6232 | auto image = sync_state.Get<IMAGE_STATE>(barrier.image); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 6233 | if (image) { |
| 6234 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 6235 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6236 | 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] | 6237 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6238 | image_memory_barriers.emplace_back(); |
| 6239 | 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] | 6240 | } |
| 6241 | } |
| 6242 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6243 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6244 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6245 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
Tony-LunarG | 3f6eceb | 2021-11-18 14:34:49 -0700 | [diff] [blame] | 6246 | const VkImageMemoryBarrier2 *barriers) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6247 | image_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6248 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 6249 | const auto &barrier = barriers[index]; |
| 6250 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 6251 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6252 | auto image = sync_state.Get<IMAGE_STATE>(barrier.image); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6253 | if (image) { |
| 6254 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 6255 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6256 | 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] | 6257 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6258 | image_memory_barriers.emplace_back(); |
| 6259 | 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] | 6260 | } |
| 6261 | } |
| 6262 | } |
| 6263 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6264 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6265 | uint32_t eventCount, const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, |
| 6266 | VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, |
| 6267 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 6268 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 6269 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
| 6270 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, srcStageMask, dstStageMask, VkDependencyFlags(0U), memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6271 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 6272 | pImageMemoryBarriers) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6273 | MakeEventsList(sync_state, eventCount, pEvents); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6274 | } |
| 6275 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6276 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd_type, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 6277 | uint32_t eventCount, const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfo) |
| 6278 | : SyncOpBarriers(cmd_type, sync_state, queue_flags, eventCount, pDependencyInfo) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6279 | MakeEventsList(sync_state, eventCount, pEvents); |
| 6280 | assert(events_.size() == barriers_.size()); // Just so nobody gets clever and decides to cull the event or barrier arrays |
| 6281 | } |
| 6282 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6283 | const char *const SyncOpWaitEvents::kIgnored = "Wait operation is ignored for this event."; |
| 6284 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6285 | bool SyncOpWaitEvents::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6286 | bool skip = false; |
| 6287 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6288 | const auto command_buffer_handle = cb_context.GetCBState().commandBuffer(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6289 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6290 | // This is only interesting at record and not replay (Execute/Submit) time. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6291 | for (size_t barrier_set_index = 0; barrier_set_index < barriers_.size(); barrier_set_index++) { |
| 6292 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6293 | if (barrier_set.single_exec_scope) { |
| 6294 | if (barrier_set.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 6295 | const std::string vuid = std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 6296 | skip = sync_state.LogInfo(command_buffer_handle, vuid, |
| 6297 | "%s, srcStageMask includes %s, unsupported by synchronization validation.", CmdName(), |
| 6298 | string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT)); |
| 6299 | } else { |
| 6300 | const auto &barriers = barrier_set.memory_barriers; |
| 6301 | for (size_t barrier_index = 0; barrier_index < barriers.size(); barrier_index++) { |
| 6302 | const auto &barrier = barriers[barrier_index]; |
| 6303 | if (barrier.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 6304 | const std::string vuid = |
| 6305 | std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 6306 | skip = |
| 6307 | sync_state.LogInfo(command_buffer_handle, vuid, |
| 6308 | "%s, srcStageMask %s of %s %zu, %s %zu, unsupported by synchronization validation.", |
| 6309 | CmdName(), string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT), |
| 6310 | "pDependencyInfo", barrier_set_index, "pMemoryBarriers", barrier_index); |
| 6311 | } |
| 6312 | } |
| 6313 | } |
| 6314 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6315 | } |
| 6316 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6317 | // The rest is common to record time and replay time. |
| 6318 | skip |= DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6319 | return skip; |
| 6320 | } |
| 6321 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6322 | bool SyncOpWaitEvents::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6323 | bool skip = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6324 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6325 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6326 | VkPipelineStageFlags2KHR event_stage_masks = 0U; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6327 | VkPipelineStageFlags2KHR barrier_mask_params = 0U; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6328 | bool events_not_found = false; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6329 | const auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6330 | assert(events_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6331 | size_t barrier_set_index = 0; |
| 6332 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6333 | for (const auto &event : events_) { |
| 6334 | const auto *sync_event = events_context->Get(event.get()); |
| 6335 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6336 | if (!sync_event) { |
| 6337 | // NOTE PHASE2: This is where we'll need queue submit time validation to come back and check the srcStageMask bits |
| 6338 | // or solve this with replay creating the SyncEventState in the queue context... also this will be a |
| 6339 | // new validation error... wait without previously submitted set event... |
| 6340 | 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] | 6341 | barrier_set_index += barrier_set_incr; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6342 | continue; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6343 | } |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6344 | |
| 6345 | // For replay calls, don't revalidate "same command buffer" events |
| 6346 | if (sync_event->last_command_tag > base_tag) continue; |
| 6347 | |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6348 | const auto event_handle = sync_event->event->event(); |
| 6349 | // TODO add "destroyed" checks |
| 6350 | |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6351 | if (sync_event->first_scope_set) { |
| 6352 | // Only accumulate barrier and event stages if there is a pending set in the current context |
| 6353 | barrier_mask_params |= barrier_set.src_exec_scope.mask_param; |
| 6354 | event_stage_masks |= sync_event->scope.mask_param; |
| 6355 | } |
| 6356 | |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6357 | const auto &src_exec_scope = barrier_set.src_exec_scope; |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6358 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6359 | 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] | 6360 | if (ignore_reason) { |
| 6361 | switch (ignore_reason) { |
| 6362 | case SyncEventState::ResetWaitRace: |
| 6363 | case SyncEventState::Reset2WaitRace: { |
| 6364 | // Four permuations of Reset and Wait calls... |
| 6365 | const char *vuid = |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6366 | (cmd_type_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent-event-03834" : "VUID-vkCmdResetEvent-event-03835"; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6367 | if (ignore_reason == SyncEventState::Reset2WaitRace) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6368 | vuid = (cmd_type_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent2-event-03831" |
| 6369 | : "VUID-vkCmdResetEvent2-event-03832"; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6370 | } |
| 6371 | const char *const message = |
| 6372 | "%s: %s %s operation following %s without intervening execution barrier, may cause race condition. %s"; |
| 6373 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6374 | sync_state.report_data->FormatHandle(event_handle).c_str(), CmdName(), |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6375 | CommandTypeString(sync_event->last_command), kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6376 | break; |
| 6377 | } |
| 6378 | case SyncEventState::SetRace: { |
| 6379 | // Issue error message that Wait is waiting on an signal subject to race condition, and is thus ignored for |
| 6380 | // this event |
| 6381 | const char *const vuid = "SYNC-vkCmdWaitEvents-unsynchronized-setops"; |
| 6382 | const char *const message = |
| 6383 | "%s: %s Unsychronized %s calls result in race conditions w.r.t. event signalling, %s %s"; |
| 6384 | const char *const reason = "First synchronization scope is undefined."; |
| 6385 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6386 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6387 | CommandTypeString(sync_event->last_command), reason, kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6388 | break; |
| 6389 | } |
| 6390 | case SyncEventState::MissingStageBits: { |
| 6391 | const auto missing_bits = sync_event->scope.mask_param & ~src_exec_scope.mask_param; |
| 6392 | // Issue error message that event waited for is not in wait events scope |
| 6393 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 6394 | const char *const message = "%s: %s stageMask %" PRIx64 " includes bits not present in srcStageMask 0x%" PRIx64 |
| 6395 | ". Bits missing from srcStageMask %s. %s"; |
| 6396 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 6397 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 6398 | sync_event->scope.mask_param, src_exec_scope.mask_param, |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6399 | sync_utils::StringPipelineStageFlags(missing_bits).c_str(), kIgnored); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6400 | break; |
| 6401 | } |
| 6402 | case SyncEventState::SetVsWait2: { |
Tony-LunarG | 279601c | 2021-11-16 10:50:51 -0700 | [diff] [blame] | 6403 | skip |= sync_state.LogError(event_handle, "VUID-vkCmdWaitEvents2-pEvents-03837", |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6404 | "%s: Follows set of %s by %s. Disallowed.", CmdName(), |
| 6405 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 6406 | CommandTypeString(sync_event->last_command)); |
| 6407 | break; |
| 6408 | } |
| 6409 | default: |
| 6410 | assert(ignore_reason == SyncEventState::NotIgnored); |
| 6411 | } |
| 6412 | } else if (barrier_set.image_memory_barriers.size()) { |
| 6413 | const auto &image_memory_barriers = barrier_set.image_memory_barriers; |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6414 | const auto *context = exec_context.GetCurrentAccessContext(); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6415 | assert(context); |
| 6416 | for (const auto &image_memory_barrier : image_memory_barriers) { |
| 6417 | if (image_memory_barrier.old_layout == image_memory_barrier.new_layout) continue; |
| 6418 | const auto *image_state = image_memory_barrier.image.get(); |
| 6419 | if (!image_state) continue; |
| 6420 | const auto &subresource_range = image_memory_barrier.range; |
| 6421 | const auto &src_access_scope = image_memory_barrier.barrier.src_access_scope; |
| 6422 | const auto hazard = |
| 6423 | context->DetectImageBarrierHazard(*image_state, sync_event->scope.exec_scope, src_access_scope, |
| 6424 | subresource_range, *sync_event, AccessContext::DetectOptions::kDetectAll); |
| 6425 | if (hazard.hazard) { |
| 6426 | skip |= sync_state.LogError(image_state->image(), string_SyncHazardVUID(hazard.hazard), |
| 6427 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 6428 | string_SyncHazard(hazard.hazard), image_memory_barrier.index, |
| 6429 | sync_state.report_data->FormatHandle(image_state->image()).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6430 | exec_context.FormatHazard(hazard).c_str()); |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame] | 6431 | break; |
| 6432 | } |
| 6433 | } |
| 6434 | } |
| 6435 | // TODO: Add infrastructure for checking pDependencyInfo's vs. CmdSetEvent2 VUID - vkCmdWaitEvents2KHR - pEvents - |
| 6436 | // 03839 |
| 6437 | barrier_set_index += barrier_set_incr; |
| 6438 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6439 | |
| 6440 | // 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] | 6441 | 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] | 6442 | if (extra_stage_bits) { |
| 6443 | // 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] | 6444 | // NOTE: This isn't exactly the right VUID for WaitEvents2, but it's as close as we currently have support for |
| 6445 | const char *const vuid = |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6446 | (CMD_WAITEVENTS == cmd_type_) ? "VUID-vkCmdWaitEvents-srcStageMask-01158" : "VUID-vkCmdWaitEvents2-pEvents-03838"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6447 | const char *const message = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6448 | "%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] | 6449 | const auto handle = exec_context.Handle(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6450 | if (events_not_found) { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6451 | skip |= sync_state.LogInfo(handle, vuid, message, CmdName(), barrier_mask_params, |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6452 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6453 | " vkCmdSetEvent may be in previously submitted command buffer."); |
| 6454 | } else { |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6455 | skip |= sync_state.LogError(handle, vuid, message, CmdName(), barrier_mask_params, |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 6456 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), ""); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6457 | } |
| 6458 | } |
| 6459 | return skip; |
| 6460 | } |
| 6461 | |
| 6462 | struct SyncOpWaitEventsFunctorFactory { |
| 6463 | using BarrierOpFunctor = WaitEventBarrierOp; |
| 6464 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 6465 | using GlobalBarrierOpFunctor = WaitEventBarrierOp; |
| 6466 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 6467 | using BufferRange = EventSimpleRangeGenerator; |
| 6468 | using ImageRange = EventImageRangeGenerator; |
| 6469 | using GlobalRange = EventSimpleRangeGenerator; |
| 6470 | |
| 6471 | // Need to restrict to only valid exec and access scope for this event |
| 6472 | // Pass by value is intentional to get a copy we can change without modifying the passed barrier |
| 6473 | SyncBarrier RestrictToEvent(SyncBarrier barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 6474 | 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] | 6475 | barrier.src_access_scope = sync_event->scope.valid_accesses & barrier.src_access_scope; |
| 6476 | return barrier; |
| 6477 | } |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6478 | 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] | 6479 | auto barrier = RestrictToEvent(barrier_arg); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6480 | 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] | 6481 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 6482 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6483 | return GlobalApplyFunctor(false /* don't resolve */, size_hint, tag); |
| 6484 | } |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6485 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const QueueId queue_id, const SyncBarrier &barrier_arg) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6486 | auto barrier = RestrictToEvent(barrier_arg); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6487 | return GlobalBarrierOpFunctor(queue_id, sync_event->first_scope_tag, barrier, false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6488 | } |
| 6489 | |
| 6490 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range_arg) const { |
| 6491 | const AccessAddressType address_type = GetAccessAddressType(buffer); |
| 6492 | const auto base_address = ResourceBaseAddress(buffer); |
| 6493 | ResourceAccessRange range = SimpleBinding(buffer) ? (range_arg + base_address) : ResourceAccessRange(); |
| 6494 | EventSimpleRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), range); |
| 6495 | return filtered_range_gen; |
| 6496 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 6497 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6498 | if (!SimpleBinding(image)) return ImageRange(); |
| 6499 | const auto address_type = GetAccessAddressType(image); |
| 6500 | const auto base_address = ResourceBaseAddress(image); |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 6501 | subresource_adapter::ImageRangeGenerator image_range_gen(*image.fragment_encoder.get(), subresource_range, base_address, |
| 6502 | false); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6503 | EventImageRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), image_range_gen); |
| 6504 | |
| 6505 | return filtered_range_gen; |
| 6506 | } |
| 6507 | GlobalRange MakeGlobalRangeGen(AccessAddressType address_type) const { |
| 6508 | return EventSimpleRangeGenerator(sync_event->FirstScope(address_type), kFullRange); |
| 6509 | } |
| 6510 | SyncOpWaitEventsFunctorFactory(SyncEventState *sync_event_) : sync_event(sync_event_) { assert(sync_event); } |
| 6511 | SyncEventState *sync_event; |
| 6512 | }; |
| 6513 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6514 | ResourceUsageTag SyncOpWaitEvents::Record(CommandBufferAccessContext *cb_context) const { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6515 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6516 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6517 | const QueueId queue_id = cb_context->GetQueueId(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6518 | assert(access_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6519 | if (!access_context) return tag; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6520 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 6521 | assert(events_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6522 | if (!events_context) return tag; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6523 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6524 | ReplayRecord(queue_id, tag, access_context, events_context); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6525 | return tag; |
| 6526 | } |
| 6527 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6528 | void SyncOpWaitEvents::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
| 6529 | SyncEventsContext *events_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6530 | // Unlike PipelineBarrier, WaitEvent is *not* limited to accesses within the current subpass (if any) and thus needs to import |
| 6531 | // all accesses. Can instead import for all first_scopes, or a union of them, if this becomes a performance/memory issue, |
| 6532 | // but with no idea of the performance of the union, nor of whether it even matters... take the simplest approach here, |
| 6533 | access_context->ResolvePreviousAccesses(); |
| 6534 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6535 | size_t barrier_set_index = 0; |
| 6536 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 6537 | assert(barriers_.size() == 1 || (barriers_.size() == events_.size())); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6538 | for (auto &event_shared : events_) { |
| 6539 | if (!event_shared.get()) continue; |
| 6540 | auto *sync_event = events_context->GetFromShared(event_shared); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6541 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6542 | sync_event->last_command = cmd_type_; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6543 | sync_event->last_command_tag = tag; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6544 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6545 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 6546 | const auto &dst = barrier_set.dst_exec_scope; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6547 | 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] | 6548 | // These apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 6549 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 6550 | // of the barriers is maintained. |
| 6551 | SyncOpWaitEventsFunctorFactory factory(sync_event); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6552 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, queue_id, tag, access_context); |
| 6553 | ApplyBarriers(barrier_set.image_memory_barriers, factory, queue_id, tag, access_context); |
| 6554 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, queue_id, tag, access_context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6555 | |
| 6556 | // Apply the global barrier to the event itself (for race condition tracking) |
| 6557 | // Events don't happen at a stage, so we need to store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 6558 | sync_event->barriers = dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 6559 | sync_event->barriers |= dst.exec_scope; |
| 6560 | } else { |
| 6561 | // We ignored this wait, so we don't have any effective synchronization barriers for it. |
| 6562 | sync_event->barriers = 0U; |
| 6563 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6564 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | // Apply the pending barriers |
| 6568 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
| 6569 | access_context->ApplyToContext(apply_pending_action); |
| 6570 | } |
| 6571 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6572 | bool SyncOpWaitEvents::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6573 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
| 6574 | return DoValidate(*exec_context, base_tag); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6575 | } |
| 6576 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6577 | bool SyncValidator::PreCallValidateCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 6578 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 6579 | bool skip = false; |
| 6580 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 6581 | assert(cb_access_context); |
| 6582 | if (!cb_access_context) return skip; |
| 6583 | |
| 6584 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 6585 | assert(context); |
| 6586 | if (!context) return skip; |
| 6587 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6588 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6589 | |
| 6590 | if (dst_buffer) { |
| 6591 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 6592 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
| 6593 | if (hazard.hazard) { |
| 6594 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 6595 | "vkCmdWriteBufferMarkerAMD2: Hazard %s for dstBuffer %s. Access info %s.", |
| 6596 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), |
John Zulauf | 397e68b | 2022-04-19 11:44:07 -0600 | [diff] [blame] | 6597 | cb_access_context->FormatHazard(hazard).c_str()); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6598 | } |
| 6599 | } |
| 6600 | return skip; |
| 6601 | } |
| 6602 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 6603 | 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] | 6604 | events_.reserve(event_count); |
| 6605 | for (uint32_t event_index = 0; event_index < event_count; event_index++) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6606 | events_.emplace_back(sync_state.Get<EVENT_STATE>(events[event_index])); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 6607 | } |
| 6608 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6609 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6610 | 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] | 6611 | VkPipelineStageFlags2KHR stageMask) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6612 | : SyncOpBase(cmd_type), |
| 6613 | event_(sync_state.Get<EVENT_STATE>(event)), |
| 6614 | exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6615 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6616 | bool SyncOpResetEvent::Validate(const CommandBufferAccessContext& cb_context) const { |
| 6617 | return DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6618 | } |
| 6619 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6620 | bool SyncOpResetEvent::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
| 6621 | auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6622 | assert(events_context); |
| 6623 | bool skip = false; |
| 6624 | if (!events_context) return skip; |
| 6625 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6626 | const auto &sync_state = exec_context.GetSyncState(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6627 | const auto *sync_event = events_context->Get(event_); |
| 6628 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 6629 | |
John Zulauf | 1bf3052 | 2021-09-03 15:39:06 -0600 | [diff] [blame] | 6630 | if (sync_event->last_command_tag > base_tag) return skip; // if we validated this in recording of the secondary, don't repeat |
| 6631 | |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6632 | const char *const set_wait = |
| 6633 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 6634 | "hazards."; |
| 6635 | const char *message = set_wait; // Only one message this call. |
| 6636 | if (!sync_event->HasBarrier(exec_scope_.mask_param, exec_scope_.exec_scope)) { |
| 6637 | const char *vuid = nullptr; |
| 6638 | switch (sync_event->last_command) { |
| 6639 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6640 | case CMD_SETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6641 | case CMD_SETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6642 | // Needs a barrier between set and reset |
| 6643 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-set"; |
| 6644 | break; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6645 | case CMD_WAITEVENTS: |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 6646 | case CMD_WAITEVENTS2: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6647 | case CMD_WAITEVENTS2KHR: { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6648 | // Needs to be in the barriers chain (either because of a barrier, or because of dstStageMask |
| 6649 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-wait"; |
| 6650 | break; |
| 6651 | } |
| 6652 | default: |
| 6653 | // The only other valid last command that wasn't one. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6654 | assert((sync_event->last_command == CMD_NONE) || (sync_event->last_command == CMD_RESETEVENT) || |
| 6655 | (sync_event->last_command == CMD_RESETEVENT2KHR)); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6656 | break; |
| 6657 | } |
| 6658 | if (vuid) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6659 | skip |= sync_state.LogError(event_->event(), vuid, message, CmdName(), |
| 6660 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6661 | CommandTypeString(sync_event->last_command)); |
| 6662 | } |
| 6663 | } |
| 6664 | return skip; |
| 6665 | } |
| 6666 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6667 | ResourceUsageTag SyncOpResetEvent::Record(CommandBufferAccessContext *cb_context) const { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6668 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6669 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 6670 | assert(events_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6671 | if (!events_context) return tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6672 | |
| 6673 | auto *sync_event = events_context->GetFromShared(event_); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6674 | if (!sync_event) return tag; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6675 | |
| 6676 | // Update the event state |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6677 | sync_event->last_command = cmd_type_; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6678 | sync_event->last_command_tag = tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6679 | sync_event->unsynchronized_set = CMD_NONE; |
| 6680 | sync_event->ResetFirstScope(); |
| 6681 | sync_event->barriers = 0U; |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6682 | |
| 6683 | return tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6684 | } |
| 6685 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6686 | bool SyncOpResetEvent::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6687 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
| 6688 | return DoValidate(*exec_context, base_tag); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6689 | } |
| 6690 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6691 | void SyncOpResetEvent::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
| 6692 | SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6693 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6694 | SyncOpSetEvent::SyncOpSetEvent(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] | 6695 | VkPipelineStageFlags2KHR stageMask) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6696 | : SyncOpBase(cmd_type), |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6697 | event_(sync_state.Get<EVENT_STATE>(event)), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6698 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)), |
| 6699 | dep_info_() {} |
| 6700 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6701 | SyncOpSetEvent::SyncOpSetEvent(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] | 6702 | const VkDependencyInfoKHR &dep_info) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6703 | : SyncOpBase(cmd_type), |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6704 | event_(sync_state.Get<EVENT_STATE>(event)), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6705 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, sync_utils::GetGlobalStageMasks(dep_info).src)), |
Tony-LunarG | 273f32f | 2021-09-28 08:56:30 -0600 | [diff] [blame] | 6706 | dep_info_(new safe_VkDependencyInfo(&dep_info)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6707 | |
| 6708 | bool SyncOpSetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6709 | return DoValidate(cb_context, ResourceUsageRecord::kMaxIndex); |
| 6710 | } |
| 6711 | bool SyncOpSetEvent::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6712 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
| 6713 | assert(exec_context); |
| 6714 | return DoValidate(*exec_context, base_tag); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6715 | } |
| 6716 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6717 | bool SyncOpSetEvent::DoValidate(const CommandExecutionContext &exec_context, const ResourceUsageTag base_tag) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6718 | bool skip = false; |
| 6719 | |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6720 | const auto &sync_state = exec_context.GetSyncState(); |
| 6721 | auto *events_context = exec_context.GetCurrentEventsContext(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6722 | assert(events_context); |
| 6723 | if (!events_context) return skip; |
| 6724 | |
| 6725 | const auto *sync_event = events_context->Get(event_); |
| 6726 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 6727 | |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6728 | if (sync_event->last_command_tag >= base_tag) return skip; // for replay we don't want to revalidate internal "last commmand" |
| 6729 | |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6730 | const char *const reset_set = |
| 6731 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 6732 | "hazards."; |
| 6733 | const char *const wait = |
| 6734 | "%s: %s %s operation following %s without intervening vkCmdResetEvent, may result in data hazard and is ignored."; |
| 6735 | |
| 6736 | 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] | 6737 | const char *vuid_stem = nullptr; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6738 | const char *message = nullptr; |
| 6739 | switch (sync_event->last_command) { |
| 6740 | case CMD_RESETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6741 | case CMD_RESETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6742 | case CMD_RESETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6743 | // Needs a barrier between reset and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6744 | vuid_stem = "-missingbarrier-reset"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6745 | message = reset_set; |
| 6746 | break; |
| 6747 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6748 | case CMD_SETEVENT2KHR: |
Tony-LunarG | 8d71c4f | 2022-01-27 15:25:53 -0700 | [diff] [blame] | 6749 | case CMD_SETEVENT2: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6750 | // Needs a barrier between set and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6751 | vuid_stem = "-missingbarrier-set"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6752 | message = reset_set; |
| 6753 | break; |
| 6754 | case CMD_WAITEVENTS: |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 6755 | case CMD_WAITEVENTS2: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6756 | case CMD_WAITEVENTS2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6757 | // Needs a barrier or is in second execution scope |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6758 | vuid_stem = "-missingbarrier-wait"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6759 | message = wait; |
| 6760 | break; |
| 6761 | default: |
| 6762 | // The only other valid last command that wasn't one. |
| 6763 | assert(sync_event->last_command == CMD_NONE); |
| 6764 | break; |
| 6765 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6766 | if (vuid_stem) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6767 | assert(nullptr != message); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6768 | std::string vuid("SYNC-"); |
| 6769 | vuid.append(CmdName()).append(vuid_stem); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6770 | skip |= sync_state.LogError(event_->event(), vuid.c_str(), message, CmdName(), |
| 6771 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6772 | CommandTypeString(sync_event->last_command)); |
| 6773 | } |
| 6774 | } |
| 6775 | |
| 6776 | return skip; |
| 6777 | } |
| 6778 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6779 | ResourceUsageTag SyncOpSetEvent::Record(CommandBufferAccessContext *cb_context) const { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6780 | const auto tag = cb_context->NextCommandTag(cmd_type_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6781 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 6782 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6783 | const QueueId queue_id = cb_context->GetQueueId(); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6784 | assert(events_context); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6785 | if (access_context && events_context) { |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6786 | ReplayRecord(queue_id, tag, access_context, events_context); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6787 | } |
| 6788 | return tag; |
| 6789 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6790 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6791 | void SyncOpSetEvent::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
| 6792 | SyncEventsContext *events_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6793 | auto *sync_event = events_context->GetFromShared(event_); |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6794 | 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] | 6795 | |
| 6796 | // NOTE: We're going to simply record the sync scope here, as anything else would be implementation defined/undefined |
| 6797 | // and we're issuing errors re: missing barriers between event commands, which if the user fixes would fix |
| 6798 | // any issues caused by naive scope setting here. |
| 6799 | |
| 6800 | // What happens with two SetEvent is that one cannot know what group of operations will be waited for. |
| 6801 | // Given: |
| 6802 | // Stuff1; SetEvent; Stuff2; SetEvent; WaitEvents; |
| 6803 | // WaitEvents cannot know which of Stuff1, Stuff2, or both has completed execution. |
| 6804 | |
| 6805 | if (!sync_event->HasBarrier(src_exec_scope_.mask_param, src_exec_scope_.exec_scope)) { |
| 6806 | sync_event->unsynchronized_set = sync_event->last_command; |
| 6807 | sync_event->ResetFirstScope(); |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6808 | } else if (!sync_event->first_scope_set) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6809 | // We only set the scope if there isn't one |
| 6810 | sync_event->scope = src_exec_scope_; |
| 6811 | |
| 6812 | auto set_scope = [&sync_event](AccessAddressType address_type, const ResourceAccessRangeMap::value_type &access) { |
| 6813 | auto &scope_map = sync_event->first_scope[static_cast<size_t>(address_type)]; |
| 6814 | if (access.second.InSourceScopeOrChain(sync_event->scope.exec_scope, sync_event->scope.valid_accesses)) { |
| 6815 | scope_map.insert(scope_map.end(), std::make_pair(access.first, true)); |
| 6816 | } |
| 6817 | }; |
| 6818 | access_context->ForAll(set_scope); |
| 6819 | sync_event->unsynchronized_set = CMD_NONE; |
John Zulauf | 78b1f89 | 2021-09-20 15:02:09 -0600 | [diff] [blame] | 6820 | sync_event->first_scope_set = true; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6821 | sync_event->first_scope_tag = tag; |
| 6822 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6823 | // TODO: Store dep_info_ shared ptr in sync_state for WaitEvents2 validation |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6824 | sync_event->last_command = cmd_type_; |
John Zulauf | 610e28c | 2021-08-03 17:46:23 -0600 | [diff] [blame] | 6825 | sync_event->last_command_tag = tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6826 | sync_event->barriers = 0U; |
| 6827 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6828 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6829 | SyncOpBeginRenderPass::SyncOpBeginRenderPass(CMD_TYPE cmd_type, const SyncValidator &sync_state, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6830 | const VkRenderPassBeginInfo *pRenderPassBegin, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 6831 | const VkSubpassBeginInfo *pSubpassBeginInfo) |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6832 | : SyncOpBase(cmd_type) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6833 | if (pRenderPassBegin) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6834 | rp_state_ = sync_state.Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6835 | renderpass_begin_info_ = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6836 | auto fb_state = sync_state.Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6837 | if (fb_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 6838 | shared_attachments_ = sync_state.GetAttachmentViews(*renderpass_begin_info_.ptr(), *fb_state); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6839 | // TODO: Revisit this when all attachment validation is through SyncOps to see if we can discard the plain pointer copy |
| 6840 | // Note that this a safe to presist as long as shared_attachments is not cleared |
| 6841 | attachments_.reserve(shared_attachments_.size()); |
sfricke-samsung | 01c9ae9 | 2021-02-09 22:30:52 -0800 | [diff] [blame] | 6842 | for (const auto &attachment : shared_attachments_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6843 | attachments_.emplace_back(attachment.get()); |
| 6844 | } |
| 6845 | } |
| 6846 | if (pSubpassBeginInfo) { |
| 6847 | subpass_begin_info_ = safe_VkSubpassBeginInfo(pSubpassBeginInfo); |
| 6848 | } |
| 6849 | } |
| 6850 | } |
| 6851 | |
| 6852 | bool SyncOpBeginRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6853 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 6854 | bool skip = false; |
| 6855 | |
| 6856 | assert(rp_state_.get()); |
| 6857 | if (nullptr == rp_state_.get()) return skip; |
| 6858 | auto &rp_state = *rp_state_.get(); |
| 6859 | |
| 6860 | const uint32_t subpass = 0; |
| 6861 | |
| 6862 | // Construct the state we can use to validate against... (since validation is const and RecordCmdBeginRenderPass |
| 6863 | // hasn't happened yet) |
| 6864 | const std::vector<AccessContext> empty_context_vector; |
| 6865 | AccessContext temp_context(subpass, cb_context.GetQueueFlags(), rp_state.subpass_dependencies, empty_context_vector, |
| 6866 | cb_context.GetCurrentAccessContext()); |
| 6867 | |
| 6868 | // Validate attachment operations |
| 6869 | if (attachments_.size() == 0) return skip; |
| 6870 | const auto &render_area = renderpass_begin_info_.renderArea; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 6871 | |
| 6872 | // Since the isn't a valid RenderPassAccessContext until Record, needs to create the view/generator list... we could limit this |
| 6873 | // by predicating on whether subpass 0 uses the attachment if it is too expensive to create the full list redundantly here. |
| 6874 | // More broadly we could look at thread specific state shared between Validate and Record as is done for other heavyweight |
| 6875 | // operations (though it's currently a messy approach) |
| 6876 | AttachmentViewGenVector view_gens = RenderPassAccessContext::CreateAttachmentViewGen(render_area, attachments_); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6877 | 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] | 6878 | |
| 6879 | // Validate load operations if there were no layout transition hazards |
| 6880 | if (!skip) { |
John Zulauf | ee98402 | 2022-04-13 16:39:50 -0600 | [diff] [blame] | 6881 | temp_context.RecordLayoutTransitions(rp_state, subpass, view_gens, kInvalidTag); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6882 | 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] | 6883 | } |
| 6884 | |
| 6885 | return skip; |
| 6886 | } |
| 6887 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6888 | ResourceUsageTag SyncOpBeginRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6889 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 6890 | assert(rp_state_.get()); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6891 | if (nullptr == rp_state_.get()) return cb_context->NextCommandTag(cmd_type_); |
| 6892 | 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] | 6893 | } |
| 6894 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6895 | bool SyncOpBeginRenderPass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6896 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6897 | return false; |
| 6898 | } |
| 6899 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6900 | void SyncOpBeginRenderPass::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6901 | SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6902 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6903 | SyncOpNextSubpass::SyncOpNextSubpass(CMD_TYPE cmd_type, const SyncValidator &sync_state, |
| 6904 | const VkSubpassBeginInfo *pSubpassBeginInfo, const VkSubpassEndInfo *pSubpassEndInfo) |
| 6905 | : SyncOpBase(cmd_type) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6906 | if (pSubpassBeginInfo) { |
| 6907 | subpass_begin_info_.initialize(pSubpassBeginInfo); |
| 6908 | } |
| 6909 | if (pSubpassEndInfo) { |
| 6910 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 6911 | } |
| 6912 | } |
| 6913 | |
| 6914 | bool SyncOpNextSubpass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6915 | bool skip = false; |
| 6916 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 6917 | if (!renderpass_context) return skip; |
| 6918 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6919 | skip |= renderpass_context->ValidateNextSubpass(cb_context.GetExecutionContext(), cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6920 | return skip; |
| 6921 | } |
| 6922 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6923 | ResourceUsageTag SyncOpNextSubpass::Record(CommandBufferAccessContext *cb_context) const { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6924 | return cb_context->RecordNextSubpass(cmd_type_); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6925 | } |
| 6926 | |
| 6927 | bool SyncOpNextSubpass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6928 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6929 | return false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6930 | } |
| 6931 | |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6932 | SyncOpEndRenderPass::SyncOpEndRenderPass(CMD_TYPE cmd_type, const SyncValidator &sync_state, |
| 6933 | const VkSubpassEndInfo *pSubpassEndInfo) |
| 6934 | : SyncOpBase(cmd_type) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6935 | if (pSubpassEndInfo) { |
| 6936 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 6937 | } |
| 6938 | } |
| 6939 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6940 | void SyncOpNextSubpass::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
| 6941 | SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6942 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6943 | bool SyncOpEndRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6944 | bool skip = false; |
| 6945 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 6946 | |
| 6947 | if (!renderpass_context) return skip; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6948 | skip |= renderpass_context->ValidateEndRenderPass(cb_context.GetExecutionContext(), cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6949 | return skip; |
| 6950 | } |
| 6951 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6952 | ResourceUsageTag SyncOpEndRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6953 | return cb_context->RecordEndRenderPass(cmd_type_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6954 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6955 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6956 | bool SyncOpEndRenderPass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6957 | ResourceUsageTag base_tag, CommandExecutionContext *exec_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6958 | return false; |
| 6959 | } |
| 6960 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 6961 | void SyncOpEndRenderPass::ReplayRecord(QueueId queue_id, ResourceUsageTag tag, AccessContext *access_context, |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 6962 | SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6963 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6964 | void SyncValidator::PreCallRecordCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 6965 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
| 6966 | StateTracker::PreCallRecordCmdWriteBufferMarker2AMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
| 6967 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 6968 | assert(cb_access_context); |
| 6969 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 6970 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 6971 | assert(context); |
| 6972 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 6973 | auto dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6974 | |
| 6975 | if (dst_buffer) { |
| 6976 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 6977 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
| 6978 | } |
| 6979 | } |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 6980 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6981 | bool SyncValidator::PreCallValidateCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 6982 | const VkCommandBuffer *pCommandBuffers) const { |
| 6983 | bool skip = StateTracker::PreCallValidateCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6984 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 6985 | assert(cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6986 | |
| 6987 | // Heavyweight, but we need a proxy copy of the active command buffer access context |
| 6988 | CommandBufferAccessContext proxy_cb_context(*cb_context, CommandBufferAccessContext::AsProxyContext()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6989 | |
| 6990 | // Make working copies of the access and events contexts |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6991 | for (uint32_t cb_index = 0; cb_index < commandBufferCount; ++cb_index) { |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 6992 | proxy_cb_context.NextIndexedCommandTag(CMD_EXECUTECOMMANDS, cb_index); |
| 6993 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6994 | const auto *recorded_cb_context = GetAccessContext(pCommandBuffers[cb_index]); |
| 6995 | if (!recorded_cb_context) continue; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6996 | |
| 6997 | const auto *recorded_context = recorded_cb_context->GetCurrentAccessContext(); |
| 6998 | assert(recorded_context); |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 6999 | skip |= recorded_cb_context->ValidateFirstUse(&proxy_cb_context, "vkCmdExecuteCommands", cb_index); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7000 | |
| 7001 | // The barriers have already been applied in ValidatFirstUse |
| 7002 | ResourceUsageRange tag_range = proxy_cb_context.ImportRecordedAccessLog(*recorded_cb_context); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7003 | proxy_cb_context.ResolveExecutedCommandBuffer(*recorded_context, tag_range.begin); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7004 | } |
| 7005 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7006 | return skip; |
| 7007 | } |
| 7008 | |
| 7009 | void SyncValidator::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 7010 | const VkCommandBuffer *pCommandBuffers) { |
| 7011 | StateTracker::PreCallRecordCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7012 | auto *cb_context = GetAccessContext(commandBuffer); |
| 7013 | assert(cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7014 | for (uint32_t cb_index = 0; cb_index < commandBufferCount; ++cb_index) { |
John Zulauf | 41a9c7c | 2021-12-07 15:59:53 -0700 | [diff] [blame] | 7015 | cb_context->NextIndexedCommandTag(CMD_EXECUTECOMMANDS, cb_index); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7016 | const auto *recorded_cb_context = GetAccessContext(pCommandBuffers[cb_index]); |
| 7017 | if (!recorded_cb_context) continue; |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7018 | cb_context->RecordExecutedCommandBuffer(*recorded_cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 7019 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 7020 | } |
| 7021 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7022 | void SyncValidator::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) { |
| 7023 | StateTracker::PostCallRecordQueueWaitIdle(queue, result); |
| 7024 | if ((result != VK_SUCCESS) || (!enabled[sync_validation_queue_submit]) || (queue == VK_NULL_HANDLE)) return; |
| 7025 | |
| 7026 | const auto queue_state = GetQueueSyncStateShared(queue); |
| 7027 | if (!queue_state) return; // Invalid queue |
| 7028 | QueueId waited_queue = queue_state->GetQueueId(); |
| 7029 | |
| 7030 | // We need to go through every queue batch context and clear all accesses this wait synchronizes |
| 7031 | // As usual -- two groups, the "last batch" and the signaled semaphores |
| 7032 | // NOTE: Since ApplyTaggedWait crawls through every usage in every ResourceAccessState in the AccessContext of *every* |
| 7033 | // QueueBatchContext, track which we've done to avoid duplicate traversals |
| 7034 | QueueBatchContext::BatchSet waited; |
| 7035 | for (auto &queue : queue_sync_states_) { |
| 7036 | auto batch = queue.second->LastBatch(); |
| 7037 | if (batch) { |
| 7038 | batch->ApplyTaggedWait(waited_queue, ResourceUsageRecord::kMaxIndex); |
| 7039 | waited.emplace(batch); |
| 7040 | } |
| 7041 | } |
| 7042 | |
| 7043 | for (const auto &signaled : signaled_semaphores_) { |
| 7044 | auto &sem_sig = signaled.second; |
| 7045 | if (sem_sig && sem_sig->batch && (waited.find(sem_sig->batch) == waited.end())) { |
| 7046 | sem_sig->batch->ApplyTaggedWait(waited_queue, ResourceUsageRecord::kMaxIndex); |
| 7047 | waited.emplace(sem_sig->batch); |
| 7048 | } |
| 7049 | } |
| 7050 | // TODO: Update Events and Fences affected by Wait |
| 7051 | } |
| 7052 | |
| 7053 | void SyncValidator::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) { |
| 7054 | StateTracker::PostCallRecordDeviceWaitIdle(device, result); |
| 7055 | for (auto &queue : queue_sync_states_) { |
| 7056 | auto batch = queue.second->LastBatch(); |
| 7057 | if (batch) { |
| 7058 | batch->ApplyDeviceWait(); |
| 7059 | } |
| 7060 | } |
| 7061 | |
| 7062 | auto wait_no_list = [](std::shared_ptr<QueueBatchContext> &batch) { |
| 7063 | batch->ApplyDeviceWait(); |
| 7064 | return false; |
| 7065 | }; |
| 7066 | |
| 7067 | GetQueueLastBatchSnapshot(wait_no_list); |
| 7068 | |
| 7069 | // TODO: Update Events and Fences affected by Wait |
| 7070 | } |
| 7071 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7072 | struct QueueSubmitCmdState { |
| 7073 | std::shared_ptr<const QueueSyncState> queue; |
| 7074 | std::shared_ptr<QueueBatchContext> last_batch; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7075 | AccessLogger logger; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7076 | SignaledSemaphores signaled; |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7077 | QueueSubmitCmdState(const AccessLogger &parent_log, const SignaledSemaphores &parent_semaphores) |
| 7078 | : logger(&parent_log), signaled(parent_semaphores) {} |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7079 | }; |
| 7080 | |
| 7081 | template <> |
| 7082 | thread_local layer_data::optional<QueueSubmitCmdState> layer_data::TlsGuard<QueueSubmitCmdState>::payload_{}; |
| 7083 | |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7084 | bool SyncValidator::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, |
| 7085 | VkFence fence) const { |
| 7086 | bool skip = false; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7087 | |
| 7088 | // 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] | 7089 | if (!enabled[sync_validation_queue_submit]) return skip; |
| 7090 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7091 | layer_data::TlsGuard<QueueSubmitCmdState> cmd_state(&skip, global_access_log_, signaled_semaphores_); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7092 | const auto fence_state = Get<FENCE_STATE>(fence); |
| 7093 | cmd_state->queue = GetQueueSyncStateShared(queue); |
| 7094 | if (!cmd_state->queue) return skip; // Invalid Queue |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7095 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7096 | // The submit id is a mutable automic which is not recoverable on a skip == true condition |
| 7097 | uint64_t submit_id = cmd_state->queue->ReserveSubmitId(); |
| 7098 | |
| 7099 | // verify each submit batch |
| 7100 | // Since the last batch from the queue state is const, we need to track the last_batch separately from the |
| 7101 | // most recently created batch |
| 7102 | std::shared_ptr<const QueueBatchContext> last_batch = cmd_state->queue->LastBatch(); |
| 7103 | std::shared_ptr<QueueBatchContext> batch; |
| 7104 | for (uint32_t batch_idx = 0; batch_idx < submitCount; batch_idx++) { |
| 7105 | const VkSubmitInfo &submit = pSubmits[batch_idx]; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7106 | batch = std::make_shared<QueueBatchContext>(*this, *cmd_state->queue); |
| 7107 | batch->Setup(last_batch, submit, cmd_state->signaled); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7108 | batch->SetBatchLog(cmd_state->logger, submit_id, batch_idx); |
| 7109 | |
| 7110 | // For each submit in the batch... |
| 7111 | for (const auto &cb : *batch) { |
sjfricke | 0bea06e | 2022-06-05 09:22:26 +0900 | [diff] [blame] | 7112 | skip |= cb.cb->ValidateFirstUse(batch.get(), "vkQueueSubmit", cb.index); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7113 | |
| 7114 | // The barriers have already been applied in ValidatFirstUse |
| 7115 | ResourceUsageRange tag_range = batch->ImportRecordedAccessLog(*cb.cb); |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7116 | batch->ResolveSubmittedCommandBuffer(*cb.cb->GetCurrentAccessContext(), tag_range.begin); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7117 | } |
| 7118 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7119 | for (auto &sem : layer_data::make_span(submit.pSignalSemaphores, submit.signalSemaphoreCount)) { |
| 7120 | // Make a copy of the state, signal the copy and pend it... |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7121 | auto sem_state = Get<SEMAPHORE_STATE>(sem); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7122 | if (!sem_state) continue; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7123 | auto semaphore_info = lvl_init_struct<VkSemaphoreSubmitInfo>(); |
| 7124 | semaphore_info.stageMask = VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT; |
| 7125 | cmd_state->signaled.SignalSemaphore(sem_state, batch, semaphore_info); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7126 | } |
| 7127 | // Unless the previous batch was referenced by a signal, the QueueBatchContext will self destruct, but as |
| 7128 | // we ResolvePrevious as we can let any contexts we've fully referenced go. |
| 7129 | last_batch = batch; |
| 7130 | } |
| 7131 | // The most recently created batch will become the queue's "last batch" in the record phase |
| 7132 | if (batch) { |
| 7133 | cmd_state->last_batch = std::move(batch); |
| 7134 | } |
| 7135 | |
| 7136 | // 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] | 7137 | return skip; |
| 7138 | } |
| 7139 | |
| 7140 | void SyncValidator::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence, |
| 7141 | VkResult result) { |
| 7142 | StateTracker::PostCallRecordQueueSubmit(queue, submitCount, pSubmits, fence, result); |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7143 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7144 | // 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] | 7145 | if (!enabled[sync_validation_queue_submit]) return; // Queue submit validation must be affirmatively enabled |
| 7146 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7147 | // The earliest return (when enabled), must be *after* the TlsGuard, as it is the TlsGuard that cleans up the cmd_state |
| 7148 | // static payload |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7149 | layer_data::TlsGuard<QueueSubmitCmdState> cmd_state; |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7150 | |
| 7151 | if (VK_SUCCESS != result) return; // dispatched QueueSubmit failed |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7152 | if (!cmd_state->queue) return; // Validation couldn't find a valid queue object |
| 7153 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7154 | // Don't need to look up the queue state again, but we need a non-const version |
| 7155 | 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] | 7156 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7157 | // The global the semaphores we applied to the cmd_state QueueBatchContexts |
| 7158 | // NOTE: All conserved QueueBatchContext's need to have there access logs reset to use the global logger and the only conserved |
| 7159 | // QBC's are those referenced by unwaited signals and the last batch. |
| 7160 | for (auto &sig_sem : cmd_state->signaled) { |
| 7161 | if (sig_sem.second && sig_sem.second->batch) { |
| 7162 | sig_sem.second->batch->ResetAccessLog(); |
| 7163 | } |
| 7164 | signaled_semaphores_.Import(sig_sem.first, std::move(sig_sem.second)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7165 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7166 | cmd_state->signaled.Reset(); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7167 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7168 | // Update the queue to point to the last batch from the submit |
| 7169 | if (cmd_state->last_batch) { |
| 7170 | cmd_state->last_batch->ResetAccessLog(); |
| 7171 | queue_state->SetLastBatch(std::move(cmd_state->last_batch)); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7172 | } |
| 7173 | |
| 7174 | // Update the global access log from the one built during validation |
| 7175 | global_access_log_.MergeMove(std::move(cmd_state->logger)); |
| 7176 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7177 | |
| 7178 | // WIP: record information about fences |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7179 | } |
| 7180 | |
| 7181 | bool SyncValidator::PreCallValidateQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 7182 | VkFence fence) const { |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7183 | bool skip = false; |
| 7184 | if (!enabled[sync_validation_queue_submit]) return skip; |
| 7185 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7186 | // WIP: Add Submit2 support |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7187 | return skip; |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7188 | } |
| 7189 | |
| 7190 | void SyncValidator::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 7191 | VkFence fence, VkResult result) { |
| 7192 | StateTracker::PostCallRecordQueueSubmit2KHR(queue, submitCount, pSubmits, fence, result); |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7193 | if (VK_SUCCESS != result) return; // dispatched QueueSubmit2 failed |
| 7194 | |
| 7195 | if (!enabled[sync_validation_queue_submit]) return; |
| 7196 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7197 | // WIP: Add Submit2 support |
John Zulauf | bbda457 | 2022-04-19 16:20:45 -0600 | [diff] [blame] | 7198 | } |
| 7199 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7200 | AttachmentViewGen::AttachmentViewGen(const IMAGE_VIEW_STATE *view, const VkOffset3D &offset, const VkExtent3D &extent) |
| 7201 | : view_(view), view_mask_(), gen_store_() { |
| 7202 | if (!view_ || !view_->image_state || !SimpleBinding(*view_->image_state)) return; |
| 7203 | const IMAGE_STATE &image_state = *view_->image_state.get(); |
| 7204 | const auto base_address = ResourceBaseAddress(image_state); |
| 7205 | const auto *encoder = image_state.fragment_encoder.get(); |
| 7206 | if (!encoder) return; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 7207 | // Get offset and extent for the view, accounting for possible depth slicing |
| 7208 | const VkOffset3D zero_offset = view->GetOffset(); |
| 7209 | const VkExtent3D &image_extent = view->GetExtent(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7210 | // Intentional copy |
| 7211 | VkImageSubresourceRange subres_range = view_->normalized_subresource_range; |
| 7212 | view_mask_ = subres_range.aspectMask; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 7213 | gen_store_[Gen::kViewSubresource].emplace(*encoder, subres_range, zero_offset, image_extent, base_address, |
| 7214 | view->IsDepthSliced()); |
| 7215 | 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] | 7216 | |
| 7217 | const auto depth = view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT; |
| 7218 | if (depth && (depth != view_mask_)) { |
| 7219 | subres_range.aspectMask = depth; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 7220 | 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] | 7221 | } |
| 7222 | const auto stencil = view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT; |
| 7223 | if (stencil && (stencil != view_mask_)) { |
| 7224 | subres_range.aspectMask = stencil; |
Aitor Camacho | e67f2c7 | 2022-06-08 14:41:58 +0200 | [diff] [blame] | 7225 | gen_store_[Gen::kStencilOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address, |
| 7226 | view->IsDepthSliced()); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 7227 | } |
| 7228 | } |
| 7229 | |
| 7230 | const ImageRangeGen *AttachmentViewGen::GetRangeGen(AttachmentViewGen::Gen gen_type) const { |
| 7231 | const ImageRangeGen *got = nullptr; |
| 7232 | switch (gen_type) { |
| 7233 | case kViewSubresource: |
| 7234 | got = &gen_store_[kViewSubresource]; |
| 7235 | break; |
| 7236 | case kRenderArea: |
| 7237 | got = &gen_store_[kRenderArea]; |
| 7238 | break; |
| 7239 | case kDepthOnlyRenderArea: |
| 7240 | got = |
| 7241 | (view_mask_ == VK_IMAGE_ASPECT_DEPTH_BIT) ? &gen_store_[Gen::kRenderArea] : &gen_store_[Gen::kDepthOnlyRenderArea]; |
| 7242 | break; |
| 7243 | case kStencilOnlyRenderArea: |
| 7244 | got = (view_mask_ == VK_IMAGE_ASPECT_STENCIL_BIT) ? &gen_store_[Gen::kRenderArea] |
| 7245 | : &gen_store_[Gen::kStencilOnlyRenderArea]; |
| 7246 | break; |
| 7247 | default: |
| 7248 | assert(got); |
| 7249 | } |
| 7250 | return got; |
| 7251 | } |
| 7252 | |
| 7253 | AttachmentViewGen::Gen AttachmentViewGen::GetDepthStencilRenderAreaGenType(bool depth_op, bool stencil_op) const { |
| 7254 | assert(IsValid()); |
| 7255 | assert(view_mask_ & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); |
| 7256 | if (depth_op) { |
| 7257 | assert(view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 7258 | if (stencil_op) { |
| 7259 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 7260 | return kRenderArea; |
| 7261 | } |
| 7262 | return kDepthOnlyRenderArea; |
| 7263 | } |
| 7264 | if (stencil_op) { |
| 7265 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 7266 | return kStencilOnlyRenderArea; |
| 7267 | } |
| 7268 | |
| 7269 | assert(depth_op || stencil_op); |
| 7270 | return kRenderArea; |
| 7271 | } |
| 7272 | |
| 7273 | AccessAddressType AttachmentViewGen::GetAddressType() const { return AccessContext::ImageAddressType(*view_->image_state); } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 7274 | |
| 7275 | void SyncEventsContext::ApplyBarrier(const SyncExecScope &src, const SyncExecScope &dst) { |
| 7276 | const bool all_commands_bit = 0 != (src.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 7277 | for (auto &event_pair : map_) { |
| 7278 | assert(event_pair.second); // Shouldn't be storing empty |
| 7279 | auto &sync_event = *event_pair.second; |
| 7280 | // Events don't happen at a stage, so we need to check and store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 7281 | if ((sync_event.barriers & src.exec_scope) || all_commands_bit) { |
| 7282 | sync_event.barriers |= dst.exec_scope; |
| 7283 | sync_event.barriers |= dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 7284 | } |
| 7285 | } |
| 7286 | } |
John Zulauf | bb89045 | 2021-12-14 11:30:18 -0700 | [diff] [blame] | 7287 | |
| 7288 | ReplayTrackbackBarriersAction::ReplayTrackbackBarriersAction(VkQueueFlags queue_flags, |
| 7289 | const SubpassDependencyGraphNode &subpass_dep, |
| 7290 | const std::vector<ReplayTrackbackBarriersAction> &replay_contexts) { |
| 7291 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 7292 | trackback_barriers.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
| 7293 | for (const auto &prev_dep : subpass_dep.prev) { |
| 7294 | const auto prev_pass = prev_dep.first->pass; |
| 7295 | const auto &prev_barriers = prev_dep.second; |
| 7296 | trackback_barriers.emplace_back(&replay_contexts[prev_pass], queue_flags, prev_barriers); |
| 7297 | } |
| 7298 | if (has_barrier_from_external) { |
| 7299 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 7300 | trackback_barriers.emplace_back(nullptr, queue_flags, subpass_dep.barrier_from_external); |
| 7301 | } |
| 7302 | } |
| 7303 | |
| 7304 | void ReplayTrackbackBarriersAction::operator()(ResourceAccessState *access) const { |
| 7305 | if (trackback_barriers.size() == 1) { |
| 7306 | trackback_barriers[0](access); |
| 7307 | } else { |
| 7308 | ResourceAccessState resolved; |
| 7309 | for (const auto &trackback : trackback_barriers) { |
| 7310 | ResourceAccessState access_copy = *access; |
| 7311 | trackback(&access_copy); |
| 7312 | resolved.Resolve(access_copy); |
| 7313 | } |
| 7314 | *access = resolved; |
| 7315 | } |
| 7316 | } |
| 7317 | |
| 7318 | ReplayTrackbackBarriersAction::TrackbackBarriers::TrackbackBarriers( |
| 7319 | const ReplayTrackbackBarriersAction *source_subpass_, VkQueueFlags queue_flags_, |
| 7320 | const std::vector<const VkSubpassDependency2 *> &subpass_dependencies_) |
| 7321 | : Base(source_subpass_, queue_flags_, subpass_dependencies_) {} |
| 7322 | |
| 7323 | void ReplayTrackbackBarriersAction::TrackbackBarriers::operator()(ResourceAccessState *access) const { |
| 7324 | if (source_subpass) { |
| 7325 | (*source_subpass)(access); |
| 7326 | } |
| 7327 | access->ApplyBarriersImmediate(barriers); |
| 7328 | } |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7329 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7330 | QueueBatchContext::QueueBatchContext(const SyncValidator &sync_state, const QueueSyncState &queue_state) |
| 7331 | : CommandExecutionContext(&sync_state), queue_state_(&queue_state), tag_range_(0, 0), batch_log_(nullptr) {} |
| 7332 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7333 | template <typename BatchInfo> |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7334 | void QueueBatchContext::Setup(const std::shared_ptr<const QueueBatchContext> &prev_batch, const BatchInfo &batch_info, |
| 7335 | SignaledSemaphores &signaled) { |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7336 | SetupCommandBufferInfo(batch_info); |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7337 | SetupAccessContext(prev_batch, batch_info, signaled); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7338 | } |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7339 | void QueueBatchContext::ResolveSubmittedCommandBuffer(const AccessContext &recorded_context, ResourceUsageTag offset) { |
| 7340 | QueueId queue_id = queue_state_->GetQueueId(); |
| 7341 | auto tag_queue_op = [offset, queue_id](ResourceAccessState *access) { |
| 7342 | access->OffsetTag(offset); |
| 7343 | access->SetQueueId(queue_id); |
| 7344 | }; |
| 7345 | GetCurrentAccessContext()->ResolveFromContext(tag_queue_op, recorded_context); |
| 7346 | } |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7347 | |
| 7348 | VulkanTypedHandle QueueBatchContext::Handle() const { return queue_state_->Handle(); } |
| 7349 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7350 | void QueueBatchContext::ApplyTaggedWait(QueueId queue_id, ResourceUsageTag tag) { |
| 7351 | QueueWaitWorm wait_worm(queue_id); |
| 7352 | access_context_.ForAll(wait_worm); |
| 7353 | if (wait_worm.erase_all) { |
| 7354 | access_context_.Reset(); |
| 7355 | } else { |
| 7356 | // TODO: Profiling will tell us if we need a more efficient clean up. |
| 7357 | for (const auto &address : wait_worm.erase_list) { |
| 7358 | access_context_.DeleteAccess(address); |
| 7359 | } |
| 7360 | } |
| 7361 | } |
| 7362 | |
| 7363 | // Clear all accesses |
| 7364 | void QueueBatchContext::ApplyDeviceWait() { access_context_.Reset(); } |
| 7365 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7366 | class ApplySemaphoreBarrierAction { |
| 7367 | public: |
| 7368 | ApplySemaphoreBarrierAction(const SemaphoreScope &signal, const SemaphoreScope &wait) : signal_(signal), wait_(wait) {} |
| 7369 | void operator()(ResourceAccessState *access) const { access->ApplySemaphore(signal_, wait_); } |
| 7370 | |
| 7371 | private: |
| 7372 | const SemaphoreScope &signal_; |
| 7373 | const SemaphoreScope wait_; |
| 7374 | }; |
| 7375 | |
| 7376 | std::shared_ptr<QueueBatchContext> QueueBatchContext::ResolveOneWaitSemaphore(VkSemaphore sem, VkPipelineStageFlags2 wait_mask, |
| 7377 | SignaledSemaphores &signaled) { |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7378 | auto sem_state = sync_state_->Get<SEMAPHORE_STATE>(sem); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7379 | if (!sem_state) return nullptr; // Semaphore validity is handled by CoreChecks |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7380 | |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7381 | // When signal state goes out of scope, the signal information will be dropped, as Unsignal has released ownership. |
| 7382 | auto signal_state = signaled.Unsignal(sem); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7383 | if (!signal_state) return nullptr; // Invalid signal, skip it. |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7384 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7385 | assert(signal_state->batch); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7386 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7387 | const SemaphoreScope &signal_scope = signal_state->first_scope; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7388 | const auto queue_flags = queue_state_->GetQueueFlags(); |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7389 | SemaphoreScope wait_scope{GetQueueId(), SyncExecScope::MakeDst(queue_flags, wait_mask)}; |
| 7390 | if (signal_scope.queue == wait_scope.queue) { |
| 7391 | // If signal queue == wait queue, signal is treated as a memory barrier with an access scope equal to the |
| 7392 | // valid accesses for the sync scope. |
| 7393 | SyncBarrier sem_barrier(signal_scope, wait_scope, SyncBarrier::AllAccess()); |
| 7394 | const BatchBarrierOp sem_barrier_op(wait_scope.queue, sem_barrier); |
| 7395 | access_context_.ResolveFromContext(sem_barrier_op, signal_state->batch->access_context_); |
| 7396 | } else { |
| 7397 | ApplySemaphoreBarrierAction sem_op(signal_scope, wait_scope); |
| 7398 | access_context_.ResolveFromContext(sem_op, signal_state->batch->access_context_); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7399 | } |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7400 | // Cannot move from the signal state because it could be from the const global state, and C++ doesn't |
| 7401 | // enforce deep constness. |
| 7402 | return signal_state->batch; |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7403 | } |
| 7404 | |
| 7405 | // Accessor Traits to allow Submit and Submit2 constructors to call the same utilities |
| 7406 | template <> |
| 7407 | class QueueBatchContext::SubmitInfoAccessor<VkSubmitInfo> { |
| 7408 | public: |
| 7409 | SubmitInfoAccessor(const VkSubmitInfo &info) : info_(info) {} |
| 7410 | inline uint32_t WaitSemaphoreCount() const { return info_.waitSemaphoreCount; } |
| 7411 | inline VkSemaphore WaitSemaphore(uint32_t index) { return info_.pWaitSemaphores[index]; } |
| 7412 | inline VkPipelineStageFlags2 WaitDstMask(uint32_t index) { return info_.pWaitDstStageMask[index]; } |
| 7413 | inline uint32_t CommandBufferCount() const { return info_.commandBufferCount; } |
| 7414 | inline VkCommandBuffer CommandBuffer(uint32_t index) { return info_.pCommandBuffers[index]; } |
| 7415 | |
| 7416 | private: |
| 7417 | const VkSubmitInfo &info_; |
| 7418 | }; |
| 7419 | template <typename BatchInfo, typename Fn> |
| 7420 | void QueueBatchContext::ForEachWaitSemaphore(const BatchInfo &batch_info, Fn &&func) { |
| 7421 | using Accessor = QueueBatchContext::SubmitInfoAccessor<BatchInfo>; |
| 7422 | Accessor batch(batch_info); |
| 7423 | const uint32_t wait_count = batch.WaitSemaphoreCount(); |
| 7424 | for (uint32_t i = 0; i < wait_count; ++i) { |
| 7425 | func(batch.WaitSemaphore(i), batch.WaitDstMask(i)); |
| 7426 | } |
| 7427 | } |
| 7428 | |
| 7429 | template <typename BatchInfo> |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7430 | void QueueBatchContext::SetupAccessContext(const std::shared_ptr<const QueueBatchContext> &prev, const BatchInfo &batch_info, |
| 7431 | SignaledSemaphores &signaled) { |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7432 | // Import (resolve) the batches that are waited on, with the semaphore's effective barriers applied |
| 7433 | layer_data::unordered_set<std::shared_ptr<const QueueBatchContext>> batches_resolved; |
| 7434 | ForEachWaitSemaphore(batch_info, [this, &signaled, &batches_resolved](VkSemaphore sem, VkPipelineStageFlags2 wait_mask) { |
| 7435 | std::shared_ptr<QueueBatchContext> resolved = ResolveOneWaitSemaphore(sem, wait_mask, signaled); |
| 7436 | if (resolved) { |
| 7437 | batches_resolved.emplace(std::move(resolved)); |
| 7438 | } |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7439 | }); |
| 7440 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7441 | // If there are no semaphores to the previous batch, make sure a "submit order" non-barriered import is done |
| 7442 | if (prev && !layer_data::Contains(batches_resolved, prev)) { |
| 7443 | access_context_.ResolveFromContext(NoopBarrierAction(), prev->access_context_); |
John Zulauf | 78cb208 | 2022-04-20 16:37:48 -0600 | [diff] [blame] | 7444 | } |
| 7445 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7446 | // 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] | 7447 | async_batches_ = |
| 7448 | sync_state_->GetQueueLastBatchSnapshot([&batches_resolved, &prev](const std::shared_ptr<const QueueBatchContext> &batch) { |
| 7449 | return (batch != prev) && !layer_data::Contains(batches_resolved, batch); |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7450 | }); |
| 7451 | for (const auto &async_batch : async_batches_) { |
| 7452 | access_context_.AddAsyncContext(async_batch->GetCurrentAccessContext()); |
| 7453 | } |
| 7454 | } |
| 7455 | |
| 7456 | template <typename BatchInfo> |
| 7457 | void QueueBatchContext::SetupCommandBufferInfo(const BatchInfo &batch_info) { |
| 7458 | using Accessor = QueueBatchContext::SubmitInfoAccessor<BatchInfo>; |
| 7459 | Accessor batch(batch_info); |
| 7460 | |
| 7461 | // Create the list of command buffers to submit |
| 7462 | const uint32_t cb_count = batch.CommandBufferCount(); |
| 7463 | command_buffers_.reserve(cb_count); |
| 7464 | for (uint32_t index = 0; index < cb_count; ++index) { |
| 7465 | auto cb_context = sync_state_->GetAccessContextShared(batch.CommandBuffer(index)); |
| 7466 | if (cb_context) { |
| 7467 | tag_range_.end += cb_context->GetTagLimit(); |
| 7468 | command_buffers_.emplace_back(index, std::move(cb_context)); |
| 7469 | } |
| 7470 | } |
| 7471 | } |
| 7472 | |
| 7473 | // Look up the usage informaiton from the local or global logger |
| 7474 | std::string QueueBatchContext::FormatUsage(ResourceUsageTag tag) const { |
| 7475 | const AccessLogger &use_logger = (logger_) ? *logger_ : sync_state_->global_access_log_; |
| 7476 | std::stringstream out; |
| 7477 | AccessLogger::AccessRecord access = use_logger[tag]; |
| 7478 | if (access.IsValid()) { |
| 7479 | const AccessLogger::BatchRecord &batch = *access.batch; |
| 7480 | const ResourceUsageRecord &record = *access.record; |
| 7481 | // Queue and Batch information |
| 7482 | out << SyncNodeFormatter(*sync_state_, batch.queue->GetQueueState()); |
| 7483 | out << ", submit: " << batch.submit_index << ", batch: " << batch.batch_index; |
| 7484 | |
| 7485 | // Commandbuffer Usages Information |
| 7486 | out << record; |
| 7487 | out << SyncNodeFormatter(*sync_state_, record.cb_state); |
| 7488 | out << ", reset_no: " << std::to_string(record.reset_count); |
| 7489 | } |
| 7490 | return out.str(); |
| 7491 | } |
| 7492 | |
| 7493 | VkQueueFlags QueueBatchContext::GetQueueFlags() const { return queue_state_->GetQueueFlags(); } |
| 7494 | |
John Zulauf | 0011952 | 2022-05-23 19:07:42 -0600 | [diff] [blame] | 7495 | QueueId QueueBatchContext::GetQueueId() const { |
| 7496 | QueueId id = queue_state_ ? queue_state_->GetQueueId() : QueueSyncState::kQueueIdInvalid; |
| 7497 | return id; |
| 7498 | } |
| 7499 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7500 | void QueueBatchContext::SetBatchLog(AccessLogger &logger, uint64_t submit_id, uint32_t batch_id) { |
| 7501 | // Need new global tags for all accesses... the Reserve updates a mutable atomic |
| 7502 | ResourceUsageRange global_tags = sync_state_->ReserveGlobalTagRange(GetTagRange().size()); |
| 7503 | SetTagBias(global_tags.begin); |
| 7504 | // Add an access log for the batches range and point the batch at it. |
| 7505 | logger_ = &logger; |
| 7506 | batch_log_ = logger.AddBatch(queue_state_, submit_id, batch_id, global_tags); |
| 7507 | } |
| 7508 | |
| 7509 | void QueueBatchContext::InsertRecordedAccessLogEntries(const CommandBufferAccessContext &submitted_cb) { |
| 7510 | assert(batch_log_); // Don't import command buffer contexts until you've set up the log for the batch context |
| 7511 | batch_log_->Append(submitted_cb.GetAccessLog()); |
| 7512 | } |
| 7513 | |
| 7514 | void QueueBatchContext::SetTagBias(ResourceUsageTag bias) { |
| 7515 | const auto size = tag_range_.size(); |
| 7516 | tag_range_.begin = bias; |
| 7517 | tag_range_.end = bias + size; |
| 7518 | access_context_.SetStartTag(bias); |
| 7519 | } |
| 7520 | |
John Zulauf | 1d5f9c1 | 2022-05-13 14:51:08 -0600 | [diff] [blame] | 7521 | QueueBatchContext::QueueWaitWorm::QueueWaitWorm(QueueId queue, ResourceUsageTag tag) : predicate(queue) {} |
| 7522 | |
| 7523 | void QueueBatchContext::QueueWaitWorm::operator()(AccessAddressType address_type, ResourceAccessRangeMap::value_type &access) { |
| 7524 | bool erased = access.second.ApplyQueueTagWait(predicate); |
| 7525 | if (erased) { |
| 7526 | erase_list.emplace_back(address_type, access.first); |
| 7527 | } else { |
| 7528 | erase_all = false; |
| 7529 | } |
| 7530 | } |
| 7531 | |
John Zulauf | 697c0e1 | 2022-04-19 16:31:12 -0600 | [diff] [blame] | 7532 | AccessLogger::BatchLog *AccessLogger::AddBatch(const QueueSyncState *queue_state, uint64_t submit_id, uint32_t batch_id, |
| 7533 | const ResourceUsageRange &range) { |
| 7534 | const auto inserted = access_log_map_.insert(std::make_pair(range, BatchLog(BatchRecord(queue_state, submit_id, batch_id)))); |
| 7535 | assert(inserted.second); |
| 7536 | return &inserted.first->second; |
| 7537 | } |
| 7538 | |
| 7539 | void AccessLogger::MergeMove(AccessLogger &&child) { |
| 7540 | for (auto &range : child.access_log_map_) { |
| 7541 | BatchLog &child_batch = range.second; |
| 7542 | auto insert_pair = access_log_map_.insert(std::make_pair(range.first, BatchLog())); |
| 7543 | insert_pair.first->second = std::move(child_batch); |
| 7544 | assert(insert_pair.second); |
| 7545 | } |
| 7546 | child.Reset(); |
| 7547 | } |
| 7548 | |
| 7549 | void AccessLogger::Reset() { |
| 7550 | prev_ = nullptr; |
| 7551 | access_log_map_.clear(); |
| 7552 | } |
| 7553 | |
| 7554 | // Since we're updating the QueueSync state, this is Record phase and the access log needs to point to the global one |
| 7555 | // Batch Contexts saved during signalling have their AccessLog reset when the pending signals are signalled. |
| 7556 | // NOTE: By design, QueueBatchContexts that are neither last, nor referenced by a signal are abandoned as unowned, since |
| 7557 | // the contexts Resolve all history from previous all contexts when created |
| 7558 | void QueueSyncState::SetLastBatch(std::shared_ptr<QueueBatchContext> &&last) { |
| 7559 | last_batch_ = std::move(last); |
| 7560 | last_batch_->ResetAccessLog(); |
| 7561 | } |
| 7562 | |
| 7563 | // Note that function is const, but updates mutable submit_index to allow Validate to create correct tagging for command invocation |
| 7564 | // scope state. |
| 7565 | // Given that queue submits are supposed to be externally synchronized for the same queue, this should safe without being |
| 7566 | // atomic... but as the ops are per submit, the performance cost is negible for the peace of mind. |
| 7567 | uint64_t QueueSyncState::ReserveSubmitId() const { return submit_index_.fetch_add(1); } |
| 7568 | |
| 7569 | void AccessLogger::BatchLog::Append(const CommandExecutionContext::AccessLog &other) { |
| 7570 | log_.insert(log_.end(), other.cbegin(), other.cend()); |
| 7571 | for (const auto &record : other) { |
| 7572 | assert(record.cb_state); |
| 7573 | cbs_referenced_.insert(record.cb_state->shared_from_this()); |
| 7574 | } |
| 7575 | } |
| 7576 | |
| 7577 | AccessLogger::AccessRecord AccessLogger::BatchLog::operator[](size_t index) const { |
| 7578 | assert(index < log_.size()); |
| 7579 | return AccessRecord{&batch_, &log_[index]}; |
| 7580 | } |
| 7581 | |
| 7582 | AccessLogger::AccessRecord AccessLogger::operator[](ResourceUsageTag tag) const { |
| 7583 | AccessRecord access_record = {nullptr, nullptr}; |
| 7584 | |
| 7585 | auto found_range = access_log_map_.find(tag); |
| 7586 | if (found_range != access_log_map_.cend()) { |
| 7587 | const ResourceUsageTag bias = found_range->first.begin; |
| 7588 | assert(tag >= bias); |
| 7589 | access_record = found_range->second[tag - bias]; |
| 7590 | } else if (prev_) { |
| 7591 | access_record = (*prev_)[tag]; |
| 7592 | } |
| 7593 | |
| 7594 | return access_record; |
| 7595 | } |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7596 | |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7597 | // This is a const method, force the returned value to be const |
| 7598 | std::shared_ptr<const SignaledSemaphores::Signal> SignaledSemaphores::GetPrev(VkSemaphore sem) const { |
John Zulauf | cb7e167 | 2022-05-04 13:46:08 -0600 | [diff] [blame] | 7599 | std::shared_ptr<Signal> prev_state; |
| 7600 | if (prev_) { |
| 7601 | prev_state = GetMapped(prev_->signaled_, sem, [&prev_state]() { return prev_state; }); |
| 7602 | } |
| 7603 | return prev_state; |
| 7604 | } |
John Zulauf | ecf4ac5 | 2022-06-06 10:08:42 -0600 | [diff] [blame] | 7605 | |
| 7606 | SignaledSemaphores::Signal::Signal(const std::shared_ptr<const SEMAPHORE_STATE> &sem_state_, |
| 7607 | const std::shared_ptr<QueueBatchContext> &batch_, const SyncExecScope &exec_scope_) |
| 7608 | : sem_state(sem_state_), batch(batch_), first_scope({batch->GetQueueId(), exec_scope_}) { |
| 7609 | // Illegal to create a signal from no batch or an invalid semaphore... caller must assure validity |
| 7610 | assert(batch); |
| 7611 | assert(sem_state); |
| 7612 | } |