John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2019-2021 The Khronos Group Inc. |
| 2 | * Copyright (c) 2019-2021 Valve Corporation |
| 3 | * Copyright (c) 2019-2021 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 | |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 29 | static bool SimpleBinding(const BINDABLE &bindable) { return !bindable.sparse && bindable.Binding(); } |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 30 | |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 31 | static bool SimpleBinding(const IMAGE_STATE &image_state) { |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 32 | bool simple = |
Jeremy Gebben | 82e11d5 | 2021-07-26 09:19:37 -0600 | [diff] [blame] | 33 | 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] | 34 | |
| 35 | // If it's not simple we must have an encoder. |
| 36 | assert(!simple || image_state.fragment_encoder.get()); |
| 37 | return simple; |
| 38 | } |
| 39 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 40 | static const ResourceAccessRange kFullRange(std::numeric_limits<VkDeviceSize>::min(), std::numeric_limits<VkDeviceSize>::max()); |
| 41 | static const std::array<AccessAddressType, static_cast<size_t>(AccessAddressType::kTypeCount)> kAddressTypes = { |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 42 | AccessAddressType::kLinear, AccessAddressType::kIdealized}; |
| 43 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 44 | static constexpr AccessAddressType GetAccessAddressType(const BUFFER_STATE &) { return AccessAddressType::kLinear; }; |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 45 | static AccessAddressType GetAccessAddressType(const IMAGE_STATE &image) { |
| 46 | return SimpleBinding(image) ? AccessContext::ImageAddressType(image) : AccessAddressType::kIdealized; |
| 47 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 48 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 49 | static const char *string_SyncHazardVUID(SyncHazard hazard) { |
| 50 | switch (hazard) { |
| 51 | case SyncHazard::NONE: |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 52 | return "SYNC-HAZARD-NONE"; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 53 | break; |
| 54 | case SyncHazard::READ_AFTER_WRITE: |
| 55 | return "SYNC-HAZARD-READ_AFTER_WRITE"; |
| 56 | break; |
| 57 | case SyncHazard::WRITE_AFTER_READ: |
| 58 | return "SYNC-HAZARD-WRITE_AFTER_READ"; |
| 59 | break; |
| 60 | case SyncHazard::WRITE_AFTER_WRITE: |
| 61 | return "SYNC-HAZARD-WRITE_AFTER_WRITE"; |
| 62 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 63 | case SyncHazard::READ_RACING_WRITE: |
| 64 | return "SYNC-HAZARD-READ-RACING-WRITE"; |
| 65 | break; |
| 66 | case SyncHazard::WRITE_RACING_WRITE: |
| 67 | return "SYNC-HAZARD-WRITE-RACING-WRITE"; |
| 68 | break; |
| 69 | case SyncHazard::WRITE_RACING_READ: |
| 70 | return "SYNC-HAZARD-WRITE-RACING-READ"; |
| 71 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 72 | default: |
| 73 | assert(0); |
| 74 | } |
| 75 | return "SYNC-HAZARD-INVALID"; |
| 76 | } |
| 77 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 78 | static bool IsHazardVsRead(SyncHazard hazard) { |
| 79 | switch (hazard) { |
| 80 | case SyncHazard::NONE: |
| 81 | return false; |
| 82 | break; |
| 83 | case SyncHazard::READ_AFTER_WRITE: |
| 84 | return false; |
| 85 | break; |
| 86 | case SyncHazard::WRITE_AFTER_READ: |
| 87 | return true; |
| 88 | break; |
| 89 | case SyncHazard::WRITE_AFTER_WRITE: |
| 90 | return false; |
| 91 | break; |
| 92 | case SyncHazard::READ_RACING_WRITE: |
| 93 | return false; |
| 94 | break; |
| 95 | case SyncHazard::WRITE_RACING_WRITE: |
| 96 | return false; |
| 97 | break; |
| 98 | case SyncHazard::WRITE_RACING_READ: |
| 99 | return true; |
| 100 | break; |
| 101 | default: |
| 102 | assert(0); |
| 103 | } |
| 104 | return false; |
| 105 | } |
| 106 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 107 | static const char *string_SyncHazard(SyncHazard hazard) { |
| 108 | switch (hazard) { |
| 109 | case SyncHazard::NONE: |
| 110 | return "NONR"; |
| 111 | break; |
| 112 | case SyncHazard::READ_AFTER_WRITE: |
| 113 | return "READ_AFTER_WRITE"; |
| 114 | break; |
| 115 | case SyncHazard::WRITE_AFTER_READ: |
| 116 | return "WRITE_AFTER_READ"; |
| 117 | break; |
| 118 | case SyncHazard::WRITE_AFTER_WRITE: |
| 119 | return "WRITE_AFTER_WRITE"; |
| 120 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 121 | case SyncHazard::READ_RACING_WRITE: |
| 122 | return "READ_RACING_WRITE"; |
| 123 | break; |
| 124 | case SyncHazard::WRITE_RACING_WRITE: |
| 125 | return "WRITE_RACING_WRITE"; |
| 126 | break; |
| 127 | case SyncHazard::WRITE_RACING_READ: |
| 128 | return "WRITE_RACING_READ"; |
| 129 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 130 | default: |
| 131 | assert(0); |
| 132 | } |
| 133 | return "INVALID HAZARD"; |
| 134 | } |
| 135 | |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 136 | static const SyncStageAccessInfoType *SyncStageAccessInfoFromMask(SyncStageAccessFlags flags) { |
| 137 | // Return the info for the first bit found |
| 138 | const SyncStageAccessInfoType *info = nullptr; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 139 | for (size_t i = 0; i < flags.size(); i++) { |
| 140 | if (flags.test(i)) { |
| 141 | info = &syncStageAccessInfoByStageAccessIndex[i]; |
| 142 | break; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | return info; |
| 146 | } |
| 147 | |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 148 | static std::string string_SyncStageAccessFlags(const SyncStageAccessFlags &flags, const char *sep = "|") { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 149 | std::string out_str; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 150 | if (flags.none()) { |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 151 | out_str = "0"; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 152 | } else { |
| 153 | for (size_t i = 0; i < syncStageAccessInfoByStageAccessIndex.size(); i++) { |
| 154 | const auto &info = syncStageAccessInfoByStageAccessIndex[i]; |
| 155 | if ((flags & info.stage_access_bit).any()) { |
| 156 | if (!out_str.empty()) { |
| 157 | out_str.append(sep); |
| 158 | } |
| 159 | out_str.append(info.name); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 160 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 161 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 162 | if (out_str.length() == 0) { |
| 163 | out_str.append("Unhandled SyncStageAccess"); |
| 164 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 165 | } |
| 166 | return out_str; |
| 167 | } |
| 168 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 169 | static std::string string_UsageTag(const ResourceUsageRecord &tag) { |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 170 | std::stringstream out; |
| 171 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 172 | out << "command: " << CommandTypeString(tag.command); |
| 173 | out << ", seq_no: " << tag.seq_num; |
| 174 | if (tag.sub_command != 0) { |
| 175 | out << ", subcmd: " << tag.sub_command; |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 176 | } |
| 177 | return out.str(); |
| 178 | } |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 179 | static std::string string_UsageIndex(SyncStageAccessIndex usage_index) { |
| 180 | const char *stage_access_name = "INVALID_STAGE_ACCESS"; |
| 181 | if (usage_index < static_cast<SyncStageAccessIndex>(syncStageAccessInfoByStageAccessIndex.size())) { |
| 182 | stage_access_name = syncStageAccessInfoByStageAccessIndex[usage_index].name; |
| 183 | } |
| 184 | return std::string(stage_access_name); |
| 185 | } |
| 186 | |
| 187 | struct NoopBarrierAction { |
| 188 | explicit NoopBarrierAction() {} |
| 189 | void operator()(ResourceAccessState *access) const {} |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 190 | const bool layout_transition = false; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | // NOTE: Make sure the proxy doesn't outlive from, as the proxy is pointing directly to access contexts owned by from. |
| 194 | CommandBufferAccessContext::CommandBufferAccessContext(const CommandBufferAccessContext &from, AsProxyContext dummy) |
| 195 | : CommandBufferAccessContext(from.sync_state_) { |
| 196 | // Copy only the needed fields out of from for a temporary, proxy command buffer context |
| 197 | cb_state_ = from.cb_state_; |
| 198 | queue_flags_ = from.queue_flags_; |
| 199 | destroyed_ = from.destroyed_; |
| 200 | access_log_ = from.access_log_; // potentially large, but no choice given tagging lookup. |
| 201 | command_number_ = from.command_number_; |
| 202 | subcommand_number_ = from.subcommand_number_; |
| 203 | reset_count_ = from.reset_count_; |
| 204 | |
| 205 | const auto *from_context = from.GetCurrentAccessContext(); |
| 206 | assert(from_context); |
| 207 | |
| 208 | // Construct a fully resolved single access context out of from |
| 209 | const NoopBarrierAction noop_barrier; |
| 210 | for (AccessAddressType address_type : kAddressTypes) { |
| 211 | from_context->ResolveAccessRange(address_type, kFullRange, noop_barrier, |
| 212 | &cb_access_context_.GetAccessStateMap(address_type), nullptr); |
| 213 | } |
| 214 | // The proxy has flatten the current render pass context (if any), but the async contexts are needed for hazard detection |
| 215 | cb_access_context_.ImportAsyncContexts(*from_context); |
| 216 | |
| 217 | events_context_ = from.events_context_; |
| 218 | |
| 219 | // We don't want to copy the full render_pass_context_ history just for the proxy. |
| 220 | } |
| 221 | |
| 222 | std::string CommandBufferAccessContext::FormatUsage(const ResourceUsageTag tag) const { |
| 223 | std::stringstream out; |
| 224 | assert(tag < access_log_.size()); |
| 225 | const auto &record = access_log_[tag]; |
| 226 | out << string_UsageTag(record); |
| 227 | if (record.cb_state != cb_state_.get()) { |
| 228 | out << ", command_buffer: " << sync_state_->report_data->FormatHandle(record.cb_state->commandBuffer()).c_str(); |
| 229 | if (record.cb_state->Destroyed()) { |
| 230 | out << " (destroyed)"; |
| 231 | } |
| 232 | |
| 233 | const auto found_it = cb_execution_reference_.find(record.cb_state); |
| 234 | assert(found_it != cb_execution_reference_.end()); |
| 235 | if (found_it != cb_execution_reference_.end()) { |
| 236 | out << ", reset_no: " << std::to_string(found_it->second.reset_count); |
| 237 | } |
| 238 | } else { |
| 239 | out << ", reset_no: " << std::to_string(reset_count_); |
| 240 | } |
| 241 | return out.str(); |
| 242 | } |
| 243 | std::string CommandBufferAccessContext::FormatUsage(const ResourceFirstAccess &access) const { |
| 244 | std::stringstream out; |
| 245 | out << "(recorded_usage: " << string_UsageIndex(access.usage_index); |
| 246 | out << ", " << FormatUsage(access.tag) << ")"; |
| 247 | return out.str(); |
| 248 | } |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 249 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 250 | std::string CommandBufferAccessContext::FormatUsage(const HazardResult &hazard) const { |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 251 | const auto &tag = hazard.tag; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 252 | assert(hazard.usage_index < static_cast<SyncStageAccessIndex>(syncStageAccessInfoByStageAccessIndex.size())); |
| 253 | const auto &usage_info = syncStageAccessInfoByStageAccessIndex[hazard.usage_index]; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 254 | std::stringstream out; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 255 | const auto *info = SyncStageAccessInfoFromMask(hazard.prior_access); |
| 256 | const char *stage_access_name = info ? info->name : "INVALID_STAGE_ACCESS"; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 257 | out << "("; |
| 258 | if (!hazard.recorded_access.get()) { |
| 259 | // if we have a recorded usage the usage is reported from the recorded contexts point of view |
| 260 | out << "usage: " << usage_info.name << ", "; |
| 261 | } |
| 262 | out << "prior_usage: " << stage_access_name; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 263 | if (IsHazardVsRead(hazard.hazard)) { |
| 264 | const auto barriers = hazard.access_state->GetReadBarriers(hazard.prior_access); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 265 | out << ", read_barriers: " << string_VkPipelineStageFlags2KHR(barriers); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 266 | } else { |
| 267 | SyncStageAccessFlags write_barrier = hazard.access_state->GetWriteBarriers(); |
| 268 | out << ", write_barriers: " << string_SyncStageAccessFlags(write_barrier); |
| 269 | } |
| 270 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 271 | assert(tag < access_log_.size()); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 272 | out << ", " << FormatUsage(tag) << ")"; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 273 | return out.str(); |
| 274 | } |
| 275 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 276 | // NOTE: the attachement read flag is put *only* in the access scope and not in the exect scope, since the ordering |
| 277 | // rules apply only to this specific access for this stage, and not the stage as a whole. The ordering detection |
| 278 | // 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] | 279 | 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] | 280 | static const SyncStageAccessFlags kColorAttachmentAccessScope = |
| 281 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_BIT | |
| 282 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT | |
| 283 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE_BIT | |
| 284 | 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] | 285 | static constexpr VkPipelineStageFlags2KHR kDepthStencilAttachmentExecScope = |
| 286 | 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] | 287 | static const SyncStageAccessFlags kDepthStencilAttachmentAccessScope = |
| 288 | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 289 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 290 | 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] | 291 | static constexpr VkPipelineStageFlags2KHR kRasterAttachmentExecScope = kDepthStencilAttachmentExecScope | kColorAttachmentExecScope; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 292 | static const SyncStageAccessFlags kRasterAttachmentAccessScope = kDepthStencilAttachmentAccessScope | kColorAttachmentAccessScope; |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 293 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 294 | ResourceAccessState::OrderingBarriers ResourceAccessState::kOrderingRules = { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 295 | {{VK_PIPELINE_STAGE_2_NONE_KHR, SyncStageAccessFlags()}, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 296 | {kColorAttachmentExecScope, kColorAttachmentAccessScope}, |
| 297 | {kDepthStencilAttachmentExecScope, kDepthStencilAttachmentAccessScope}, |
| 298 | {kRasterAttachmentExecScope, kRasterAttachmentAccessScope}}}; |
| 299 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 300 | // Sometimes we have an internal access conflict, and we using the kCurrentCommandTag to set and detect in temporary/proxy contexts |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 301 | static const ResourceUsageTag kCurrentCommandTag(ResourceUsageRecord::kMaxIndex); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 302 | |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 303 | static VkDeviceSize ResourceBaseAddress(const BINDABLE &bindable) { return bindable.GetFakeBaseAddress(); } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 304 | |
locke-lunarg | 3c03800 | 2020-04-30 23:08:08 -0600 | [diff] [blame] | 305 | inline VkDeviceSize GetRealWholeSize(VkDeviceSize offset, VkDeviceSize size, VkDeviceSize whole_size) { |
| 306 | if (size == VK_WHOLE_SIZE) { |
| 307 | return (whole_size - offset); |
| 308 | } |
| 309 | return size; |
| 310 | } |
| 311 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 312 | static inline VkDeviceSize GetBufferWholeSize(const BUFFER_STATE &buf_state, VkDeviceSize offset, VkDeviceSize size) { |
| 313 | return GetRealWholeSize(offset, size, buf_state.createInfo.size); |
| 314 | } |
| 315 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 316 | template <typename T> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 317 | static ResourceAccessRange MakeRange(const T &has_offset_and_size) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 318 | return ResourceAccessRange(has_offset_and_size.offset, (has_offset_and_size.offset + has_offset_and_size.size)); |
| 319 | } |
| 320 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 321 | static ResourceAccessRange MakeRange(VkDeviceSize start, VkDeviceSize size) { return ResourceAccessRange(start, (start + size)); } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 322 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 323 | static inline ResourceAccessRange MakeRange(const BUFFER_STATE &buffer, VkDeviceSize offset, VkDeviceSize size) { |
| 324 | return MakeRange(offset, GetBufferWholeSize(buffer, offset, size)); |
| 325 | } |
| 326 | |
| 327 | static inline ResourceAccessRange MakeRange(const BUFFER_VIEW_STATE &buf_view_state) { |
| 328 | return MakeRange(*buf_view_state.buffer_state.get(), buf_view_state.create_info.offset, buf_view_state.create_info.range); |
| 329 | } |
| 330 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 331 | // Range generators for to allow event scope filtration to be limited to the top of the resource access traversal pipeline |
| 332 | // |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 333 | // Note: there is no "begin/end" or reset facility. These are each written as "one time through" generators. |
| 334 | // |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 335 | // Usage: |
| 336 | // Constructor() -- initializes the generator to point to the begin of the space declared. |
| 337 | // * -- the current range of the generator empty signfies end |
| 338 | // ++ -- advance to the next non-empty range (or end) |
| 339 | |
| 340 | // A wrapper for a single range with the same semantics as the actual generators below |
| 341 | template <typename KeyType> |
| 342 | class SingleRangeGenerator { |
| 343 | public: |
| 344 | SingleRangeGenerator(const KeyType &range) : current_(range) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 345 | const KeyType &operator*() const { return current_; } |
| 346 | const KeyType *operator->() const { return ¤t_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 347 | SingleRangeGenerator &operator++() { |
| 348 | current_ = KeyType(); // just one real range |
| 349 | return *this; |
| 350 | } |
| 351 | |
| 352 | bool operator==(const SingleRangeGenerator &other) const { return current_ == other.current_; } |
| 353 | |
| 354 | private: |
| 355 | SingleRangeGenerator() = default; |
| 356 | const KeyType range_; |
| 357 | KeyType current_; |
| 358 | }; |
| 359 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 360 | // Generate the ranges that are the intersection of range and the entries in the RangeMap |
| 361 | template <typename RangeMap, typename KeyType = typename RangeMap::key_type> |
| 362 | class MapRangesRangeGenerator { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 363 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 364 | // 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] | 365 | MapRangesRangeGenerator() : range_(), map_(nullptr), map_pos_(), current_() { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 366 | // Default construction for KeyType *must* be empty range |
| 367 | assert(current_.empty()); |
| 368 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 369 | 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] | 370 | SeekBegin(); |
| 371 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 372 | MapRangesRangeGenerator(const MapRangesRangeGenerator &from) = default; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 373 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 374 | const KeyType &operator*() const { return current_; } |
| 375 | const KeyType *operator->() const { return ¤t_; } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 376 | MapRangesRangeGenerator &operator++() { |
| 377 | ++map_pos_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 378 | UpdateCurrent(); |
| 379 | return *this; |
| 380 | } |
| 381 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 382 | bool operator==(const MapRangesRangeGenerator &other) const { return current_ == other.current_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 383 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 384 | protected: |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 385 | void UpdateCurrent() { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 386 | if (map_pos_ != map_->cend()) { |
| 387 | current_ = range_ & map_pos_->first; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 388 | } else { |
| 389 | current_ = KeyType(); |
| 390 | } |
| 391 | } |
| 392 | void SeekBegin() { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 393 | map_pos_ = map_->lower_bound(range_); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 394 | UpdateCurrent(); |
| 395 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 396 | |
| 397 | // Adding this functionality here, to avoid gratuitous Base:: qualifiers in the derived class |
| 398 | // Note: Not exposed in this classes public interface to encourage using a consistent ++/empty generator semantic |
| 399 | template <typename Pred> |
| 400 | MapRangesRangeGenerator &PredicatedIncrement(Pred &pred) { |
| 401 | do { |
| 402 | ++map_pos_; |
| 403 | } while (map_pos_ != map_->cend() && map_pos_->first.intersects(range_) && !pred(map_pos_)); |
| 404 | UpdateCurrent(); |
| 405 | return *this; |
| 406 | } |
| 407 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 408 | const KeyType range_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 409 | const RangeMap *map_; |
| 410 | typename RangeMap::const_iterator map_pos_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 411 | KeyType current_; |
| 412 | }; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 413 | using SingleAccessRangeGenerator = SingleRangeGenerator<ResourceAccessRange>; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 414 | using EventSimpleRangeGenerator = MapRangesRangeGenerator<SyncEventState::ScopeMap>; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 415 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 416 | // Generate the ranges for entries meeting the predicate that are the intersection of range and the entries in the RangeMap |
| 417 | template <typename RangeMap, typename Predicate, typename KeyType = typename RangeMap::key_type> |
| 418 | class PredicatedMapRangesRangeGenerator : public MapRangesRangeGenerator<RangeMap, KeyType> { |
| 419 | public: |
| 420 | using Base = MapRangesRangeGenerator<RangeMap, KeyType>; |
| 421 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 422 | PredicatedMapRangesRangeGenerator() : Base(), pred_() {} |
| 423 | PredicatedMapRangesRangeGenerator(const RangeMap &filter, const KeyType &range, Predicate pred) |
| 424 | : Base(filter, range), pred_(pred) {} |
| 425 | PredicatedMapRangesRangeGenerator(const PredicatedMapRangesRangeGenerator &from) = default; |
| 426 | |
| 427 | PredicatedMapRangesRangeGenerator &operator++() { |
| 428 | Base::PredicatedIncrement(pred_); |
| 429 | return *this; |
| 430 | } |
| 431 | |
| 432 | protected: |
| 433 | Predicate pred_; |
| 434 | }; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 435 | |
| 436 | // 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] | 437 | // Templated to allow for different Range generators or map sources... |
| 438 | template <typename RangeMap, typename RangeGen, typename KeyType = typename RangeMap::key_type> |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 439 | class FilteredGeneratorGenerator { |
| 440 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 441 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 442 | FilteredGeneratorGenerator() : filter_(nullptr), gen_(), filter_pos_(), current_() { |
| 443 | // Default construction for KeyType *must* be empty range |
| 444 | assert(current_.empty()); |
| 445 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 446 | 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] | 447 | SeekBegin(); |
| 448 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 449 | FilteredGeneratorGenerator(const FilteredGeneratorGenerator &from) = default; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 450 | const KeyType &operator*() const { return current_; } |
| 451 | const KeyType *operator->() const { return ¤t_; } |
| 452 | FilteredGeneratorGenerator &operator++() { |
| 453 | KeyType gen_range = GenRange(); |
| 454 | KeyType filter_range = FilterRange(); |
| 455 | current_ = KeyType(); |
| 456 | while (gen_range.non_empty() && filter_range.non_empty() && current_.empty()) { |
| 457 | if (gen_range.end > filter_range.end) { |
| 458 | // if the generated range is beyond the filter_range, advance the filter range |
| 459 | filter_range = AdvanceFilter(); |
| 460 | } else { |
| 461 | gen_range = AdvanceGen(); |
| 462 | } |
| 463 | current_ = gen_range & filter_range; |
| 464 | } |
| 465 | return *this; |
| 466 | } |
| 467 | |
| 468 | bool operator==(const FilteredGeneratorGenerator &other) const { return current_ == other.current_; } |
| 469 | |
| 470 | private: |
| 471 | KeyType AdvanceFilter() { |
| 472 | ++filter_pos_; |
| 473 | auto filter_range = FilterRange(); |
| 474 | if (filter_range.valid()) { |
| 475 | FastForwardGen(filter_range); |
| 476 | } |
| 477 | return filter_range; |
| 478 | } |
| 479 | KeyType AdvanceGen() { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 480 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 481 | auto gen_range = GenRange(); |
| 482 | if (gen_range.valid()) { |
| 483 | FastForwardFilter(gen_range); |
| 484 | } |
| 485 | return gen_range; |
| 486 | } |
| 487 | |
| 488 | KeyType FilterRange() const { return (filter_pos_ != filter_->cend()) ? filter_pos_->first : KeyType(); } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 489 | KeyType GenRange() const { return *gen_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 490 | |
| 491 | KeyType FastForwardFilter(const KeyType &range) { |
| 492 | auto filter_range = FilterRange(); |
| 493 | int retry_count = 0; |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 494 | const static int kRetryLimit = 2; // TODO -- determine whether this limit is optimal |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 495 | while (!filter_range.empty() && (filter_range.end <= range.begin)) { |
| 496 | if (retry_count < kRetryLimit) { |
| 497 | ++filter_pos_; |
| 498 | filter_range = FilterRange(); |
| 499 | retry_count++; |
| 500 | } else { |
| 501 | // Okay we've tried walking, do a seek. |
| 502 | filter_pos_ = filter_->lower_bound(range); |
| 503 | break; |
| 504 | } |
| 505 | } |
| 506 | return FilterRange(); |
| 507 | } |
| 508 | |
| 509 | // TODO: Consider adding "seek" (or an absolute bound "get" to range generators to make this walk |
| 510 | // faster. |
| 511 | KeyType FastForwardGen(const KeyType &range) { |
| 512 | auto gen_range = GenRange(); |
| 513 | while (!gen_range.empty() && (gen_range.end <= range.begin)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 514 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 515 | gen_range = GenRange(); |
| 516 | } |
| 517 | return gen_range; |
| 518 | } |
| 519 | |
| 520 | void SeekBegin() { |
| 521 | auto gen_range = GenRange(); |
| 522 | if (gen_range.empty()) { |
| 523 | current_ = KeyType(); |
| 524 | filter_pos_ = filter_->cend(); |
| 525 | } else { |
| 526 | filter_pos_ = filter_->lower_bound(gen_range); |
| 527 | current_ = gen_range & FilterRange(); |
| 528 | } |
| 529 | } |
| 530 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 531 | const RangeMap *filter_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 532 | RangeGen gen_; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 533 | typename RangeMap::const_iterator filter_pos_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 534 | KeyType current_; |
| 535 | }; |
| 536 | |
| 537 | using EventImageRangeGenerator = FilteredGeneratorGenerator<SyncEventState::ScopeMap, subresource_adapter::ImageRangeGenerator>; |
| 538 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 539 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 540 | ResourceAccessRange GetBufferRange(VkDeviceSize offset, VkDeviceSize buf_whole_size, uint32_t first_index, uint32_t count, |
| 541 | VkDeviceSize stride) { |
| 542 | VkDeviceSize range_start = offset + first_index * stride; |
| 543 | VkDeviceSize range_size = 0; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 544 | if (count == UINT32_MAX) { |
| 545 | range_size = buf_whole_size - range_start; |
| 546 | } else { |
| 547 | range_size = count * stride; |
| 548 | } |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 549 | return MakeRange(range_start, range_size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 550 | } |
| 551 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 552 | SyncStageAccessIndex GetSyncStageAccessIndexsByDescriptorSet(VkDescriptorType descriptor_type, const interface_var &descriptor_data, |
| 553 | VkShaderStageFlagBits stage_flag) { |
| 554 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 555 | assert(stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT); |
| 556 | return SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ; |
| 557 | } |
| 558 | auto stage_access = syncStageAccessMaskByShaderStage.find(stage_flag); |
| 559 | if (stage_access == syncStageAccessMaskByShaderStage.end()) { |
| 560 | assert(0); |
| 561 | } |
| 562 | if (descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) { |
| 563 | return stage_access->second.uniform_read; |
| 564 | } |
| 565 | |
| 566 | // If the desriptorSet is writable, we don't need to care SHADER_READ. SHADER_WRITE is enough. |
| 567 | // Because if write hazard happens, read hazard might or might not happen. |
| 568 | // But if write hazard doesn't happen, read hazard is impossible to happen. |
| 569 | if (descriptor_data.is_writable) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 570 | return stage_access->second.storage_write; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 571 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 572 | // TODO: sampled_read |
| 573 | return stage_access->second.storage_read; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 574 | } |
| 575 | |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 576 | bool IsImageLayoutDepthWritable(VkImageLayout image_layout) { |
| 577 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 578 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL || |
| 579 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) |
| 580 | ? true |
| 581 | : false; |
| 582 | } |
| 583 | |
| 584 | bool IsImageLayoutStencilWritable(VkImageLayout image_layout) { |
| 585 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 586 | image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL || |
| 587 | image_layout == VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL) |
| 588 | ? true |
| 589 | : false; |
| 590 | } |
| 591 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 592 | // 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] | 593 | template <typename Action> |
| 594 | static void ApplyOverImageRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &subresource_range_arg, |
| 595 | Action &action) { |
| 596 | // At this point the "apply over range" logic only supports a single memory binding |
| 597 | if (!SimpleBinding(image_state)) return; |
| 598 | auto subresource_range = NormalizeSubresourceRange(image_state.createInfo, subresource_range_arg); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 599 | const auto base_address = ResourceBaseAddress(image_state); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 600 | subresource_adapter::ImageRangeGenerator range_gen(*image_state.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
| 601 | image_state.createInfo.extent, base_address); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 602 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 603 | action(*range_gen); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 607 | // Tranverse the attachment resolves for this a specific subpass, and do action() to them. |
| 608 | // Used by both validation and record operations |
| 609 | // |
| 610 | // The signature for Action() reflect the needs of both uses. |
| 611 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 612 | void ResolveOperation(Action &action, const RENDER_PASS_STATE &rp_state, const AttachmentViewGenVector &attachment_views, |
| 613 | uint32_t subpass) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 614 | const auto &rp_ci = rp_state.createInfo; |
| 615 | const auto *attachment_ci = rp_ci.pAttachments; |
| 616 | const auto &subpass_ci = rp_ci.pSubpasses[subpass]; |
| 617 | |
| 618 | // Color resolves -- require an inuse color attachment and a matching inuse resolve attachment |
| 619 | const auto *color_attachments = subpass_ci.pColorAttachments; |
| 620 | const auto *color_resolve = subpass_ci.pResolveAttachments; |
| 621 | if (color_resolve && color_attachments) { |
| 622 | for (uint32_t i = 0; i < subpass_ci.colorAttachmentCount; i++) { |
| 623 | const auto &color_attach = color_attachments[i].attachment; |
| 624 | const auto &resolve_attach = subpass_ci.pResolveAttachments[i].attachment; |
| 625 | if ((color_attach != VK_ATTACHMENT_UNUSED) && (resolve_attach != VK_ATTACHMENT_UNUSED)) { |
| 626 | action("color", "resolve read", color_attach, resolve_attach, attachment_views[color_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 627 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, |
| 628 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 629 | action("color", "resolve write", color_attach, resolve_attach, attachment_views[resolve_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 630 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 631 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | // Depth stencil resolve only if the extension is present |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 637 | const auto ds_resolve = LvlFindInChain<VkSubpassDescriptionDepthStencilResolve>(subpass_ci.pNext); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 638 | if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment && |
| 639 | (ds_resolve->pDepthStencilResolveAttachment->attachment != VK_ATTACHMENT_UNUSED) && subpass_ci.pDepthStencilAttachment && |
| 640 | (subpass_ci.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) { |
| 641 | const auto src_at = subpass_ci.pDepthStencilAttachment->attachment; |
| 642 | const auto src_ci = attachment_ci[src_at]; |
| 643 | // The formats are required to match so we can pick either |
| 644 | const bool resolve_depth = (ds_resolve->depthResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasDepth(src_ci.format); |
| 645 | const bool resolve_stencil = (ds_resolve->stencilResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasStencil(src_ci.format); |
| 646 | const auto dst_at = ds_resolve->pDepthStencilResolveAttachment->attachment; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 647 | |
| 648 | // Figure out which aspects are actually touched during resolve operations |
| 649 | const char *aspect_string = nullptr; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 650 | AttachmentViewGen::Gen gen_type = AttachmentViewGen::Gen::kRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 651 | if (resolve_depth && resolve_stencil) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 652 | aspect_string = "depth/stencil"; |
| 653 | } else if (resolve_depth) { |
| 654 | // Validate depth only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 655 | gen_type = AttachmentViewGen::Gen::kDepthOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 656 | aspect_string = "depth"; |
| 657 | } else if (resolve_stencil) { |
| 658 | // Validate all stencil only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 659 | gen_type = AttachmentViewGen::Gen::kStencilOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 660 | aspect_string = "stencil"; |
| 661 | } |
| 662 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 663 | if (aspect_string) { |
| 664 | action(aspect_string, "resolve read", src_at, dst_at, attachment_views[src_at], gen_type, |
| 665 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, SyncOrdering::kRaster); |
| 666 | action(aspect_string, "resolve write", src_at, dst_at, attachment_views[dst_at], gen_type, |
| 667 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | // Action for validating resolve operations |
| 673 | class ValidateResolveAction { |
| 674 | public: |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 675 | ValidateResolveAction(VkRenderPass render_pass, uint32_t subpass, const AccessContext &context, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 676 | const CommandExecutionContext &ex_context, const char *func_name) |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 677 | : render_pass_(render_pass), |
| 678 | subpass_(subpass), |
| 679 | context_(context), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 680 | ex_context_(ex_context), |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 681 | func_name_(func_name), |
| 682 | skip_(false) {} |
| 683 | 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] | 684 | const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, |
| 685 | SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 686 | HazardResult hazard; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 687 | hazard = context_.DetectHazard(view_gen, gen_type, current_usage, ordering_rule); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 688 | if (hazard.hazard) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 689 | skip_ |= |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 690 | ex_context_.GetSyncState().LogError(render_pass_, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 691 | "%s: Hazard %s in subpass %" PRIu32 "during %s %s, from attachment %" PRIu32 |
| 692 | " to resolve attachment %" PRIu32 ". Access info %s.", |
| 693 | func_name_, string_SyncHazard(hazard.hazard), subpass_, aspect_name, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 694 | attachment_name, src_at, dst_at, ex_context_.FormatUsage(hazard).c_str()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | // Providing a mechanism for the constructing caller to get the result of the validation |
| 698 | bool GetSkip() const { return skip_; } |
| 699 | |
| 700 | private: |
| 701 | VkRenderPass render_pass_; |
| 702 | const uint32_t subpass_; |
| 703 | const AccessContext &context_; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 704 | const CommandExecutionContext &ex_context_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 705 | const char *func_name_; |
| 706 | bool skip_; |
| 707 | }; |
| 708 | |
| 709 | // Update action for resolve operations |
| 710 | class UpdateStateResolveAction { |
| 711 | public: |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 712 | UpdateStateResolveAction(AccessContext &context, ResourceUsageTag tag) : context_(context), tag_(tag) {} |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 713 | void operator()(const char *, const char *, uint32_t, uint32_t, const AttachmentViewGen &view_gen, |
| 714 | AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 715 | // Ignores validation only arguments... |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 716 | context_.UpdateAccessState(view_gen, gen_type, current_usage, ordering_rule, tag_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | private: |
| 720 | AccessContext &context_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 721 | const ResourceUsageTag tag_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 722 | }; |
| 723 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 724 | void HazardResult::Set(const ResourceAccessState *access_state_, SyncStageAccessIndex usage_index_, SyncHazard hazard_, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 725 | const SyncStageAccessFlags &prior_, const ResourceUsageTag tag_) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 726 | access_state = layer_data::make_unique<const ResourceAccessState>(*access_state_); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 727 | usage_index = usage_index_; |
| 728 | hazard = hazard_; |
| 729 | prior_access = prior_; |
| 730 | tag = tag_; |
| 731 | } |
| 732 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 733 | void HazardResult::AddRecordedAccess(const ResourceFirstAccess &first_access) { |
| 734 | recorded_access = layer_data::make_unique<const ResourceFirstAccess>(first_access); |
| 735 | } |
| 736 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 737 | AccessContext::AccessContext(uint32_t subpass, VkQueueFlags queue_flags, |
| 738 | const std::vector<SubpassDependencyGraphNode> &dependencies, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 739 | const std::vector<AccessContext> &contexts, const AccessContext *external_context) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 740 | Reset(); |
| 741 | const auto &subpass_dep = dependencies[subpass]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 742 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 743 | prev_.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 744 | 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] | 745 | for (const auto &prev_dep : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 746 | const auto prev_pass = prev_dep.first->pass; |
| 747 | const auto &prev_barriers = prev_dep.second; |
| 748 | assert(prev_dep.second.size()); |
| 749 | prev_.emplace_back(&contexts[prev_pass], queue_flags, prev_barriers); |
| 750 | prev_by_subpass_[prev_pass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 751 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 752 | |
| 753 | async_.reserve(subpass_dep.async.size()); |
| 754 | for (const auto async_subpass : subpass_dep.async) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 755 | async_.emplace_back(&contexts[async_subpass]); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 756 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 757 | if (has_barrier_from_external) { |
| 758 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 759 | prev_.emplace_back(external_context, queue_flags, subpass_dep.barrier_from_external); |
| 760 | src_external_ = &prev_.back(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 761 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 762 | if (subpass_dep.barrier_to_external.size()) { |
| 763 | dst_external_ = TrackBack(this, queue_flags, subpass_dep.barrier_to_external); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 764 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 765 | } |
| 766 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 767 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 768 | HazardResult AccessContext::DetectPreviousHazard(AccessAddressType type, const Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 769 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 770 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 771 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 772 | |
| 773 | HazardResult hazard; |
| 774 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 775 | hazard = detector.Detect(prev); |
| 776 | } |
| 777 | return hazard; |
| 778 | } |
| 779 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 780 | template <typename Action> |
| 781 | void AccessContext::ForAll(Action &&action) { |
| 782 | for (const auto address_type : kAddressTypes) { |
| 783 | auto &accesses = GetAccessStateMap(address_type); |
| 784 | for (const auto &access : accesses) { |
| 785 | action(address_type, access); |
| 786 | } |
| 787 | } |
| 788 | } |
| 789 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 790 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 791 | // the DAG of the contexts (for example subpasses) |
| 792 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 793 | HazardResult AccessContext::DetectHazard(AccessAddressType type, const Detector &detector, const ResourceAccessRange &range, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 794 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 795 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 796 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 797 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 798 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 799 | // so we'll check these first |
| 800 | for (const auto &async_context : async_) { |
| 801 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 802 | if (hazard.hazard) return hazard; |
| 803 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 804 | } |
| 805 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 806 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 807 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 808 | const auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 809 | const auto the_end = accesses.cend(); // End is not invalidated |
| 810 | auto pos = accesses.lower_bound(range); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 811 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 812 | |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 813 | while (pos != the_end && pos->first.begin < range.end) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 814 | // Cover any leading gap, or gap between entries |
| 815 | if (detect_prev) { |
| 816 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 817 | // Cover any leading gap, or gap between entries |
| 818 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 819 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 820 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 821 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 822 | if (hazard.hazard) return hazard; |
| 823 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 824 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 825 | gap.begin = pos->first.end; |
| 826 | } |
| 827 | |
| 828 | hazard = detector.Detect(pos); |
| 829 | if (hazard.hazard) return hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 830 | ++pos; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | if (detect_prev) { |
| 834 | // Detect in the trailing empty as needed |
| 835 | gap.end = range.end; |
| 836 | if (gap.non_empty()) { |
| 837 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 838 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | return hazard; |
| 842 | } |
| 843 | |
| 844 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 845 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 846 | HazardResult AccessContext::DetectAsyncHazard(AccessAddressType type, const Detector &detector, |
| 847 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 848 | auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 849 | auto pos = accesses.lower_bound(range); |
| 850 | const auto the_end = accesses.end(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 851 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 852 | HazardResult hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 853 | while (pos != the_end && pos->first.begin < range.end) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 854 | hazard = detector.DetectAsync(pos, start_tag_); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 855 | if (hazard.hazard) break; |
| 856 | ++pos; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 857 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 858 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 859 | return hazard; |
| 860 | } |
| 861 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 862 | struct ApplySubpassTransitionBarriersAction { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 863 | explicit ApplySubpassTransitionBarriersAction(const std::vector<SyncBarrier> &barriers_) : barriers(barriers_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 864 | void operator()(ResourceAccessState *access) const { |
| 865 | assert(access); |
| 866 | access->ApplyBarriers(barriers, true); |
| 867 | } |
| 868 | const std::vector<SyncBarrier> &barriers; |
| 869 | }; |
| 870 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 871 | struct ApplyTrackbackStackAction { |
| 872 | explicit ApplyTrackbackStackAction(const std::vector<SyncBarrier> &barriers_, |
| 873 | const ResourceAccessStateFunction *previous_barrier_ = nullptr) |
| 874 | : barriers(barriers_), previous_barrier(previous_barrier_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 875 | void operator()(ResourceAccessState *access) const { |
| 876 | assert(access); |
| 877 | assert(!access->HasPendingState()); |
| 878 | access->ApplyBarriers(barriers, false); |
| 879 | access->ApplyPendingBarriers(kCurrentCommandTag); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 880 | if (previous_barrier) { |
| 881 | assert(bool(*previous_barrier)); |
| 882 | (*previous_barrier)(access); |
| 883 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 884 | } |
| 885 | const std::vector<SyncBarrier> &barriers; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 886 | const ResourceAccessStateFunction *previous_barrier; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 887 | }; |
| 888 | |
| 889 | // Splits a single map entry into piece matching the entries in [first, last) the total range over [first, last) must be |
| 890 | // contained with entry. Entry must be an iterator pointing to dest, first and last must be iterators pointing to a |
| 891 | // *different* map from dest. |
| 892 | // Returns the position past the last resolved range -- the entry covering the remainder of entry->first not included in the |
| 893 | // range [first, last) |
| 894 | template <typename BarrierAction> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 895 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 896 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 897 | BarrierAction &barrier_action) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 898 | auto at = entry; |
| 899 | for (auto pos = first; pos != last; ++pos) { |
| 900 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 901 | assert(at->first.includes(pos->first)); |
| 902 | assert(at != dest->end()); |
| 903 | // Trim up at to the same size as the entry to resolve |
| 904 | at = sparse_container::split(at, *dest, pos->first); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 905 | auto access = pos->second; // intentional copy |
| 906 | barrier_action(&access); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 907 | at->second.Resolve(access); |
| 908 | ++at; // Go to the remaining unused section of entry |
| 909 | } |
| 910 | } |
| 911 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 912 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 913 | SyncBarrier merged = {}; |
| 914 | for (const auto &barrier : barriers) { |
| 915 | merged.Merge(barrier); |
| 916 | } |
| 917 | return merged; |
| 918 | } |
| 919 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 920 | template <typename BarrierAction> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 921 | void AccessContext::ResolveAccessRange(AccessAddressType type, const ResourceAccessRange &range, BarrierAction &barrier_action, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 922 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 923 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 924 | if (!range.non_empty()) return; |
| 925 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 926 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 927 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 928 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 929 | if (current->pos_B->valid) { |
| 930 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 931 | auto access = src_pos->second; // intentional copy |
| 932 | barrier_action(&access); |
| 933 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 934 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 935 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 936 | trimmed->second.Resolve(access); |
| 937 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 938 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 939 | 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] | 940 | 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] | 941 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 942 | } else { |
| 943 | // we have to descend to fill this gap |
| 944 | if (recur_to_infill) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 945 | ResourceAccessRange recurrence_range = current_range; |
| 946 | // The current context is empty for the current range, so recur to fill the gap. |
| 947 | // Since we will be recurring back up the DAG, expand the gap descent to cover the full range for which B |
| 948 | // is not valid, to minimize that recurrence |
| 949 | if (current->pos_B.at_end()) { |
| 950 | // Do the remainder here.... |
| 951 | recurrence_range.end = range.end; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 952 | } else { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 953 | // Recur only over the range until B becomes valid (within the limits of range). |
| 954 | 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] | 955 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 956 | ResolvePreviousAccessStack(type, recurrence_range, resolve_map, infill_state, barrier_action); |
| 957 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 958 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 959 | // iterator of the outer while. |
| 960 | |
| 961 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 962 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 963 | // we stepped on the dest map |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 964 | 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] | 965 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 966 | current.seek(seek_to); |
| 967 | } else if (!current->pos_A->valid && infill_state) { |
| 968 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 969 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 970 | 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] | 971 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 972 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 973 | ++current; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 974 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 975 | |
| 976 | // Infill if range goes passed both the current and resolve map prior contents |
| 977 | if (recur_to_infill && (current->range.end < range.end)) { |
| 978 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 979 | ResolvePreviousAccessStack<BarrierAction>(type, trailing_fill_range, resolve_map, infill_state, barrier_action); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 980 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 981 | } |
| 982 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 983 | template <typename BarrierAction> |
| 984 | void AccessContext::ResolvePreviousAccessStack(AccessAddressType type, const ResourceAccessRange &range, |
| 985 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 986 | const BarrierAction &previous_barrier) const { |
| 987 | ResourceAccessStateFunction stacked_barrier(std::ref(previous_barrier)); |
| 988 | ResolvePreviousAccess(type, range, descent_map, infill_state, &stacked_barrier); |
| 989 | } |
| 990 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 991 | void AccessContext::ResolvePreviousAccess(AccessAddressType type, const ResourceAccessRange &range, |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 992 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 993 | const ResourceAccessStateFunction *previous_barrier) const { |
| 994 | if (prev_.size() == 0) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 995 | if (range.non_empty() && infill_state) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 996 | // Fill the empty poritions of descent_map with the default_state with the barrier function applied (iff present) |
| 997 | ResourceAccessState state_copy; |
| 998 | if (previous_barrier) { |
| 999 | assert(bool(*previous_barrier)); |
| 1000 | state_copy = *infill_state; |
| 1001 | (*previous_barrier)(&state_copy); |
| 1002 | infill_state = &state_copy; |
| 1003 | } |
| 1004 | sparse_container::update_range_value(*descent_map, range, *infill_state, |
| 1005 | sparse_container::value_precedence::prefer_dest); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1006 | } |
| 1007 | } else { |
| 1008 | // Look for something to fill the gap further along. |
| 1009 | for (const auto &prev_dep : prev_) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1010 | const ApplyTrackbackStackAction barrier_action(prev_dep.barriers, previous_barrier); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1011 | prev_dep.context->ResolveAccessRange(type, range, barrier_action, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1012 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1013 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1014 | } |
| 1015 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1016 | // Non-lazy import of all accesses, WaitEvents needs this. |
| 1017 | void AccessContext::ResolvePreviousAccesses() { |
| 1018 | ResourceAccessState default_state; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1019 | if (!prev_.size()) return; // If no previous contexts, nothing to do |
| 1020 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1021 | for (const auto address_type : kAddressTypes) { |
| 1022 | ResolvePreviousAccess(address_type, kFullRange, &GetAccessStateMap(address_type), &default_state); |
| 1023 | } |
| 1024 | } |
| 1025 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1026 | AccessAddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
| 1027 | return (image.fragment_encoder->IsLinearImage()) ? AccessAddressType::kLinear : AccessAddressType::kIdealized; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1028 | } |
| 1029 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1030 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1031 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_NONE_EXT) |
| 1032 | ? SYNC_ACCESS_INDEX_NONE |
| 1033 | : ((load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 1034 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1035 | return stage_access; |
| 1036 | } |
| 1037 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1038 | const auto stage_access = |
| 1039 | (load_op == VK_ATTACHMENT_LOAD_OP_NONE_EXT) |
| 1040 | ? SYNC_ACCESS_INDEX_NONE |
| 1041 | : ((load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 1042 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1043 | return stage_access; |
| 1044 | } |
| 1045 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1046 | // Caller must manage returned pointer |
| 1047 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1048 | uint32_t subpass, const AttachmentViewGenVector &attachment_views) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1049 | auto *proxy = new AccessContext(context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1050 | proxy->UpdateAttachmentResolveAccess(rp_state, attachment_views, subpass, kCurrentCommandTag); |
| 1051 | proxy->UpdateAttachmentStoreAccess(rp_state, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1052 | return proxy; |
| 1053 | } |
| 1054 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1055 | template <typename BarrierAction> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1056 | void AccessContext::ResolveAccessRange(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1057 | BarrierAction &barrier_action, ResourceAccessRangeMap *descent_map, |
| 1058 | const ResourceAccessState *infill_state) const { |
| 1059 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1060 | if (!attachment_gen) return; |
| 1061 | |
| 1062 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1063 | const AccessAddressType address_type = view_gen.GetAddressType(); |
| 1064 | for (; range_gen->non_empty(); ++range_gen) { |
| 1065 | ResolveAccessRange(address_type, *range_gen, barrier_action, descent_map, infill_state); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1066 | } |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 1067 | } |
| 1068 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1069 | // Layout transitions are handled as if the were occuring in the beginning of the next subpass |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1070 | bool AccessContext::ValidateLayoutTransitions(const CommandExecutionContext &ex_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1071 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1072 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1073 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1074 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 1075 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 1076 | // those affects have not been recorded yet. |
| 1077 | // |
| 1078 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 1079 | // to apply and only copy then, if this proves a hot spot. |
| 1080 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 1081 | TrackBack proxy_track_back; |
| 1082 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1083 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 1084 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1085 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 1086 | |
| 1087 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1088 | assert(track_back); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1089 | if (prev_needs_proxy) { |
| 1090 | if (!proxy_for_prev) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1091 | proxy_for_prev.reset( |
| 1092 | CreateStoreResolveProxyContext(*track_back->context, rp_state, transition.prev_pass, attachment_views)); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1093 | proxy_track_back = *track_back; |
| 1094 | proxy_track_back.context = proxy_for_prev.get(); |
| 1095 | } |
| 1096 | track_back = &proxy_track_back; |
| 1097 | } |
| 1098 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1099 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1100 | skip |= ex_context.GetSyncState().LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1101 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1102 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 1103 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1104 | string_VkImageLayout(transition.old_layout), |
| 1105 | string_VkImageLayout(transition.new_layout), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1106 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | return skip; |
| 1110 | } |
| 1111 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1112 | bool AccessContext::ValidateLoadOperation(const CommandExecutionContext &ex_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1113 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1114 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1115 | bool skip = false; |
| 1116 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1117 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1118 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1119 | if (subpass == rp_state.attachment_first_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1120 | const auto &view_gen = attachment_views[i]; |
| 1121 | if (!view_gen.IsValid()) continue; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1122 | const auto &ci = attachment_ci[i]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1123 | |
| 1124 | // Need check in the following way |
| 1125 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 1126 | // vs. transition |
| 1127 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 1128 | // for each aspect loaded. |
| 1129 | |
| 1130 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1131 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1132 | const bool is_color = !(has_depth || has_stencil); |
| 1133 | |
| 1134 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1135 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1136 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1137 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1138 | const char *aspect = nullptr; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1139 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1140 | bool checked_stencil = false; |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1141 | if (is_color && (load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1142 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, load_index, SyncOrdering::kColorAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1143 | aspect = "color"; |
| 1144 | } else { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1145 | if (has_depth && (load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1146 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_index, |
| 1147 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1148 | aspect = "depth"; |
| 1149 | } |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1150 | if (!hazard.hazard && has_stencil && (stencil_load_index != SYNC_ACCESS_INDEX_NONE)) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1151 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, stencil_load_index, |
| 1152 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1153 | aspect = "stencil"; |
| 1154 | checked_stencil = true; |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | if (hazard.hazard) { |
| 1159 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1160 | const auto &sync_state = ex_context.GetSyncState(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1161 | if (hazard.tag == kCurrentCommandTag) { |
| 1162 | // Hazard vs. ILT |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1163 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1164 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1165 | " aspect %s during load with loadOp %s.", |
| 1166 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string); |
| 1167 | } else { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1168 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1169 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1170 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1171 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1172 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | return skip; |
| 1178 | } |
| 1179 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1180 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 1181 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 1182 | // store is part of the same Next/End operation. |
| 1183 | // The latter is handled in layout transistion validation directly |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1184 | bool AccessContext::ValidateStoreOperation(const CommandExecutionContext &ex_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1185 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1186 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1187 | bool skip = false; |
| 1188 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1189 | |
| 1190 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1191 | if (subpass == rp_state.attachment_last_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1192 | const AttachmentViewGen &view_gen = attachment_views[i]; |
| 1193 | if (!view_gen.IsValid()) continue; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1194 | const auto &ci = attachment_ci[i]; |
| 1195 | |
| 1196 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1197 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 1198 | // sake, we treat DONT_CARE as writing. |
| 1199 | const bool has_depth = FormatHasDepth(ci.format); |
| 1200 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1201 | const bool is_color = !(has_depth || has_stencil); |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1202 | 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] | 1203 | if (!has_stencil && !store_op_stores) continue; |
| 1204 | |
| 1205 | HazardResult hazard; |
| 1206 | const char *aspect = nullptr; |
| 1207 | bool checked_stencil = false; |
| 1208 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1209 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1210 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1211 | aspect = "color"; |
| 1212 | } else { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1213 | 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] | 1214 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1215 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1216 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1217 | aspect = "depth"; |
| 1218 | } |
| 1219 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1220 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1221 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1222 | aspect = "stencil"; |
| 1223 | checked_stencil = true; |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | if (hazard.hazard) { |
| 1228 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 1229 | const char *const store_op_string = string_VkAttachmentStoreOp(checked_stencil ? ci.stencilStoreOp : ci.storeOp); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1230 | skip |= ex_context.GetSyncState().LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1231 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1232 | " %s aspect during store with %s %s. Access info %s", |
| 1233 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1234 | op_type_string, store_op_string, ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | } |
| 1238 | return skip; |
| 1239 | } |
| 1240 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1241 | bool AccessContext::ValidateResolveOperations(const CommandExecutionContext &ex_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1242 | const VkRect2D &render_area, const AttachmentViewGenVector &attachment_views, |
| 1243 | const char *func_name, uint32_t subpass) const { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1244 | ValidateResolveAction validate_action(rp_state.renderPass(), subpass, *this, ex_context, func_name); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1245 | ResolveOperation(validate_action, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1246 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1247 | } |
| 1248 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1249 | class HazardDetector { |
| 1250 | SyncStageAccessIndex usage_index_; |
| 1251 | |
| 1252 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1253 | 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] | 1254 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1255 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1256 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1257 | explicit HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1258 | }; |
| 1259 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1260 | class HazardDetectorWithOrdering { |
| 1261 | const SyncStageAccessIndex usage_index_; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1262 | const SyncOrdering ordering_rule_; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1263 | |
| 1264 | public: |
| 1265 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1266 | return pos->second.DetectHazard(usage_index_, ordering_rule_); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1267 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1268 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1269 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1270 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1271 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, SyncOrdering ordering) : usage_index_(usage), ordering_rule_(ordering) {} |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1272 | }; |
| 1273 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1274 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1275 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1276 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1277 | const auto base_address = ResourceBaseAddress(buffer); |
| 1278 | HazardDetector detector(usage_index); |
| 1279 | return DetectHazard(AccessAddressType::kLinear, detector, (range + base_address), DetectOptions::kDetectAll); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 1280 | } |
| 1281 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1282 | template <typename Detector> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1283 | HazardResult AccessContext::DetectHazard(Detector &detector, const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1284 | DetectOptions options) const { |
| 1285 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1286 | if (!attachment_gen) return HazardResult(); |
| 1287 | |
| 1288 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1289 | const auto address_type = view_gen.GetAddressType(); |
| 1290 | for (; range_gen->non_empty(); ++range_gen) { |
| 1291 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1292 | if (hazard.hazard) return hazard; |
| 1293 | } |
| 1294 | |
| 1295 | return HazardResult(); |
| 1296 | } |
| 1297 | |
| 1298 | template <typename Detector> |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1299 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1300 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1301 | const VkExtent3D &extent, DetectOptions options) const { |
| 1302 | if (!SimpleBinding(image)) return HazardResult(); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1303 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1304 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1305 | base_address); |
| 1306 | const auto address_type = ImageAddressType(image); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1307 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1308 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1309 | if (hazard.hazard) return hazard; |
| 1310 | } |
| 1311 | return HazardResult(); |
| 1312 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1313 | template <typename Detector> |
| 1314 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1315 | const VkImageSubresourceRange &subresource_range, DetectOptions options) const { |
| 1316 | if (!SimpleBinding(image)) return HazardResult(); |
| 1317 | const auto base_address = ResourceBaseAddress(image); |
| 1318 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
| 1319 | const auto address_type = ImageAddressType(image); |
| 1320 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1321 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1322 | if (hazard.hazard) return hazard; |
| 1323 | } |
| 1324 | return HazardResult(); |
| 1325 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1326 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1327 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1328 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1329 | const VkExtent3D &extent) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1330 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1331 | subresource.layerCount}; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1332 | HazardDetector detector(current_usage); |
| 1333 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1337 | const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1338 | HazardDetector detector(current_usage); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1339 | return DetectHazard(detector, image, subresource_range, DetectOptions::kDetectAll); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1340 | } |
| 1341 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1342 | HazardResult AccessContext::DetectHazard(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1343 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) const { |
| 1344 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
| 1345 | return DetectHazard(detector, view_gen, gen_type, DetectOptions::kDetectAll); |
| 1346 | } |
| 1347 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1348 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1349 | const VkImageSubresourceRange &subresource_range, SyncOrdering ordering_rule, |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1350 | const VkOffset3D &offset, const VkExtent3D &extent) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1351 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1352 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1353 | } |
| 1354 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1355 | class BarrierHazardDetector { |
| 1356 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1357 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1358 | SyncStageAccessFlags src_access_scope) |
| 1359 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1360 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1361 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1362 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1363 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1364 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1365 | // 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] | 1366 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | private: |
| 1370 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1371 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1372 | SyncStageAccessFlags src_access_scope_; |
| 1373 | }; |
| 1374 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1375 | class EventBarrierHazardDetector { |
| 1376 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1377 | EventBarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1378 | SyncStageAccessFlags src_access_scope, const SyncEventState::ScopeMap &event_scope, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1379 | ResourceUsageTag scope_tag) |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1380 | : usage_index_(usage_index), |
| 1381 | src_exec_scope_(src_exec_scope), |
| 1382 | src_access_scope_(src_access_scope), |
| 1383 | event_scope_(event_scope), |
| 1384 | scope_pos_(event_scope.cbegin()), |
| 1385 | scope_end_(event_scope.cend()), |
| 1386 | scope_tag_(scope_tag) {} |
| 1387 | |
| 1388 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1389 | // TODO NOTE: This is almost the slowest way to do this... need to intelligently walk this... |
| 1390 | // Need to find a more efficient sync, since we know pos->first is strictly increasing call to call |
| 1391 | // NOTE: "cached_lower_bound_impl" with upgrades could do this. |
| 1392 | if (scope_pos_ == scope_end_) return HazardResult(); |
| 1393 | if (!scope_pos_->first.intersects(pos->first)) { |
| 1394 | event_scope_.lower_bound(pos->first); |
| 1395 | if ((scope_pos_ == scope_end_) || !scope_pos_->first.intersects(pos->first)) return HazardResult(); |
| 1396 | } |
| 1397 | |
| 1398 | // Some portion of this pos is in the event_scope, so check for a barrier hazard |
| 1399 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_, scope_tag_); |
| 1400 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1401 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1402 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1403 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
| 1404 | } |
| 1405 | |
| 1406 | private: |
| 1407 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1408 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1409 | SyncStageAccessFlags src_access_scope_; |
| 1410 | const SyncEventState::ScopeMap &event_scope_; |
| 1411 | SyncEventState::ScopeMap::const_iterator scope_pos_; |
| 1412 | SyncEventState::ScopeMap::const_iterator scope_end_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1413 | const ResourceUsageTag scope_tag_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1414 | }; |
| 1415 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1416 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1417 | const SyncStageAccessFlags &src_access_scope, |
| 1418 | const VkImageSubresourceRange &subresource_range, |
| 1419 | const SyncEventState &sync_event, DetectOptions options) const { |
| 1420 | // It's not particularly DRY to get the address type in this function as well as lower down, but we have to select the |
| 1421 | // first access scope map to use, and there's no easy way to plumb it in below. |
| 1422 | const auto address_type = ImageAddressType(image); |
| 1423 | const auto &event_scope = sync_event.FirstScope(address_type); |
| 1424 | |
| 1425 | EventBarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope, |
| 1426 | event_scope, sync_event.first_scope_tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1427 | return DetectHazard(detector, image, subresource_range, options); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1430 | HazardResult AccessContext::DetectImageBarrierHazard(const AttachmentViewGen &view_gen, const SyncBarrier &barrier, |
| 1431 | DetectOptions options) const { |
| 1432 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, barrier.src_exec_scope.exec_scope, |
| 1433 | barrier.src_access_scope); |
| 1434 | return DetectHazard(detector, view_gen, AttachmentViewGen::Gen::kViewSubresource, options); |
| 1435 | } |
| 1436 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1437 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1438 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1439 | const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1440 | const DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1441 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1442 | return DetectHazard(detector, image, subresource_range, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1445 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1446 | const SyncStageAccessFlags &src_stage_accesses, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1447 | const VkImageMemoryBarrier &barrier) const { |
| 1448 | auto subresource_range = NormalizeSubresourceRange(image.createInfo, barrier.subresourceRange); |
| 1449 | const auto src_access_scope = SyncStageAccess::AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 1450 | return DetectImageBarrierHazard(image, src_exec_scope, src_access_scope, subresource_range, kDetectAll); |
| 1451 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1452 | HazardResult AccessContext::DetectImageBarrierHazard(const SyncImageMemoryBarrier &image_barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1453 | 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] | 1454 | image_barrier.barrier.src_access_scope, image_barrier.range, kDetectAll); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1455 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1456 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1457 | template <typename Flags, typename Map> |
| 1458 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1459 | SyncStageAccessFlags scope = 0; |
| 1460 | for (const auto &bit_scope : map) { |
| 1461 | if (flag_mask < bit_scope.first) break; |
| 1462 | |
| 1463 | if (flag_mask & bit_scope.first) { |
| 1464 | scope |= bit_scope.second; |
| 1465 | } |
| 1466 | } |
| 1467 | return scope; |
| 1468 | } |
| 1469 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1470 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags2KHR stages) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1471 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1472 | } |
| 1473 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1474 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags2KHR accesses) { |
| 1475 | return AccessScopeImpl(sync_utils::ExpandAccessFlags(accesses), syncStageAccessMaskByAccessBit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1476 | } |
| 1477 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1478 | // Getting from stage mask and access mask to stage/access masks is something we need to be good at... |
| 1479 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags2KHR stages, VkAccessFlags2KHR accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1480 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1481 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1482 | // 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] | 1483 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1484 | } |
| 1485 | |
| 1486 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1487 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1488 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1489 | // that do incrementalupdates |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1490 | assert(accesses); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1491 | auto pos = accesses->lower_bound(range); |
| 1492 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1493 | // The range is empty, fill it with a default value. |
| 1494 | pos = action.Infill(accesses, pos, range); |
| 1495 | } else if (range.begin < pos->first.begin) { |
| 1496 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1497 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1498 | } else if (pos->first.begin < range.begin) { |
| 1499 | // Trim the beginning if needed |
| 1500 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1501 | ++pos; |
| 1502 | } |
| 1503 | |
| 1504 | const auto the_end = accesses->end(); |
| 1505 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1506 | if (pos->first.end > range.end) { |
| 1507 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1508 | } |
| 1509 | |
| 1510 | pos = action(accesses, pos); |
| 1511 | if (pos == the_end) break; |
| 1512 | |
| 1513 | auto next = pos; |
| 1514 | ++next; |
| 1515 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1516 | // Need to infill if next is disjoint |
| 1517 | 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] | 1518 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1519 | next = action.Infill(accesses, next, new_range); |
| 1520 | } |
| 1521 | pos = next; |
| 1522 | } |
| 1523 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1524 | |
| 1525 | // Give a comparable interface for range generators and ranges |
| 1526 | template <typename Action> |
| 1527 | inline void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, ResourceAccessRange *range) { |
| 1528 | assert(range); |
| 1529 | UpdateMemoryAccessState(accesses, *range, action); |
| 1530 | } |
| 1531 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1532 | template <typename Action, typename RangeGen> |
| 1533 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, RangeGen *range_gen_arg) { |
| 1534 | assert(range_gen_arg); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1535 | 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] | 1536 | for (; range_gen->non_empty(); ++range_gen) { |
| 1537 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1538 | } |
| 1539 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1540 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1541 | template <typename Action, typename RangeGen> |
| 1542 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, const RangeGen &range_gen_prebuilt) { |
| 1543 | RangeGen range_gen(range_gen_prebuilt); // RangeGenerators can be expensive to create from scratch... initialize from built |
| 1544 | for (; range_gen->non_empty(); ++range_gen) { |
| 1545 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1546 | } |
| 1547 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1548 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1549 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1550 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1551 | // this is only called on gaps, and never returns a gap. |
| 1552 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1553 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1554 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1555 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1556 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1557 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1558 | auto &access_state = pos->second; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1559 | access_state.Update(usage, ordering_rule, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1560 | return pos; |
| 1561 | } |
| 1562 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1563 | UpdateMemoryAccessStateFunctor(AccessAddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1564 | SyncOrdering ordering_rule_, ResourceUsageTag tag_) |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1565 | : type(type_), context(context_), usage(usage_), ordering_rule(ordering_rule_), tag(tag_) {} |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1566 | const AccessAddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1567 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1568 | const SyncStageAccessIndex usage; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1569 | const SyncOrdering ordering_rule; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1570 | const ResourceUsageTag tag; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1571 | }; |
| 1572 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1573 | // The barrier operation for pipeline and subpass dependencies` |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1574 | struct PipelineBarrierOp { |
| 1575 | SyncBarrier barrier; |
| 1576 | bool layout_transition; |
| 1577 | PipelineBarrierOp(const SyncBarrier &barrier_, bool layout_transition_) |
| 1578 | : barrier(barrier_), layout_transition(layout_transition_) {} |
| 1579 | PipelineBarrierOp() = default; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1580 | PipelineBarrierOp(const PipelineBarrierOp &) = default; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1581 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(barrier, layout_transition); } |
| 1582 | }; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1583 | // The barrier operation for wait events |
| 1584 | struct WaitEventBarrierOp { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1585 | ResourceUsageTag scope_tag; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1586 | SyncBarrier barrier; |
| 1587 | bool layout_transition; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1588 | WaitEventBarrierOp(const ResourceUsageTag scope_tag_, const SyncBarrier &barrier_, bool layout_transition_) |
| 1589 | : scope_tag(scope_tag_), barrier(barrier_), layout_transition(layout_transition_) {} |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1590 | WaitEventBarrierOp() = default; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1591 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(scope_tag, barrier, layout_transition); } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1592 | }; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1593 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1594 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1595 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1596 | // of a collection is known/present. |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1597 | template <typename BarrierOp, typename OpVector = std::vector<BarrierOp>> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1598 | class ApplyBarrierOpsFunctor { |
| 1599 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1600 | using Iterator = ResourceAccessRangeMap::iterator; |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1601 | // Only called with a gap, and pos at the lower_bound(range) |
| 1602 | inline Iterator Infill(ResourceAccessRangeMap *accesses, const Iterator &pos, const ResourceAccessRange &range) const { |
| 1603 | if (!infill_default_) { |
| 1604 | return pos; |
| 1605 | } |
| 1606 | ResourceAccessState default_state; |
| 1607 | auto inserted = accesses->insert(pos, std::make_pair(range, default_state)); |
| 1608 | return inserted; |
| 1609 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1610 | |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1611 | Iterator operator()(ResourceAccessRangeMap *accesses, const Iterator &pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1612 | auto &access_state = pos->second; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1613 | for (const auto &op : barrier_ops_) { |
| 1614 | op(&access_state); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1615 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1616 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1617 | if (resolve_) { |
| 1618 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1619 | // another walk |
| 1620 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1621 | } |
| 1622 | return pos; |
| 1623 | } |
| 1624 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1625 | // 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] | 1626 | ApplyBarrierOpsFunctor(bool resolve, typename OpVector::size_type size_hint, ResourceUsageTag tag) |
| 1627 | : resolve_(resolve), infill_default_(false), barrier_ops_(), tag_(tag) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1628 | barrier_ops_.reserve(size_hint); |
| 1629 | } |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1630 | void EmplaceBack(const BarrierOp &op) { |
| 1631 | barrier_ops_.emplace_back(op); |
| 1632 | infill_default_ |= op.layout_transition; |
| 1633 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1634 | |
| 1635 | private: |
| 1636 | bool resolve_; |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1637 | bool infill_default_; |
| 1638 | OpVector barrier_ops_; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1639 | const ResourceUsageTag tag_; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1640 | }; |
| 1641 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1642 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1643 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1644 | template <typename BarrierOp> |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1645 | class ApplyBarrierFunctor : public ApplyBarrierOpsFunctor<BarrierOp, small_vector<BarrierOp, 1>> { |
| 1646 | using Base = ApplyBarrierOpsFunctor<BarrierOp, small_vector<BarrierOp, 1>>; |
| 1647 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1648 | public: |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1649 | ApplyBarrierFunctor(const BarrierOp &barrier_op) : Base(false, 1, kCurrentCommandTag) { Base::EmplaceBack(barrier_op); } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1650 | }; |
| 1651 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1652 | // This functor resolves the pendinging state. |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1653 | class ResolvePendingBarrierFunctor : public ApplyBarrierOpsFunctor<NoopBarrierAction, small_vector<NoopBarrierAction, 1>> { |
| 1654 | using Base = ApplyBarrierOpsFunctor<NoopBarrierAction, small_vector<NoopBarrierAction, 1>>; |
| 1655 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1656 | public: |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 1657 | ResolvePendingBarrierFunctor(ResourceUsageTag tag) : Base(true, 0, tag) {} |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1658 | }; |
| 1659 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1660 | void AccessContext::UpdateAccessState(AccessAddressType type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1661 | const ResourceAccessRange &range, const ResourceUsageTag tag) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1662 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1663 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1664 | } |
| 1665 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1666 | 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] | 1667 | const ResourceAccessRange &range, const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1668 | if (!SimpleBinding(buffer)) return; |
| 1669 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1670 | UpdateAccessState(AccessAddressType::kLinear, current_usage, ordering_rule, range + base_address, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1671 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1672 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1673 | 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] | 1674 | const VkImageSubresourceRange &subresource_range, const ResourceUsageTag &tag) { |
| 1675 | if (!SimpleBinding(image)) return; |
| 1676 | const auto base_address = ResourceBaseAddress(image); |
| 1677 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
| 1678 | const auto address_type = ImageAddressType(image); |
| 1679 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1680 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
| 1681 | } |
| 1682 | 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] | 1683 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1684 | const VkExtent3D &extent, const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1685 | if (!SimpleBinding(image)) return; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1686 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1687 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1688 | base_address); |
| 1689 | const auto address_type = ImageAddressType(image); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1690 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1691 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1692 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1693 | |
| 1694 | void AccessContext::UpdateAccessState(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1695 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, const ResourceUsageTag tag) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1696 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1697 | if (!gen) return; |
| 1698 | subresource_adapter::ImageRangeGenerator range_gen(*gen); |
| 1699 | const auto address_type = view_gen.GetAddressType(); |
| 1700 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1701 | ApplyUpdateAction(address_type, action, &range_gen); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1702 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1703 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1704 | 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] | 1705 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1706 | const VkExtent3D &extent, const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1707 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1708 | subresource.layerCount}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1709 | UpdateAccessState(image, current_usage, ordering_rule, subresource_range, offset, extent, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1710 | } |
| 1711 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1712 | template <typename Action, typename RangeGen> |
| 1713 | void AccessContext::ApplyUpdateAction(AccessAddressType address_type, const Action &action, RangeGen *range_gen_arg) { |
| 1714 | assert(range_gen_arg); // Old Google C++ styleguide require non-const object pass by * not &, but this isn't an optional arg. |
| 1715 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, range_gen_arg); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1719 | void AccessContext::ApplyUpdateAction(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, const Action &action) { |
| 1720 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1721 | if (!gen) return; |
| 1722 | UpdateMemoryAccessState(&GetAccessStateMap(view_gen.GetAddressType()), action, *gen); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1723 | } |
| 1724 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1725 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, |
| 1726 | const AttachmentViewGenVector &attachment_views, uint32_t subpass, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1727 | const ResourceUsageTag tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1728 | UpdateStateResolveAction update(*this, tag); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1729 | ResolveOperation(update, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1730 | } |
| 1731 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1732 | 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] | 1733 | uint32_t subpass, const ResourceUsageTag tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1734 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1735 | |
| 1736 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1737 | if (rp_state.attachment_last_subpass[i] == subpass) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1738 | const auto &view_gen = attachment_views[i]; |
| 1739 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1740 | |
| 1741 | const auto &ci = attachment_ci[i]; |
| 1742 | const bool has_depth = FormatHasDepth(ci.format); |
| 1743 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1744 | const bool is_color = !(has_depth || has_stencil); |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1745 | 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] | 1746 | |
| 1747 | if (is_color && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1748 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1749 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1750 | } else { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1751 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1752 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1753 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1754 | } |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 1755 | 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] | 1756 | if (has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1757 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1758 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | } |
| 1763 | } |
| 1764 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1765 | template <typename Action> |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1766 | void AccessContext::ApplyToContext(const Action &barrier_action) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1767 | // 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] | 1768 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1769 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), kFullRange, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1774 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1775 | auto &context = contexts[subpass_index]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1776 | ApplyTrackbackStackAction barrier_action(context.GetDstExternalTrackBack().barriers); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1777 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1778 | context.ResolveAccessRange(address_type, kFullRange, barrier_action, &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1779 | } |
| 1780 | } |
| 1781 | } |
| 1782 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 1783 | // Caller must ensure that lifespan of this is less than from |
| 1784 | void AccessContext::ImportAsyncContexts(const AccessContext &from) { async_ = from.async_; } |
| 1785 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1786 | // Suitable only for *subpass* access contexts |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1787 | HazardResult AccessContext::DetectSubpassTransitionHazard(const TrackBack &track_back, const AttachmentViewGen &attach_view) const { |
| 1788 | if (!attach_view.IsValid()) return HazardResult(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1789 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1790 | // We should never ask for a transition from a context we don't have |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1791 | assert(track_back.context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1792 | |
| 1793 | // 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] | 1794 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1795 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1796 | HazardResult hazard = track_back.context->DetectImageBarrierHazard(attach_view, merged_barrier, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1797 | if (!hazard.hazard) { |
| 1798 | // The Async hazard check is against the current context's async set. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1799 | hazard = DetectImageBarrierHazard(attach_view, merged_barrier, kDetectAsync); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1800 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1801 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1802 | return hazard; |
| 1803 | } |
| 1804 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1805 | void AccessContext::RecordLayoutTransitions(const RENDER_PASS_STATE &rp_state, uint32_t subpass, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1806 | const AttachmentViewGenVector &attachment_views, const ResourceUsageTag tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1807 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1808 | const ResourceAccessState empty_infill; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1809 | for (const auto &transition : transitions) { |
| 1810 | const auto prev_pass = transition.prev_pass; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1811 | const auto &view_gen = attachment_views[transition.attachment]; |
| 1812 | if (!view_gen.IsValid()) continue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1813 | |
| 1814 | const auto *trackback = GetTrackBackFromSubpass(prev_pass); |
| 1815 | assert(trackback); |
| 1816 | |
| 1817 | // Import the attachments into the current context |
| 1818 | const auto *prev_context = trackback->context; |
| 1819 | assert(prev_context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1820 | const auto address_type = view_gen.GetAddressType(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1821 | auto &target_map = GetAccessStateMap(address_type); |
| 1822 | ApplySubpassTransitionBarriersAction barrier_action(trackback->barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1823 | prev_context->ResolveAccessRange(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action, &target_map, |
| 1824 | &empty_infill); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1825 | } |
| 1826 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1827 | // If there were no transitions skip this global map walk |
| 1828 | if (transitions.size()) { |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1829 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1830 | ApplyToContext(apply_pending_action); |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1831 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1832 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1833 | |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1834 | void CommandBufferAccessContext::ApplyGlobalBarriersToEvents(const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 1835 | auto *events_context = GetCurrentEventsContext(); |
| 1836 | assert(events_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 1837 | events_context->ApplyBarrier(src, dst); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1840 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1841 | const char *func_name) const { |
| 1842 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1843 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1844 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 1845 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1846 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1847 | return skip; |
| 1848 | } |
| 1849 | |
| 1850 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1851 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1852 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1853 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1854 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1855 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1856 | for (const auto &stage_state : pipe->stage_state) { |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 1857 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->create_info.graphics.pRasterizationState && |
| 1858 | pipe->create_info.graphics.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1859 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1860 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1861 | for (const auto &set_binding : stage_state.descriptor_uses) { |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1862 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.set].bound_descriptor_set; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1863 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1864 | set_binding.first.binding); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1865 | const auto descriptor_type = binding_it.GetType(); |
| 1866 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1867 | auto array_idx = 0; |
| 1868 | |
| 1869 | if (binding_it.IsVariableDescriptorCount()) { |
| 1870 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1871 | } |
| 1872 | SyncStageAccessIndex sync_index = |
| 1873 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1874 | |
| 1875 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1876 | uint32_t index = i - index_range.start; |
| 1877 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1878 | switch (descriptor->GetClass()) { |
| 1879 | case DescriptorClass::ImageSampler: |
| 1880 | case DescriptorClass::Image: { |
| 1881 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1882 | VkImageLayout image_layout; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1883 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1884 | const auto image_sampler_descriptor = static_cast<const ImageSamplerDescriptor *>(descriptor); |
| 1885 | img_view_state = image_sampler_descriptor->GetImageViewState(); |
| 1886 | image_layout = image_sampler_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1887 | } else { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1888 | const auto image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 1889 | img_view_state = image_descriptor->GetImageViewState(); |
| 1890 | image_layout = image_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1891 | } |
| 1892 | if (!img_view_state) continue; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1893 | HazardResult hazard; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 1894 | // NOTE: 2D ImageViews of VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT Images are not allowed in |
| 1895 | // Descriptors, so we do not have to worry about depth slicing here. |
| 1896 | // See: VUID 00343 |
| 1897 | assert(!img_view_state->IsDepthSliced()); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1898 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1899 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1900 | |
| 1901 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1902 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1903 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1904 | // Input attachments are subject to raster ordering rules |
| 1905 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1906 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1907 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1908 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1909 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1910 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1911 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1912 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1913 | img_view_state->image_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1914 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 1915 | ", index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1916 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1917 | sync_state_->report_data->FormatHandle(img_view_state->image_view()).c_str(), |
| 1918 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 1919 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1920 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1921 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1922 | set_binding.first.binding, index, FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1923 | } |
| 1924 | break; |
| 1925 | } |
| 1926 | case DescriptorClass::TexelBuffer: { |
| 1927 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1928 | if (!buf_view_state) continue; |
| 1929 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1930 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1931 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1932 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1933 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1934 | buf_view_state->buffer_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1935 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1936 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1937 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view()).c_str(), |
| 1938 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 1939 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1940 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1941 | string_VkDescriptorType(descriptor_type), set_binding.first.binding, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1942 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1943 | } |
| 1944 | break; |
| 1945 | } |
| 1946 | case DescriptorClass::GeneralBuffer: { |
| 1947 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1948 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1949 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1950 | const ResourceAccessRange range = |
| 1951 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1952 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 1953 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1954 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1955 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1956 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1957 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1958 | sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 1959 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 1960 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1961 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1962 | string_VkDescriptorType(descriptor_type), set_binding.first.binding, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1963 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1964 | } |
| 1965 | break; |
| 1966 | } |
| 1967 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1968 | default: |
| 1969 | break; |
| 1970 | } |
| 1971 | } |
| 1972 | } |
| 1973 | } |
| 1974 | return skip; |
| 1975 | } |
| 1976 | |
| 1977 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 1978 | const ResourceUsageTag tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1979 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1980 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 1981 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1982 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1983 | return; |
| 1984 | } |
| 1985 | |
| 1986 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1987 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1988 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1989 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1990 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1991 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1992 | for (const auto &stage_state : pipe->stage_state) { |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 1993 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->create_info.graphics.pRasterizationState && |
| 1994 | pipe->create_info.graphics.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1995 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1996 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1997 | for (const auto &set_binding : stage_state.descriptor_uses) { |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1998 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.set].bound_descriptor_set; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1999 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2000 | set_binding.first.binding); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2001 | const auto descriptor_type = binding_it.GetType(); |
| 2002 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 2003 | auto array_idx = 0; |
| 2004 | |
| 2005 | if (binding_it.IsVariableDescriptorCount()) { |
| 2006 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 2007 | } |
| 2008 | SyncStageAccessIndex sync_index = |
| 2009 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 2010 | |
| 2011 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 2012 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 2013 | switch (descriptor->GetClass()) { |
| 2014 | case DescriptorClass::ImageSampler: |
| 2015 | case DescriptorClass::Image: { |
| 2016 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
| 2017 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
| 2018 | img_view_state = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetImageViewState(); |
| 2019 | } else { |
| 2020 | img_view_state = static_cast<const ImageDescriptor *>(descriptor)->GetImageViewState(); |
| 2021 | } |
| 2022 | if (!img_view_state) continue; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 2023 | // NOTE: 2D ImageViews of VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT Images are not allowed in |
| 2024 | // Descriptors, so we do not have to worry about depth slicing here. |
| 2025 | // See: VUID 00343 |
| 2026 | assert(!img_view_state->IsDepthSliced()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2027 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2028 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2029 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 2030 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 2031 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kRaster, |
| 2032 | img_view_state->normalized_subresource_range, offset, extent, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2033 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 2034 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kNonAttachment, |
| 2035 | img_view_state->normalized_subresource_range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2036 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2037 | break; |
| 2038 | } |
| 2039 | case DescriptorClass::TexelBuffer: { |
| 2040 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 2041 | if (!buf_view_state) continue; |
| 2042 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2043 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2044 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2045 | break; |
| 2046 | } |
| 2047 | case DescriptorClass::GeneralBuffer: { |
| 2048 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 2049 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 2050 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2051 | const ResourceAccessRange range = |
| 2052 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2053 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2054 | break; |
| 2055 | } |
| 2056 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2057 | default: |
| 2058 | break; |
| 2059 | } |
| 2060 | } |
| 2061 | } |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const char *func_name) const { |
| 2066 | bool skip = false; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2067 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2068 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2069 | return skip; |
| 2070 | } |
| 2071 | |
| 2072 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2073 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2074 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2075 | |
| 2076 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2077 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2078 | if (binding_description.binding < binding_buffers_size) { |
| 2079 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2080 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2081 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2082 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2083 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2084 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2085 | 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] | 2086 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2087 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2088 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for vertex %s in %s. Access info %s.", |
| 2089 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 2090 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2091 | } |
| 2092 | } |
| 2093 | } |
| 2094 | return skip; |
| 2095 | } |
| 2096 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2097 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag tag) { |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2098 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2099 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2100 | return; |
| 2101 | } |
| 2102 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2103 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2104 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2105 | |
| 2106 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2107 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2108 | if (binding_description.binding < binding_buffers_size) { |
| 2109 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2110 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2111 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2112 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2113 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2114 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2115 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ, |
| 2116 | SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const char *func_name) const { |
| 2122 | bool skip = false; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2123 | 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] | 2124 | return skip; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2125 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2126 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2127 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2128 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2129 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2130 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2131 | 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] | 2132 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2133 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2134 | index_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for index %s in %s. Access info %s.", |
| 2135 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(index_buf_state->buffer()).c_str(), |
| 2136 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2140 | // We will detect more accurate range in the future. |
| 2141 | skip |= ValidateDrawVertex(UINT32_MAX, 0, func_name); |
| 2142 | return skip; |
| 2143 | } |
| 2144 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2145 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag tag) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2146 | 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] | 2147 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2148 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2149 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2150 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2151 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2152 | 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] | 2153 | |
| 2154 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2155 | // We will detect more accurate range in the future. |
| 2156 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 2157 | } |
| 2158 | |
| 2159 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(const char *func_name) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2160 | bool skip = false; |
| 2161 | if (!current_renderpass_context_) return skip; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2162 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(GetExecutionContext(), *cb_state_.get(), func_name); |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2163 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2164 | } |
| 2165 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2166 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2167 | if (current_renderpass_context_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2168 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), tag); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2169 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2170 | } |
| 2171 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2172 | void CommandBufferAccessContext::RecordBeginRenderPass(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2173 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2174 | const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2175 | // Create an access context the current renderpass. |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2176 | 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] | 2177 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2178 | current_renderpass_context_->RecordBeginRenderPass(tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2179 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2180 | } |
| 2181 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 2182 | void CommandBufferAccessContext::RecordNextSubpass(ResourceUsageTag prev_tag, ResourceUsageTag next_tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2183 | assert(current_renderpass_context_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2184 | current_renderpass_context_->RecordNextSubpass(prev_tag, next_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2185 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
| 2186 | } |
| 2187 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 2188 | void CommandBufferAccessContext::RecordEndRenderPass(const ResourceUsageTag tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2189 | assert(current_renderpass_context_); |
| 2190 | if (!current_renderpass_context_) return; |
| 2191 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 2192 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2193 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2194 | current_renderpass_context_ = nullptr; |
| 2195 | } |
| 2196 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2197 | void CommandBufferAccessContext::RecordDestroyEvent(VkEvent event) { |
| 2198 | // Erase is okay with the key not being |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2199 | const auto *event_state = sync_state_->Get<EVENT_STATE>(event); |
| 2200 | if (event_state) { |
| 2201 | GetCurrentEventsContext()->Destroy(event_state); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2202 | } |
| 2203 | } |
| 2204 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2205 | // The is the recorded cb context |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2206 | bool CommandBufferAccessContext::ValidateFirstUse(CommandBufferAccessContext *proxy_context, const char *func_name, |
| 2207 | uint32_t index) const { |
| 2208 | assert(proxy_context); |
| 2209 | auto *events_context = proxy_context->GetCurrentEventsContext(); |
| 2210 | auto *access_context = proxy_context->GetCurrentAccessContext(); |
| 2211 | const ResourceUsageTag base_tag = proxy_context->GetTagLimit(); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2212 | bool skip = false; |
| 2213 | ResourceUsageRange tag_range = {0, 0}; |
| 2214 | const AccessContext *recorded_context = GetCurrentAccessContext(); |
| 2215 | assert(recorded_context); |
| 2216 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2217 | auto log_msg = [this](const HazardResult &hazard, const CommandBufferAccessContext &active_context, const char *func_name, |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2218 | uint32_t index) { |
| 2219 | const auto cb_handle = active_context.cb_state_->commandBuffer(); |
| 2220 | const auto recorded_handle = cb_state_->commandBuffer(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2221 | const auto *report_data = sync_state_->report_data; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2222 | return sync_state_->LogError(cb_handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2223 | "%s: Hazard %s for entry %" PRIu32 ", %s, Recorded access info %s. Access info %s.", func_name, |
| 2224 | string_SyncHazard(hazard.hazard), index, report_data->FormatHandle(recorded_handle).c_str(), |
| 2225 | FormatUsage(*hazard.recorded_access).c_str(), active_context.FormatUsage(hazard).c_str()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2226 | }; |
| 2227 | for (const auto &sync_op : sync_ops_) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2228 | // we update the range to any include layout transition first use writes, |
| 2229 | // as they are stored along with the source scope (as effective barrier) when recorded |
| 2230 | tag_range.end = sync_op.tag + 1; |
| 2231 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2232 | hazard = recorded_context->DetectFirstUseHazard(tag_range, *access_context); |
| 2233 | if (hazard.hazard) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2234 | skip |= log_msg(hazard, *proxy_context, func_name, index); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2235 | } |
| 2236 | // 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] | 2237 | // Record the barrier into the proxy context. |
| 2238 | sync_op.sync_op->DoRecord(base_tag + sync_op.tag, access_context, events_context); |
| 2239 | tag_range.begin = tag_range.end; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | // and anything after the last syncop |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2243 | tag_range.end = ResourceUsageRecord::kMaxIndex; |
| 2244 | hazard = recorded_context->DetectFirstUseHazard(tag_range, *access_context); |
| 2245 | if (hazard.hazard) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2246 | skip |= log_msg(hazard, *proxy_context, func_name, index); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | return skip; |
| 2250 | } |
| 2251 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2252 | void CommandBufferAccessContext::RecordExecutedCommandBuffer(const CommandBufferAccessContext &recorded_cb_context, CMD_TYPE cmd) { |
| 2253 | auto *events_context = GetCurrentEventsContext(); |
| 2254 | auto *access_context = GetCurrentAccessContext(); |
| 2255 | const AccessContext *recorded_context = recorded_cb_context.GetCurrentAccessContext(); |
| 2256 | assert(recorded_context); |
| 2257 | |
| 2258 | // Just run through the barriers ignoring the usage from the recorded context, as Resolve will overwrite outdated state |
| 2259 | const ResourceUsageTag base_tag = GetTagLimit(); |
| 2260 | for (const auto &sync_op : recorded_cb_context.sync_ops_) { |
| 2261 | // we update the range to any include layout transition first use writes, |
| 2262 | // as they are stored along with the source scope (as effective barrier) when recorded |
| 2263 | sync_op.sync_op->DoRecord(base_tag + sync_op.tag, access_context, events_context); |
| 2264 | } |
| 2265 | |
| 2266 | ResourceUsageRange tag_range = ImportRecordedAccessLog(recorded_cb_context); |
| 2267 | assert(base_tag == tag_range.begin); // to ensure the to offset calculation agree |
| 2268 | ResolveRecordedContext(*recorded_context, tag_range.begin); |
| 2269 | } |
| 2270 | |
| 2271 | void CommandBufferAccessContext::ResolveRecordedContext(const AccessContext &recorded_context, ResourceUsageTag offset) { |
| 2272 | auto tag_offset = [offset](ResourceAccessState *access) { access->OffsetTag(offset); }; |
| 2273 | |
| 2274 | auto *access_context = GetCurrentAccessContext(); |
| 2275 | for (auto address_type : kAddressTypes) { |
| 2276 | recorded_context.ResolveAccessRange(address_type, kFullRange, tag_offset, &access_context->GetAccessStateMap(address_type), |
| 2277 | nullptr, false); |
| 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | ResourceUsageRange CommandBufferAccessContext::ImportRecordedAccessLog(const CommandBufferAccessContext &recorded_context) { |
| 2282 | // The execution references ensure lifespan for the referenced child CB's... |
| 2283 | ResourceUsageRange tag_range(GetTagLimit(), 0); |
| 2284 | const auto &rec_cb = recorded_context.cb_state_; |
| 2285 | const CMD_BUFFER_STATE *const_rec_cb_plain = rec_cb.get(); |
| 2286 | cb_execution_reference_.emplace(const_rec_cb_plain, CmdBufReference(rec_cb, recorded_context.reset_count_)); |
| 2287 | access_log_.insert(access_log_.end(), recorded_context.access_log_.cbegin(), recorded_context.access_log_.end()); |
| 2288 | tag_range.end = access_log_.size(); |
| 2289 | return tag_range; |
| 2290 | } |
| 2291 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2292 | class HazardDetectFirstUse { |
| 2293 | public: |
| 2294 | HazardDetectFirstUse(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range) |
| 2295 | : recorded_use_(recorded_use), tag_range_(tag_range) {} |
| 2296 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 2297 | return pos->second.DetectHazard(recorded_use_, tag_range_); |
| 2298 | } |
| 2299 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, ResourceUsageTag start_tag) const { |
| 2300 | return pos->second.DetectAsyncHazard(recorded_use_, tag_range_, start_tag); |
| 2301 | } |
| 2302 | |
| 2303 | private: |
| 2304 | const ResourceAccessState &recorded_use_; |
| 2305 | const ResourceUsageRange &tag_range_; |
| 2306 | }; |
| 2307 | |
| 2308 | // This is called with the *recorded* command buffers access context, with the *active* access context pass in, againsts which |
| 2309 | // hazards will be detected |
| 2310 | HazardResult AccessContext::DetectFirstUseHazard(const ResourceUsageRange &tag_range, const AccessContext &access_context) const { |
| 2311 | HazardResult hazard; |
| 2312 | for (const auto address_type : kAddressTypes) { |
| 2313 | const auto &recorded_access_map = GetAccessStateMap(address_type); |
| 2314 | for (const auto &recorded_access : recorded_access_map) { |
| 2315 | // Cull any entries not in the current tag range |
| 2316 | if (!recorded_access.second.FirstAccessInTagRange(tag_range)) continue; |
| 2317 | HazardDetectFirstUse detector(recorded_access.second, tag_range); |
| 2318 | hazard = access_context.DetectHazard(address_type, detector, recorded_access.first, DetectOptions::kDetectAll); |
| 2319 | if (hazard.hazard) break; |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | return hazard; |
| 2324 | } |
| 2325 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2326 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const CommandExecutionContext &ex_context, const CMD_BUFFER_STATE &cmd, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2327 | const char *func_name) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2328 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2329 | const auto &sync_state = ex_context.GetSyncState(); |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2330 | const auto *pipe = cmd.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2331 | if (!pipe) { |
| 2332 | return skip; |
| 2333 | } |
| 2334 | |
| 2335 | const auto &create_info = pipe->create_info.graphics; |
| 2336 | if (create_info.pRasterizationState && create_info.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2337 | return skip; |
| 2338 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2339 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2340 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2341 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2342 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2343 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2344 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2345 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2346 | if (location >= subpass.colorAttachmentCount || |
| 2347 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2348 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2349 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2350 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2351 | if (!view_gen.IsValid()) continue; |
| 2352 | HazardResult hazard = |
| 2353 | current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2354 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2355 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2356 | const VkImageView view_handle = view_gen.GetViewState()->image_view(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2357 | skip |= sync_state.LogError(view_handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2358 | "%s: Hazard %s for %s in %s, Subpass #%d, and pColorAttachments #%d. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2359 | func_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2360 | sync_state.report_data->FormatHandle(view_handle).c_str(), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2361 | sync_state.report_data->FormatHandle(cmd.commandBuffer()).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2362 | location, ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2363 | } |
| 2364 | } |
| 2365 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2366 | |
| 2367 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2368 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2369 | const uint32_t depth_stencil_attachment = |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2370 | GetSubpassDepthStencilAttachmentIndex(pipe->create_info.graphics.pDepthStencilState, subpass.pDepthStencilAttachment); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2371 | |
| 2372 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2373 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2374 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2375 | bool depth_write = false, stencil_write = false; |
| 2376 | |
| 2377 | // PHASE1 TODO: These validation should be in core_checks. |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2378 | if (!FormatIsStencilOnly(view_state.create_info.format) && create_info.pDepthStencilState->depthTestEnable && |
| 2379 | create_info.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2380 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2381 | depth_write = true; |
| 2382 | } |
| 2383 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2384 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2385 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2386 | // PHASE1 TODO: These validation should be in core_checks. |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2387 | if (!FormatIsDepthOnly(view_state.create_info.format) && create_info.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2388 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2389 | stencil_write = true; |
| 2390 | } |
| 2391 | |
| 2392 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2393 | if (depth_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2394 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2395 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2396 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2397 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2398 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2399 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2400 | "%s: Hazard %s for %s in %s, Subpass #%d, and depth part of pDepthStencilAttachment. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2401 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2402 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
| 2403 | sync_state.report_data->FormatHandle(cmd.commandBuffer()).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2404 | ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | if (stencil_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2408 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2409 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2410 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2411 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2412 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2413 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2414 | "%s: Hazard %s for %s in %s, Subpass #%d, and stencil part of pDepthStencilAttachment. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2415 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2416 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
| 2417 | sync_state.report_data->FormatHandle(cmd.commandBuffer()).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2418 | ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2419 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2420 | } |
| 2421 | } |
| 2422 | return skip; |
| 2423 | } |
| 2424 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2425 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd, const ResourceUsageTag tag) { |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2426 | const auto *pipe = cmd.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2427 | if (!pipe) { |
| 2428 | return; |
| 2429 | } |
| 2430 | |
| 2431 | const auto &create_info = pipe->create_info.graphics; |
| 2432 | if (create_info.pRasterizationState && create_info.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2433 | return; |
| 2434 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2435 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2436 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2437 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2438 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2439 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2440 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2441 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2442 | if (location >= subpass.colorAttachmentCount || |
| 2443 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2444 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2445 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2446 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2447 | current_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2448 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment, |
| 2449 | tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2450 | } |
| 2451 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2452 | |
| 2453 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2454 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2455 | const uint32_t depth_stencil_attachment = |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2456 | GetSubpassDepthStencilAttachmentIndex(create_info.pDepthStencilState, subpass.pDepthStencilAttachment); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2457 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2458 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2459 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2460 | bool depth_write = false, stencil_write = false; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2461 | const bool has_depth = 0 != (view_state.normalized_subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 2462 | 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] | 2463 | |
| 2464 | // PHASE1 TODO: These validation should be in core_checks. |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2465 | if (has_depth && !FormatIsStencilOnly(view_state.create_info.format) && create_info.pDepthStencilState->depthTestEnable && |
| 2466 | create_info.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2467 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2468 | depth_write = true; |
| 2469 | } |
| 2470 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2471 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2472 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2473 | // PHASE1 TODO: These validation should be in core_checks. |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2474 | if (has_stencil && !FormatIsDepthOnly(view_state.create_info.format) && create_info.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2475 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2476 | stencil_write = true; |
| 2477 | } |
| 2478 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2479 | if (depth_write || stencil_write) { |
| 2480 | const auto ds_gentype = view_gen.GetDepthStencilRenderAreaGenType(depth_write, stencil_write); |
| 2481 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2482 | current_context.UpdateAccessState(view_gen, ds_gentype, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2483 | SyncOrdering::kDepthStencilAttachment, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2484 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2485 | } |
| 2486 | } |
| 2487 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2488 | bool RenderPassAccessContext::ValidateNextSubpass(const CommandExecutionContext &ex_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2489 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2490 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2491 | skip |= CurrentContext().ValidateResolveOperations(ex_context, *rp_state_, render_area_, attachment_views_, func_name, |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2492 | current_subpass_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2493 | skip |= CurrentContext().ValidateStoreOperation(ex_context, *rp_state_, render_area_, current_subpass_, attachment_views_, |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2494 | func_name); |
| 2495 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2496 | const auto next_subpass = current_subpass_ + 1; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2497 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2498 | skip |= |
| 2499 | next_context.ValidateLayoutTransitions(ex_context, *rp_state_, render_area_, next_subpass, attachment_views_, func_name); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2500 | if (!skip) { |
| 2501 | // To avoid complex (and buggy) duplication of the affect of layout transitions on load operations, we'll record them |
| 2502 | // on a copy of the (empty) next context. |
| 2503 | // Note: The resource access map should be empty so hopefully this copy isn't too horrible from a perf POV. |
| 2504 | AccessContext temp_context(next_context); |
| 2505 | temp_context.RecordLayoutTransitions(*rp_state_, next_subpass, attachment_views_, kCurrentCommandTag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2506 | skip |= |
| 2507 | temp_context.ValidateLoadOperation(ex_context, *rp_state_, render_area_, next_subpass, attachment_views_, func_name); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2508 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2509 | return skip; |
| 2510 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2511 | bool RenderPassAccessContext::ValidateEndRenderPass(const CommandExecutionContext &ex_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2512 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2513 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2514 | skip |= CurrentContext().ValidateResolveOperations(ex_context, *rp_state_, render_area_, attachment_views_, func_name, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2515 | current_subpass_); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2516 | skip |= CurrentContext().ValidateStoreOperation(ex_context, *rp_state_, render_area_, current_subpass_, |
| 2517 | |
| 2518 | attachment_views_, func_name); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2519 | skip |= ValidateFinalSubpassLayoutTransitions(ex_context, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2520 | return skip; |
| 2521 | } |
| 2522 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2523 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy() const { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2524 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, attachment_views_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2525 | } |
| 2526 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2527 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const CommandExecutionContext &ex_context, |
| 2528 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2529 | bool skip = false; |
| 2530 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2531 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2532 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2533 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2534 | // to apply and only copy then, if this proves a hot spot. |
| 2535 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2536 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2537 | // Validate the "finalLayout" transitions to external |
| 2538 | // Get them from where there we're hidding in the extra entry. |
| 2539 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2540 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2541 | const auto &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2542 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
| 2543 | assert(trackback.context); // Transitions are given implicit transitions if the StateTracker is working correctly |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2544 | auto *context = trackback.context; |
| 2545 | |
| 2546 | if (transition.prev_pass == current_subpass_) { |
| 2547 | if (!proxy_for_current) { |
| 2548 | // 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] | 2549 | proxy_for_current.reset(CreateStoreResolveProxy()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2550 | } |
| 2551 | context = proxy_for_current.get(); |
| 2552 | } |
| 2553 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2554 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2555 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2556 | auto hazard = context->DetectImageBarrierHazard(view_gen, merged_barrier, AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2557 | if (hazard.hazard) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2558 | skip |= ex_context.GetSyncState().LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2559 | rp_state_->renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2560 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
| 2561 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 2562 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2563 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2564 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2565 | } |
| 2566 | } |
| 2567 | return skip; |
| 2568 | } |
| 2569 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2570 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2571 | // Add layout transitions... |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2572 | subpass_contexts_[current_subpass_].RecordLayoutTransitions(*rp_state_, current_subpass_, attachment_views_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2573 | } |
| 2574 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2575 | void RenderPassAccessContext::RecordLoadOperations(const ResourceUsageTag tag) { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2576 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2577 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2578 | |
| 2579 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2580 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2581 | const AttachmentViewGen &view_gen = attachment_views_[i]; |
| 2582 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2583 | |
| 2584 | const auto &ci = attachment_ci[i]; |
| 2585 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2586 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2587 | const bool is_color = !(has_depth || has_stencil); |
| 2588 | |
| 2589 | if (is_color) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2590 | const SyncStageAccessIndex load_op = ColorLoadUsage(ci.loadOp); |
| 2591 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2592 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, load_op, |
| 2593 | SyncOrdering::kColorAttachment, tag); |
| 2594 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2595 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2596 | if (has_depth) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2597 | const SyncStageAccessIndex load_op = DepthStencilLoadUsage(ci.loadOp); |
| 2598 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2599 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_op, |
| 2600 | SyncOrdering::kDepthStencilAttachment, tag); |
| 2601 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2602 | } |
| 2603 | if (has_stencil) { |
John Zulauf | 5726140 | 2021-08-13 11:32:06 -0600 | [diff] [blame] | 2604 | const SyncStageAccessIndex load_op = DepthStencilLoadUsage(ci.stencilLoadOp); |
| 2605 | if (load_op != SYNC_ACCESS_INDEX_NONE) { |
| 2606 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, load_op, |
| 2607 | SyncOrdering::kDepthStencilAttachment, tag); |
| 2608 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | } |
| 2612 | } |
| 2613 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2614 | AttachmentViewGenVector RenderPassAccessContext::CreateAttachmentViewGen( |
| 2615 | const VkRect2D &render_area, const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
| 2616 | AttachmentViewGenVector view_gens; |
| 2617 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2618 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2619 | view_gens.reserve(attachment_views.size()); |
| 2620 | for (const auto *view : attachment_views) { |
| 2621 | view_gens.emplace_back(view, offset, extent); |
| 2622 | } |
| 2623 | return view_gens; |
| 2624 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2625 | RenderPassAccessContext::RenderPassAccessContext(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2626 | VkQueueFlags queue_flags, |
| 2627 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2628 | const AccessContext *external_context) |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2629 | : 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] | 2630 | // 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] | 2631 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2632 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2633 | subpass_contexts_.emplace_back(pass, queue_flags, rp_state_->subpass_dependencies, subpass_contexts_, external_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2634 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2635 | attachment_views_ = CreateAttachmentViewGen(render_area, attachment_views); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2636 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2637 | void RenderPassAccessContext::RecordBeginRenderPass(const ResourceUsageTag tag) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2638 | assert(0 == current_subpass_); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2639 | subpass_contexts_[current_subpass_].SetStartTag(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2640 | RecordLayoutTransitions(tag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2641 | RecordLoadOperations(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2642 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2643 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2644 | void RenderPassAccessContext::RecordNextSubpass(const ResourceUsageTag prev_subpass_tag, const ResourceUsageTag next_subpass_tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2645 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2646 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, prev_subpass_tag); |
| 2647 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, prev_subpass_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2648 | |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 2649 | // Move to the next sub-command for the new subpass. The resolve and store are logically part of the previous |
| 2650 | // 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] | 2651 | current_subpass_++; |
| 2652 | assert(current_subpass_ < subpass_contexts_.size()); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2653 | subpass_contexts_[current_subpass_].SetStartTag(next_subpass_tag); |
| 2654 | RecordLayoutTransitions(next_subpass_tag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2655 | RecordLoadOperations(next_subpass_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2656 | } |
| 2657 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2658 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const ResourceUsageTag tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2659 | // Add the resolve and store accesses |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2660 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, tag); |
| 2661 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2662 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2663 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2664 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2665 | |
| 2666 | // Add the "finalLayout" transitions to external |
| 2667 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2668 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2669 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2670 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2671 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2672 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2673 | const AttachmentViewGen &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2674 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | aa97d8b | 2020-07-14 10:58:13 -0600 | [diff] [blame] | 2675 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2676 | ApplyBarrierOpsFunctor<PipelineBarrierOp> barrier_action(true /* resolve */, last_trackback.barriers.size(), tag); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2677 | for (const auto &barrier : last_trackback.barriers) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2678 | barrier_action.EmplaceBack(PipelineBarrierOp(barrier, true)); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2679 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2680 | external_context->ApplyUpdateAction(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2681 | } |
| 2682 | } |
| 2683 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2684 | SyncExecScope SyncExecScope::MakeSrc(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2685 | SyncExecScope result; |
| 2686 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2687 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2688 | result.exec_scope = sync_utils::WithEarlierPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2689 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2690 | return result; |
| 2691 | } |
| 2692 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2693 | SyncExecScope SyncExecScope::MakeDst(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2694 | SyncExecScope result; |
| 2695 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2696 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2697 | result.exec_scope = sync_utils::WithLaterPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2698 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2699 | return result; |
| 2700 | } |
| 2701 | |
| 2702 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2703 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2704 | src_access_scope = 0; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2705 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2706 | dst_access_scope = 0; |
| 2707 | } |
| 2708 | |
| 2709 | template <typename Barrier> |
| 2710 | SyncBarrier::SyncBarrier(const Barrier &barrier, const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2711 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2712 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2713 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2714 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
| 2715 | } |
| 2716 | |
| 2717 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &subpass) { |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2718 | const auto barrier = lvl_find_in_chain<VkMemoryBarrier2KHR>(subpass.pNext); |
| 2719 | if (barrier) { |
| 2720 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier->srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2721 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2722 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier->srcAccessMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2723 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2724 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier->dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2725 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2726 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier->dstAccessMask); |
| 2727 | |
| 2728 | } else { |
| 2729 | auto src = SyncExecScope::MakeSrc(queue_flags, subpass.srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2730 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2731 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, subpass.srcAccessMask); |
| 2732 | |
| 2733 | auto dst = SyncExecScope::MakeDst(queue_flags, subpass.dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2734 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2735 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, subpass.dstAccessMask); |
| 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | template <typename Barrier> |
| 2740 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const Barrier &barrier) { |
| 2741 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 2742 | src_exec_scope = src.exec_scope; |
| 2743 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
| 2744 | |
| 2745 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2746 | dst_exec_scope = dst.exec_scope; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2747 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2748 | } |
| 2749 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2750 | // Apply a list of barriers, without resolving pending state, useful for subpass layout transitions |
| 2751 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
| 2752 | for (const auto &barrier : barriers) { |
| 2753 | ApplyBarrier(barrier, layout_transition); |
| 2754 | } |
| 2755 | } |
| 2756 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2757 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2758 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2759 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2760 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, const ResourceUsageTag tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2761 | 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] | 2762 | assert(pending_write_barriers.none()); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2763 | assert(!pending_write_dep_chain); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2764 | for (const auto &barrier : barriers) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2765 | ApplyBarrier(barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2766 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2767 | ApplyPendingBarriers(tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2768 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2769 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2770 | HazardResult hazard; |
| 2771 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2772 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2773 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2774 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2775 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2776 | } |
| 2777 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2778 | // Write operation: |
| 2779 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2780 | // If reads exists -- test only against them because either: |
| 2781 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2782 | // * 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 |
| 2783 | // the current write happens after the reads, so just test the write against the reades |
| 2784 | // Otherwise test against last_write |
| 2785 | // |
| 2786 | // Look for casus belli for WAR |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2787 | if (last_reads.size()) { |
| 2788 | for (const auto &read_access : last_reads) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2789 | if (IsReadHazard(usage_stage, read_access)) { |
| 2790 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2791 | break; |
| 2792 | } |
| 2793 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2794 | } else if (last_write.any() && IsWriteHazard(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2795 | // Write-After-Write check -- if we have a previous write to test against |
| 2796 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2797 | } |
| 2798 | } |
| 2799 | return hazard; |
| 2800 | } |
| 2801 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2802 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrdering ordering_rule) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2803 | const auto &ordering = GetOrderingRules(ordering_rule); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2804 | return DetectHazard(usage_index, ordering); |
| 2805 | } |
| 2806 | |
| 2807 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const OrderingBarrier &ordering) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2808 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 2809 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2810 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2811 | const auto usage_stage = PipelineStageBit(usage_index); |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2812 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
| 2813 | const bool last_write_is_ordered = (last_write & ordering.access_scope).any(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2814 | if (IsRead(usage_bit)) { |
| 2815 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 2816 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 2817 | if (is_raw_hazard) { |
| 2818 | // NOTE: we know last_write is non-zero |
| 2819 | // See if the ordering rules save us from the simple RAW check above |
| 2820 | // First check to see if the current usage is covered by the ordering rules |
| 2821 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 2822 | const bool usage_is_ordered = |
| 2823 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 2824 | if (usage_is_ordered) { |
| 2825 | // Now see of the most recent write (or a subsequent read) are ordered |
| 2826 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(ordering)); |
| 2827 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2828 | } |
| 2829 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2830 | if (is_raw_hazard) { |
| 2831 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 2832 | } |
John Zulauf | 5c628d0 | 2021-05-04 15:46:36 -0600 | [diff] [blame] | 2833 | } else if (usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION) { |
| 2834 | // For Image layout transitions, the barrier represents the first synchronization/access scope of the layout transition |
| 2835 | return DetectBarrierHazard(usage_index, ordering.exec_scope, ordering.access_scope); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2836 | } else { |
| 2837 | // Only check for WAW if there are no reads since last_write |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2838 | bool usage_write_is_ordered = (usage_bit & ordering.access_scope).any(); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2839 | if (last_reads.size()) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2840 | // Look for any WAR hazards outside the ordered set of stages |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2841 | VkPipelineStageFlags2KHR ordered_stages = 0; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2842 | if (usage_write_is_ordered) { |
| 2843 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
| 2844 | ordered_stages = GetOrderedStages(ordering); |
| 2845 | } |
| 2846 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 2847 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2848 | for (const auto &read_access : last_reads) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2849 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 2850 | if (IsReadHazard(usage_stage, read_access)) { |
| 2851 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2852 | break; |
| 2853 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2854 | } |
| 2855 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2856 | } else if (!(last_write_is_ordered && usage_write_is_ordered)) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2857 | if (last_write.any() && IsWriteHazard(usage_bit)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2858 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2859 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2860 | } |
| 2861 | } |
| 2862 | return hazard; |
| 2863 | } |
| 2864 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2865 | HazardResult ResourceAccessState::DetectHazard(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range) const { |
| 2866 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2867 | using Size = FirstAccesses::size_type; |
| 2868 | const auto &recorded_accesses = recorded_use.first_accesses_; |
| 2869 | Size count = recorded_accesses.size(); |
| 2870 | if (count) { |
| 2871 | const auto &last_access = recorded_accesses.back(); |
| 2872 | bool do_write_last = IsWrite(last_access.usage_index); |
| 2873 | if (do_write_last) --count; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2874 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2875 | for (Size i = 0; i < count; ++count) { |
| 2876 | const auto &first = recorded_accesses[i]; |
| 2877 | // Skip and quit logic |
| 2878 | if (first.tag < tag_range.begin) continue; |
| 2879 | if (first.tag >= tag_range.end) { |
| 2880 | do_write_last = false; // ignore last since we know it can't be in tag_range |
| 2881 | break; |
| 2882 | } |
| 2883 | |
| 2884 | hazard = DetectHazard(first.usage_index, first.ordering_rule); |
| 2885 | if (hazard.hazard) { |
| 2886 | hazard.AddRecordedAccess(first); |
| 2887 | break; |
| 2888 | } |
| 2889 | } |
| 2890 | |
| 2891 | if (do_write_last && tag_range.includes(last_access.tag)) { |
| 2892 | // Writes are a bit special... both for the "most recent" access logic, and layout transition specific logic |
| 2893 | OrderingBarrier barrier = GetOrderingRules(last_access.ordering_rule); |
| 2894 | if (last_access.usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION) { |
| 2895 | // Or in the layout first access scope as a barrier... IFF the usage is an ILT |
| 2896 | // this was saved off in the "apply barriers" logic to simplify ILT access checks as they straddle |
| 2897 | // the barrier that applies them |
| 2898 | barrier |= recorded_use.first_write_layout_ordering_; |
| 2899 | } |
| 2900 | // Any read stages present in the recorded context (this) are most recent to the write, and thus mask those stages in |
| 2901 | // the active context |
| 2902 | if (recorded_use.first_read_stages_) { |
| 2903 | // we need to ignore the first use read stage in the active context (so we add them to the ordering rule), |
| 2904 | // reads in the active context are not "most recent" as all recorded context operations are *after* them |
| 2905 | // This supresses only RAW checks for stages present in the recorded context, but not those only present in the |
| 2906 | // active context. |
| 2907 | barrier.exec_scope |= recorded_use.first_read_stages_; |
| 2908 | // if there are any first use reads, we suppress WAW by injecting the active context write in the ordering rule |
| 2909 | barrier.access_scope |= FlagBit(last_access.usage_index); |
| 2910 | } |
| 2911 | hazard = DetectHazard(last_access.usage_index, barrier); |
| 2912 | if (hazard.hazard) { |
| 2913 | hazard.AddRecordedAccess(last_access); |
| 2914 | } |
| 2915 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2916 | } |
| 2917 | return hazard; |
| 2918 | } |
| 2919 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2920 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2921 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index, const ResourceUsageTag start_tag) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2922 | HazardResult hazard; |
| 2923 | auto usage = FlagBit(usage_index); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2924 | // Async checks need to not go back further than the start of the subpass, as we only want to find hazards between the async |
| 2925 | // subpasses. Anything older than that should have been checked at the start of each subpass, taking into account all of |
| 2926 | // the raster ordering rules. |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2927 | if (IsRead(usage)) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2928 | if (last_write.any() && (write_tag >= start_tag)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2929 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2930 | } |
| 2931 | } else { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2932 | if (last_write.any() && (write_tag >= start_tag)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2933 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2934 | } else if (last_reads.size() > 0) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2935 | // 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] | 2936 | for (const auto &read_access : last_reads) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2937 | if (read_access.tag >= start_tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2938 | 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] | 2939 | break; |
| 2940 | } |
| 2941 | } |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2942 | } |
| 2943 | } |
| 2944 | return hazard; |
| 2945 | } |
| 2946 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2947 | HazardResult ResourceAccessState::DetectAsyncHazard(const ResourceAccessState &recorded_use, const ResourceUsageRange &tag_range, |
| 2948 | ResourceUsageTag start_tag) const { |
| 2949 | HazardResult hazard; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2950 | for (const auto &first : recorded_use.first_accesses_) { |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2951 | // Skip and quit logic |
| 2952 | if (first.tag < tag_range.begin) continue; |
| 2953 | if (first.tag >= tag_range.end) break; |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2954 | |
| 2955 | hazard = DetectAsyncHazard(first.usage_index, start_tag); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 2956 | if (hazard.hazard) { |
| 2957 | hazard.AddRecordedAccess(first); |
| 2958 | break; |
| 2959 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 2960 | } |
| 2961 | return hazard; |
| 2962 | } |
| 2963 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2964 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2965 | const SyncStageAccessFlags &src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2966 | // Only supporting image layout transitions for now |
| 2967 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2968 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2969 | // only test for WAW if there no intervening read operations. |
| 2970 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2971 | if (last_reads.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2972 | // Look at the reads if any |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2973 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2974 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2975 | 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] | 2976 | break; |
| 2977 | } |
| 2978 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2979 | } else if (last_write.any() && IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2980 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2981 | } |
| 2982 | |
| 2983 | return hazard; |
| 2984 | } |
| 2985 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2986 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2987 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2988 | const ResourceUsageTag event_tag) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2989 | // Only supporting image layout transitions for now |
| 2990 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2991 | HazardResult hazard; |
| 2992 | // only test for WAW if there no intervening read operations. |
| 2993 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 2994 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2995 | if (last_reads.size()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2996 | // Look at the reads if any... if reads exist, they are either the resaon the access is in the event |
| 2997 | // first scope, or they are a hazard. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2998 | for (const auto &read_access : last_reads) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 2999 | if (read_access.tag < event_tag) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3000 | // The read is in the events first synchronization scope, so we use a barrier hazard check |
| 3001 | // If the read stage is not in the src sync scope |
| 3002 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 3003 | // then the barrier access is unsafe (R/W after R) |
| 3004 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
| 3005 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3006 | break; |
| 3007 | } |
| 3008 | } else { |
| 3009 | // The read not in the event first sync scope and so is a hazard vs. the layout transition |
| 3010 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 3011 | } |
| 3012 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3013 | } else if (last_write.any()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3014 | // 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] | 3015 | if (write_tag < event_tag) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3016 | // The write is in the first sync scope of the event (sync their aren't any reads to be the reason) |
| 3017 | // So do a normal barrier hazard check |
| 3018 | if (IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 3019 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3020 | } |
| 3021 | } else { |
| 3022 | // 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] | 3023 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 3024 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3025 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3026 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3027 | return hazard; |
| 3028 | } |
| 3029 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3030 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 3031 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 3032 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 3033 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3034 | if (write_tag < other.write_tag) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3035 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 3036 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3037 | *this = other; |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3038 | } else if (other.write_tag == write_tag) { |
| 3039 | // 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] | 3040 | // dependency chaining logic or any stage expansion) |
| 3041 | write_barriers |= other.write_barriers; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3042 | pending_write_barriers |= other.pending_write_barriers; |
| 3043 | pending_layout_transition |= other.pending_layout_transition; |
| 3044 | pending_write_dep_chain |= other.pending_write_dep_chain; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3045 | pending_layout_ordering_ |= other.pending_layout_ordering_; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3046 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 3047 | // Merge the read states |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3048 | const auto pre_merge_count = last_reads.size(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3049 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3050 | 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] | 3051 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3052 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3053 | // 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] | 3054 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 3055 | // but we should wait on profiling data for that. |
| 3056 | 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] | 3057 | auto &my_read = last_reads[my_read_index]; |
| 3058 | if (other_read.stage == my_read.stage) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3059 | if (my_read.tag < other_read.tag) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3060 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3061 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3062 | my_read.tag = other_read.tag; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3063 | my_read.pending_dep_chain = other_read.pending_dep_chain; |
| 3064 | // TODO: Phase 2 -- review the state merge logic to avoid false positive from overwriting the barriers |
| 3065 | // May require tracking more than one access per stage. |
| 3066 | my_read.barriers = other_read.barriers; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3067 | if (my_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3068 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 3069 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3070 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3071 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3072 | } else if (other_read.tag == my_read.tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3073 | // The read tags match so merge the barriers |
| 3074 | my_read.barriers |= other_read.barriers; |
| 3075 | my_read.pending_dep_chain |= other_read.pending_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3076 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 3077 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3078 | break; |
| 3079 | } |
| 3080 | } |
| 3081 | } else { |
| 3082 | // The other read stage doesn't exist in this, so add it. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3083 | last_reads.emplace_back(other_read); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3084 | last_read_stages |= other_read.stage; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3085 | if (other_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3086 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3087 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3088 | } |
| 3089 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 3090 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3091 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 3092 | // ignore it. |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3093 | |
| 3094 | // Merge first access information by making a copy of this first_access and reconstructing with a shuffle |
| 3095 | // of the copy and other into this using the update first logic. |
| 3096 | // NOTE: All sorts of additional cleverness could be put into short circuts. (for example back is write and is before front |
| 3097 | // of the other first_accesses... ) |
| 3098 | if (!(first_accesses_ == other.first_accesses_) && !other.first_accesses_.empty()) { |
| 3099 | FirstAccesses firsts(std::move(first_accesses_)); |
| 3100 | first_accesses_.clear(); |
| 3101 | first_read_stages_ = 0U; |
| 3102 | auto a = firsts.begin(); |
| 3103 | auto a_end = firsts.end(); |
| 3104 | for (auto &b : other.first_accesses_) { |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3105 | // TODO: Determine whether some tag offset will be needed for PHASE II |
| 3106 | while ((a != a_end) && (a->tag < b.tag)) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3107 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3108 | ++a; |
| 3109 | } |
| 3110 | UpdateFirst(b.tag, b.usage_index, b.ordering_rule); |
| 3111 | } |
| 3112 | for (; a != a_end; ++a) { |
| 3113 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3114 | } |
| 3115 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3116 | } |
| 3117 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3118 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, SyncOrdering ordering_rule, const ResourceUsageTag tag) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3119 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 3120 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3121 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3122 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 3123 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 3124 | const auto usage_stage = PipelineStageBit(usage_index); |
| 3125 | if (usage_stage & last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3126 | for (auto &read_access : last_reads) { |
| 3127 | if (read_access.stage == usage_stage) { |
| 3128 | read_access.Set(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3129 | break; |
| 3130 | } |
| 3131 | } |
| 3132 | } else { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3133 | last_reads.emplace_back(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3134 | last_read_stages |= usage_stage; |
| 3135 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3136 | |
| 3137 | // 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] | 3138 | if (usage_stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3139 | // TODO Revisit re: multiple reads for a given stage |
| 3140 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3141 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3142 | } else { |
| 3143 | // Assume write |
| 3144 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3145 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3146 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3147 | UpdateFirst(tag, usage_index, ordering_rule); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3148 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3149 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3150 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 3151 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 3152 | // We can overwrite them as *this* write is now after them. |
| 3153 | // |
| 3154 | // 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] | 3155 | void ResourceAccessState::SetWrite(const SyncStageAccessFlags &usage_bit, const ResourceUsageTag tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3156 | last_reads.clear(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3157 | last_read_stages = 0; |
| 3158 | read_execution_barriers = 0; |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3159 | input_attachment_read = false; // Denotes no outstanding input attachment read after the last write. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3160 | |
| 3161 | write_barriers = 0; |
| 3162 | write_dependency_chain = 0; |
| 3163 | write_tag = tag; |
| 3164 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3165 | } |
| 3166 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3167 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 3168 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 3169 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 3170 | // replace the current write barriers or add to them, so accumulate to pending as well. |
| 3171 | void ResourceAccessState::ApplyBarrier(const SyncBarrier &barrier, bool layout_transition) { |
| 3172 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 3173 | // applying the memory barriers |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 3174 | // NOTE: We update the write barrier if the write is in the first access scope or if there is a layout |
| 3175 | // transistion, under the theory of "most recent access". If the read/write *isn't* safe |
| 3176 | // vs. this layout transition DetectBarrierHazard should report it. We treat the layout |
| 3177 | // transistion *as* a write and in scope with the barrier (it's before visibility). |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3178 | if (layout_transition || WriteInSourceScopeOrChain(barrier.src_exec_scope.exec_scope, barrier.src_access_scope)) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3179 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3180 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3181 | if (layout_transition) { |
| 3182 | pending_layout_ordering_ |= OrderingBarrier(barrier.src_exec_scope.exec_scope, barrier.src_access_scope); |
| 3183 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3184 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3185 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 3186 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3187 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3188 | if (!pending_layout_transition) { |
| 3189 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 3190 | // don't need to be tracked as we're just going to zero them. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3191 | for (auto &read_access : last_reads) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3192 | // The | implements the "dependency chain" logic for this access, as the barriers field stores the second sync scope |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3193 | if (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers)) { |
| 3194 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3195 | } |
| 3196 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3197 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3198 | } |
| 3199 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3200 | // Apply the tag scoped memory barrier without updating the existing barriers. The execution barrier |
| 3201 | // changes the "chaining" state, but to keep barriers independent. See discussion above. |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3202 | void ResourceAccessState::ApplyBarrier(const ResourceUsageTag scope_tag, const SyncBarrier &barrier, bool layout_transition) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3203 | // The scope logic for events is, if we're here, the resource usage was flagged as "in the first execution scope" at |
| 3204 | // the time of the SetEvent, thus all we need check is whether the access is the same one (i.e. before the scope tag |
| 3205 | // in order to know if it's in the excecution scope |
| 3206 | // Notice that the layout transition sets the pending barriers *regardless*, as any lack of src_access_scope to |
| 3207 | // guard against the layout transition should be reported in the detect barrier hazard phase, and we only report |
| 3208 | // errors w.r.t. "most recent" accesses. |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3209 | if (layout_transition || ((write_tag < scope_tag) && (barrier.src_access_scope & last_write).any())) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3210 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3211 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3212 | if (layout_transition) { |
| 3213 | pending_layout_ordering_ |= OrderingBarrier(barrier.src_exec_scope.exec_scope, barrier.src_access_scope); |
| 3214 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3215 | } |
| 3216 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 3217 | pending_layout_transition |= layout_transition; |
| 3218 | |
| 3219 | if (!pending_layout_transition) { |
| 3220 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 3221 | // don't need to be tracked as we're just going to zero them. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3222 | for (auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3223 | // If this read is the same one we included in the set event and in scope, then apply the execution barrier... |
| 3224 | // NOTE: That's not really correct... this read stage might *not* have been included in the setevent, and the barriers |
| 3225 | // representing the chain might have changed since then (that would be an odd usage), so as a first approximation |
| 3226 | // we'll assume the barriers *haven't* been changed since (if the tag hasn't), and while this could be a false |
| 3227 | // positive in the case of Set; SomeBarrier; Wait; we'll live with it until we can add more state to the first scope |
| 3228 | // capture (the specific write and read stages that *were* in scope at the moment of SetEvents. |
| 3229 | // TODO: eliminate the false positive by including write/read-stages "in scope" information in SetEvents first_scope |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3230 | if ((read_access.tag < scope_tag) && (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers))) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3231 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3232 | } |
| 3233 | } |
| 3234 | } |
| 3235 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3236 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag tag) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3237 | if (pending_layout_transition) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3238 | // 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] | 3239 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3240 | UpdateFirst(tag, SYNC_IMAGE_LAYOUT_TRANSITION, SyncOrdering::kNonAttachment); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3241 | TouchupFirstForLayoutTransition(tag, pending_layout_ordering_); |
| 3242 | pending_layout_ordering_ = OrderingBarrier(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3243 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3244 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3245 | |
| 3246 | // Apply the accumulate execution barriers (and thus update chaining information) |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3247 | // 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] | 3248 | for (auto &read_access : last_reads) { |
| 3249 | read_access.barriers |= read_access.pending_dep_chain; |
| 3250 | read_execution_barriers |= read_access.barriers; |
| 3251 | read_access.pending_dep_chain = 0; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 3255 | write_dependency_chain |= pending_write_dep_chain; |
| 3256 | write_barriers |= pending_write_barriers; |
| 3257 | pending_write_dep_chain = 0; |
| 3258 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3259 | } |
| 3260 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 3261 | bool ResourceAccessState::FirstAccessInTagRange(const ResourceUsageRange &tag_range) const { |
| 3262 | if (!first_accesses_.size()) return false; |
| 3263 | const ResourceUsageRange first_access_range = {first_accesses_.front().tag, first_accesses_.back().tag + 1}; |
| 3264 | return tag_range.intersects(first_access_range); |
| 3265 | } |
| 3266 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3267 | // 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] | 3268 | VkPipelineStageFlags2KHR ResourceAccessState::GetReadBarriers(const SyncStageAccessFlags &usage_bit) const { |
| 3269 | VkPipelineStageFlags2KHR barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3270 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3271 | for (const auto &read_access : last_reads) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3272 | if ((read_access.access & usage_bit).any()) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3273 | barriers = read_access.barriers; |
| 3274 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3275 | } |
| 3276 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3277 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3278 | return barriers; |
| 3279 | } |
| 3280 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3281 | inline bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlags2KHR usage_stage, const SyncStageAccessFlags &usage) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3282 | assert(IsRead(usage)); |
| 3283 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 3284 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 3285 | // any reads that happen after. |
| 3286 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 3287 | // 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] | 3288 | return last_write.any() && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3289 | } |
| 3290 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3291 | VkPipelineStageFlags2KHR ResourceAccessState::GetOrderedStages(const OrderingBarrier &ordering) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3292 | // 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] | 3293 | VkPipelineStageFlags2KHR ordered_stages = last_read_stages & ordering.exec_scope; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3294 | // Special input attachment handling as always (not encoded in exec_scop) |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3295 | 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] | 3296 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3297 | // 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] | 3298 | ordered_stages |= VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | return ordered_stages; |
| 3302 | } |
| 3303 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 3304 | void ResourceAccessState::UpdateFirst(const ResourceUsageTag tag, SyncStageAccessIndex usage_index, SyncOrdering ordering_rule) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3305 | // Only record until we record a write. |
| 3306 | if (first_accesses_.empty() || IsRead(first_accesses_.back().usage_index)) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3307 | const VkPipelineStageFlags2KHR usage_stage = IsRead(usage_index) ? PipelineStageBit(usage_index) : 0U; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3308 | if (0 == (usage_stage & first_read_stages_)) { |
| 3309 | // 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] | 3310 | // We always need to know what stages were found prior to write |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3311 | first_read_stages_ |= usage_stage; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3312 | if (0 == (read_execution_barriers & usage_stage)) { |
| 3313 | // If this stage isn't masked then we add it (since writes map to usage_stage 0, this also records writes) |
| 3314 | first_accesses_.emplace_back(tag, usage_index, ordering_rule); |
| 3315 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3316 | } |
| 3317 | } |
| 3318 | } |
| 3319 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3320 | void ResourceAccessState::TouchupFirstForLayoutTransition(ResourceUsageTag tag, const OrderingBarrier &layout_ordering) { |
| 3321 | // Only call this after recording an image layout transition |
| 3322 | assert(first_accesses_.size()); |
| 3323 | if (first_accesses_.back().tag == tag) { |
| 3324 | // If this layout transition is the the first write, add the additional ordering rules that guard the ILT |
| 3325 | assert(first_accesses_.back().usage_index = SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 3326 | first_write_layout_ordering_ = layout_ordering; |
| 3327 | } |
| 3328 | } |
| 3329 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3330 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3331 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 3332 | if (access_context) { |
| 3333 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3334 | } |
| 3335 | } |
| 3336 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3337 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 3338 | auto access_found = cb_access_state.find(command_buffer); |
| 3339 | if (access_found != cb_access_state.end()) { |
| 3340 | access_found->second->Reset(); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 3341 | access_found->second->MarkDestroyed(); |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3342 | cb_access_state.erase(access_found); |
| 3343 | } |
| 3344 | } |
| 3345 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3346 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3347 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 3348 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3349 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3350 | assert(cb_context); |
| 3351 | if (!cb_context) return skip; |
| 3352 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3353 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3354 | // If we have no previous accesses, we have no hazards |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3355 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3356 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3357 | |
| 3358 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3359 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3360 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3361 | 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] | 3362 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3363 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3364 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3365 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3366 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3367 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3368 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3369 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3370 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3371 | 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] | 3372 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3373 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3374 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3375 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3376 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3377 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3378 | } |
| 3379 | } |
| 3380 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3381 | } |
| 3382 | return skip; |
| 3383 | } |
| 3384 | |
| 3385 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3386 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3387 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3388 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3389 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3390 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3391 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3392 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3393 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3394 | |
| 3395 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3396 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3397 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3398 | 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] | 3399 | 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] | 3400 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3401 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3402 | 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] | 3403 | 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] | 3404 | } |
| 3405 | } |
| 3406 | } |
| 3407 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3408 | void SyncValidator::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 3409 | // Clear out events from the command buffer contexts |
| 3410 | for (auto &cb_context : cb_access_state) { |
| 3411 | cb_context.second->RecordDestroyEvent(event); |
| 3412 | } |
| 3413 | } |
| 3414 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3415 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3416 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 3417 | bool skip = false; |
| 3418 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3419 | assert(cb_context); |
| 3420 | if (!cb_context) return skip; |
| 3421 | const auto *context = cb_context->GetCurrentAccessContext(); |
| 3422 | |
| 3423 | // If we have no previous accesses, we have no hazards |
| 3424 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3425 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3426 | |
| 3427 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3428 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3429 | if (src_buffer) { |
| 3430 | 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] | 3431 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3432 | if (hazard.hazard) { |
| 3433 | // TODO -- add tag information to log msg when useful. |
| 3434 | skip |= LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3435 | "vkCmdCopyBuffer2KHR(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3436 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3437 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3438 | } |
| 3439 | } |
| 3440 | if (dst_buffer && !skip) { |
| 3441 | 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] | 3442 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3443 | if (hazard.hazard) { |
| 3444 | skip |= LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3445 | "vkCmdCopyBuffer2KHR(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3446 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3447 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3448 | } |
| 3449 | } |
| 3450 | if (skip) break; |
| 3451 | } |
| 3452 | return skip; |
| 3453 | } |
| 3454 | |
| 3455 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 3456 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3457 | assert(cb_context); |
| 3458 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER2KHR); |
| 3459 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3460 | |
| 3461 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3462 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3463 | |
| 3464 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3465 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3466 | if (src_buffer) { |
| 3467 | 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] | 3468 | 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] | 3469 | } |
| 3470 | if (dst_buffer) { |
| 3471 | 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] | 3472 | 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] | 3473 | } |
| 3474 | } |
| 3475 | } |
| 3476 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3477 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3478 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3479 | const VkImageCopy *pRegions) const { |
| 3480 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3481 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3482 | assert(cb_access_context); |
| 3483 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3484 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3485 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3486 | assert(context); |
| 3487 | if (!context) return skip; |
| 3488 | |
| 3489 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3490 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3491 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3492 | const auto ©_region = pRegions[region]; |
| 3493 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3494 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.srcSubresource, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3495 | copy_region.srcOffset, copy_region.extent); |
| 3496 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3497 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3498 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3499 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3500 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3501 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3505 | VkExtent3D dst_copy_extent = |
| 3506 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3507 | auto hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.dstSubresource, |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3508 | copy_region.dstOffset, dst_copy_extent); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3509 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3510 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3511 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3512 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3513 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3514 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 3515 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3516 | } |
| 3517 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3518 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3519 | return skip; |
| 3520 | } |
| 3521 | |
| 3522 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3523 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3524 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3525 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3526 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3527 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3528 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3529 | assert(context); |
| 3530 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3531 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3532 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3533 | |
| 3534 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3535 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3536 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3537 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3538 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3539 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3540 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3541 | VkExtent3D dst_copy_extent = |
| 3542 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3543 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3544 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3545 | } |
| 3546 | } |
| 3547 | } |
| 3548 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3549 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 3550 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 3551 | bool skip = false; |
| 3552 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3553 | assert(cb_access_context); |
| 3554 | if (!cb_access_context) return skip; |
| 3555 | |
| 3556 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3557 | assert(context); |
| 3558 | if (!context) return skip; |
| 3559 | |
| 3560 | const auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3561 | const auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3562 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3563 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3564 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3565 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.srcSubresource, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3566 | copy_region.srcOffset, copy_region.extent); |
| 3567 | if (hazard.hazard) { |
| 3568 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 3569 | "vkCmdCopyImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 3570 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3571 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | if (dst_image) { |
| 3576 | VkExtent3D dst_copy_extent = |
| 3577 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3578 | auto hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.dstSubresource, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3579 | copy_region.dstOffset, dst_copy_extent); |
| 3580 | if (hazard.hazard) { |
| 3581 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 3582 | "vkCmdCopyImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 3583 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3584 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3585 | } |
| 3586 | if (skip) break; |
| 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | return skip; |
| 3591 | } |
| 3592 | |
| 3593 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 3594 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3595 | assert(cb_access_context); |
| 3596 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE2KHR); |
| 3597 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3598 | assert(context); |
| 3599 | |
| 3600 | auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3601 | auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3602 | |
| 3603 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3604 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3605 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3606 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3607 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3608 | } |
| 3609 | if (dst_image) { |
| 3610 | VkExtent3D dst_copy_extent = |
| 3611 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3612 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3613 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3614 | } |
| 3615 | } |
| 3616 | } |
| 3617 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3618 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3619 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3620 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3621 | uint32_t bufferMemoryBarrierCount, |
| 3622 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3623 | uint32_t imageMemoryBarrierCount, |
| 3624 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 3625 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3626 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3627 | assert(cb_access_context); |
| 3628 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3629 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 3630 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 3631 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 3632 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 3633 | pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 3634 | skip = pipeline_barrier.Validate(*cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3635 | return skip; |
| 3636 | } |
| 3637 | |
| 3638 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3639 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3640 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3641 | uint32_t bufferMemoryBarrierCount, |
| 3642 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3643 | uint32_t imageMemoryBarrierCount, |
| 3644 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3645 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3646 | assert(cb_access_context); |
| 3647 | if (!cb_access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3648 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 3649 | CommandBufferAccessContext::SyncOpPointer sync_op( |
| 3650 | new SyncOpPipelineBarrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, dstStageMask, |
| 3651 | dependencyFlags, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 3652 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers)); |
| 3653 | const auto tag = sync_op->Record(cb_access_context); |
| 3654 | cb_access_context->AddSyncOp(tag, std::move(sync_op)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3655 | } |
| 3656 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 3657 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 3658 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 3659 | bool skip = false; |
| 3660 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3661 | assert(cb_access_context); |
| 3662 | if (!cb_access_context) return skip; |
| 3663 | |
| 3664 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3665 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 3666 | return skip; |
| 3667 | } |
| 3668 | |
| 3669 | void SyncValidator::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) { |
| 3670 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3671 | assert(cb_access_context); |
| 3672 | if (!cb_access_context) return; |
| 3673 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 3674 | CommandBufferAccessContext::SyncOpPointer sync_op( |
| 3675 | new SyncOpPipelineBarrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo)); |
| 3676 | const auto tag = sync_op->Record(cb_access_context); |
| 3677 | cb_access_context->AddSyncOp(tag, std::move(sync_op)); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 3678 | } |
| 3679 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3680 | void SyncValidator::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 3681 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result) { |
| 3682 | // The state tracker sets up the device state |
| 3683 | StateTracker::PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, result); |
| 3684 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3685 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 3686 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3687 | // TODO: Find a good way to do this hooklessly. |
| 3688 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 3689 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, LayerObjectTypeSyncValidation); |
| 3690 | SyncValidator *sync_device_state = static_cast<SyncValidator *>(validation_data); |
| 3691 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3692 | sync_device_state->SetCommandBufferResetCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3693 | sync_device_state->ResetCommandBufferCallback(command_buffer); |
| 3694 | }); |
| 3695 | sync_device_state->SetCommandBufferFreeCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3696 | sync_device_state->FreeCommandBufferCallback(command_buffer); |
| 3697 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3698 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3699 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3700 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3701 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3702 | bool skip = false; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3703 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3704 | if (cb_context) { |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3705 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3706 | skip = sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3707 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3708 | return skip; |
| 3709 | } |
| 3710 | |
| 3711 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3712 | VkSubpassContents contents) const { |
| 3713 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3714 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3715 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3716 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3717 | return skip; |
| 3718 | } |
| 3719 | |
| 3720 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3721 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3722 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3723 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3724 | return skip; |
| 3725 | } |
| 3726 | |
| 3727 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3728 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3729 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3730 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3731 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3732 | return skip; |
| 3733 | } |
| 3734 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3735 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 3736 | VkResult result) { |
| 3737 | // The state tracker sets up the command buffer state |
| 3738 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 3739 | |
| 3740 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 3741 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 3742 | assert(cb_access_context); |
| 3743 | cb_access_context->Reset(); |
| 3744 | } |
| 3745 | |
| 3746 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3747 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3748 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3749 | if (cb_context) { |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3750 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3751 | sync_op.Record(cb_context); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3752 | } |
| 3753 | } |
| 3754 | |
| 3755 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3756 | VkSubpassContents contents) { |
| 3757 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3758 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3759 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3760 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3764 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3765 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3766 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3770 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3771 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3772 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3773 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3774 | } |
| 3775 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3776 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3777 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3778 | bool skip = false; |
| 3779 | |
| 3780 | auto cb_context = GetAccessContext(commandBuffer); |
| 3781 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3782 | if (!cb_context) return skip; |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3783 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3784 | return sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 3788 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3789 | // Convert to a NextSubpass2 |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3790 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3791 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3792 | auto subpass_end_info = LvlInitStruct<VkSubpassEndInfo>(); |
| 3793 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, &subpass_end_info, CMD_NEXTSUBPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3794 | return skip; |
| 3795 | } |
| 3796 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3797 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3798 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3799 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3800 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3801 | return skip; |
| 3802 | } |
| 3803 | |
| 3804 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3805 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 3806 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3807 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3808 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3812 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3813 | auto cb_context = GetAccessContext(commandBuffer); |
| 3814 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3815 | if (!cb_context) return; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3816 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3817 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3818 | sync_op.Record(cb_context); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 3822 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3823 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3824 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3825 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3829 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3830 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3831 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3835 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3836 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3837 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2KHR); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3838 | } |
| 3839 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3840 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
| 3841 | CMD_TYPE cmd) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3842 | bool skip = false; |
| 3843 | |
| 3844 | auto cb_context = GetAccessContext(commandBuffer); |
| 3845 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3846 | if (!cb_context) return skip; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3847 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3848 | SyncOpEndRenderPass sync_op(cmd, *this, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3849 | skip |= sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3850 | return skip; |
| 3851 | } |
| 3852 | |
| 3853 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 3854 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3855 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3856 | return skip; |
| 3857 | } |
| 3858 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3859 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3860 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3861 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3862 | return skip; |
| 3863 | } |
| 3864 | |
| 3865 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3866 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3867 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3868 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2KHR); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3869 | return skip; |
| 3870 | } |
| 3871 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3872 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3873 | // Resolve the all subpass contexts to the command buffer contexts |
| 3874 | auto cb_context = GetAccessContext(commandBuffer); |
| 3875 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3876 | if (!cb_context) return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3877 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3878 | SyncOpEndRenderPass sync_op(cmd, *this, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3879 | sync_op.Record(cb_context); |
| 3880 | return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3881 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3882 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 3883 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 3884 | // updates to a resource which do not conflict at the byte level. |
| 3885 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 3886 | // TODO: Add programatic control over suppression heuristics |
| 3887 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 3888 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 3889 | } |
| 3890 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3891 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3892 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3893 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3897 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3898 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3899 | } |
| 3900 | |
| 3901 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 3902 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2KHR); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3903 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3904 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3905 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3906 | template <typename BufferImageCopyRegionType> |
| 3907 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3908 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3909 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3910 | bool skip = false; |
| 3911 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3912 | assert(cb_access_context); |
| 3913 | if (!cb_access_context) return skip; |
| 3914 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3915 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3916 | const char *func_name = is_2khr ? "vkCmdCopyBufferToImage2KHR()" : "vkCmdCopyBufferToImage()"; |
| 3917 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3918 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3919 | assert(context); |
| 3920 | if (!context) return skip; |
| 3921 | |
| 3922 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3923 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3924 | |
| 3925 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3926 | const auto ©_region = pRegions[region]; |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3927 | HazardResult hazard; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3928 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3929 | if (src_buffer) { |
| 3930 | ResourceAccessRange src_range = |
| 3931 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3932 | hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3933 | if (hazard.hazard) { |
| 3934 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 3935 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3936 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3937 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3938 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3939 | } |
| 3940 | } |
| 3941 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3942 | hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.imageSubresource, |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3943 | copy_region.imageOffset, copy_region.imageExtent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3944 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3945 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3946 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", func_name, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3947 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3948 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3949 | } |
| 3950 | if (skip) break; |
| 3951 | } |
| 3952 | if (skip) break; |
| 3953 | } |
| 3954 | return skip; |
| 3955 | } |
| 3956 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3957 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3958 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3959 | const VkBufferImageCopy *pRegions) const { |
| 3960 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
| 3961 | COPY_COMMAND_VERSION_1); |
| 3962 | } |
| 3963 | |
| 3964 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3965 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 3966 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3967 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3968 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3969 | } |
| 3970 | |
| 3971 | template <typename BufferImageCopyRegionType> |
| 3972 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3973 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3974 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3975 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3976 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3977 | |
| 3978 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3979 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYBUFFERTOIMAGE2KHR : CMD_COPYBUFFERTOIMAGE; |
| 3980 | |
| 3981 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3982 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3983 | assert(context); |
| 3984 | |
| 3985 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3986 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3987 | |
| 3988 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3989 | const auto ©_region = pRegions[region]; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3990 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3991 | if (src_buffer) { |
| 3992 | ResourceAccessRange src_range = |
| 3993 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3994 | 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] | 3995 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3996 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3997 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3998 | } |
| 3999 | } |
| 4000 | } |
| 4001 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4002 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4003 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4004 | const VkBufferImageCopy *pRegions) { |
| 4005 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
| 4006 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 4007 | } |
| 4008 | |
| 4009 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 4010 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 4011 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 4012 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 4013 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 4014 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 4015 | } |
| 4016 | |
| 4017 | template <typename BufferImageCopyRegionType> |
| 4018 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4019 | VkBuffer dstBuffer, uint32_t regionCount, |
| 4020 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4021 | bool skip = false; |
| 4022 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4023 | assert(cb_access_context); |
| 4024 | if (!cb_access_context) return skip; |
| 4025 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4026 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 4027 | const char *func_name = is_2khr ? "vkCmdCopyImageToBuffer2KHR()" : "vkCmdCopyImageToBuffer()"; |
| 4028 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4029 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4030 | assert(context); |
| 4031 | if (!context) return skip; |
| 4032 | |
| 4033 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4034 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 4035 | 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] | 4036 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4037 | const auto ©_region = pRegions[region]; |
| 4038 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4039 | auto hazard = context->DetectHazard(*src_image, SYNC_COPY_TRANSFER_READ, copy_region.imageSubresource, |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4040 | copy_region.imageOffset, copy_region.imageExtent); |
| 4041 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4042 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4043 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", func_name, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4044 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4045 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4046 | } |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4047 | if (dst_mem) { |
| 4048 | ResourceAccessRange dst_range = |
| 4049 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4050 | hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4051 | if (hazard.hazard) { |
| 4052 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4053 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 4054 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4055 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4056 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4057 | } |
| 4058 | } |
| 4059 | if (skip) break; |
| 4060 | } |
| 4061 | return skip; |
| 4062 | } |
| 4063 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4064 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 4065 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 4066 | const VkBufferImageCopy *pRegions) const { |
| 4067 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
| 4068 | COPY_COMMAND_VERSION_1); |
| 4069 | } |
| 4070 | |
| 4071 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4072 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 4073 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4074 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 4075 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 4076 | } |
| 4077 | |
| 4078 | template <typename BufferImageCopyRegionType> |
| 4079 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4080 | VkBuffer dstBuffer, uint32_t regionCount, const BufferImageCopyRegionType *pRegions, |
| 4081 | CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4082 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4083 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4084 | |
| 4085 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 4086 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYIMAGETOBUFFER2KHR : CMD_COPYIMAGETOBUFFER; |
| 4087 | |
| 4088 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4089 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4090 | assert(context); |
| 4091 | |
| 4092 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4093 | auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 4094 | 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] | 4095 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4096 | |
| 4097 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4098 | const auto ©_region = pRegions[region]; |
| 4099 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4100 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4101 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 4102 | if (dst_buffer) { |
| 4103 | ResourceAccessRange dst_range = |
| 4104 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4105 | 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] | 4106 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4107 | } |
| 4108 | } |
| 4109 | } |
| 4110 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4111 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4112 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 4113 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
| 4114 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 4115 | } |
| 4116 | |
| 4117 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 4118 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 4119 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 4120 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 4121 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 4122 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 4123 | } |
| 4124 | |
| 4125 | template <typename RegionType> |
| 4126 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4127 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4128 | const RegionType *pRegions, VkFilter filter, const char *apiName) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4129 | bool skip = false; |
| 4130 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4131 | assert(cb_access_context); |
| 4132 | if (!cb_access_context) return skip; |
| 4133 | |
| 4134 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4135 | assert(context); |
| 4136 | if (!context) return skip; |
| 4137 | |
| 4138 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4139 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4140 | |
| 4141 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4142 | const auto &blit_region = pRegions[region]; |
| 4143 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4144 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4145 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4146 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4147 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4148 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4149 | 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] | 4150 | auto hazard = context->DetectHazard(*src_image, SYNC_BLIT_TRANSFER_READ, blit_region.srcSubresource, offset, extent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4151 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4152 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4153 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4154 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4155 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4156 | } |
| 4157 | } |
| 4158 | |
| 4159 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4160 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4161 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4162 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4163 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4164 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4165 | 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] | 4166 | auto hazard = context->DetectHazard(*dst_image, SYNC_BLIT_TRANSFER_WRITE, blit_region.dstSubresource, offset, extent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4167 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4168 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4169 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4170 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4171 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4172 | } |
| 4173 | if (skip) break; |
| 4174 | } |
| 4175 | } |
| 4176 | |
| 4177 | return skip; |
| 4178 | } |
| 4179 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4180 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4181 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4182 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 4183 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
| 4184 | "vkCmdBlitImage"); |
| 4185 | } |
| 4186 | |
| 4187 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 4188 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 4189 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4190 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4191 | pBlitImageInfo->filter, "vkCmdBlitImage2KHR"); |
| 4192 | } |
| 4193 | |
| 4194 | template <typename RegionType> |
| 4195 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4196 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4197 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4198 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4199 | assert(cb_access_context); |
| 4200 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4201 | assert(context); |
| 4202 | |
| 4203 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4204 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4205 | |
| 4206 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4207 | const auto &blit_region = pRegions[region]; |
| 4208 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4209 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4210 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4211 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4212 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4213 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4214 | 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] | 4215 | context->UpdateAccessState(*src_image, SYNC_BLIT_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4216 | blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4217 | } |
| 4218 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4219 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4220 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4221 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4222 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4223 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4224 | 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] | 4225 | context->UpdateAccessState(*dst_image, SYNC_BLIT_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4226 | blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4227 | } |
| 4228 | } |
| 4229 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4230 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4231 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4232 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4233 | const VkImageBlit *pRegions, VkFilter filter) { |
| 4234 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4235 | assert(cb_access_context); |
| 4236 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 4237 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4238 | pRegions, filter); |
| 4239 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 4240 | } |
| 4241 | |
| 4242 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 4243 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 4244 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4245 | assert(cb_access_context); |
| 4246 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 4247 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4248 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4249 | pBlitImageInfo->filter, tag); |
| 4250 | } |
| 4251 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4252 | bool SyncValidator::ValidateIndirectBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4253 | VkCommandBuffer commandBuffer, const VkDeviceSize struct_size, const VkBuffer buffer, |
| 4254 | const VkDeviceSize offset, const uint32_t drawCount, const uint32_t stride, |
| 4255 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4256 | bool skip = false; |
| 4257 | if (drawCount == 0) return skip; |
| 4258 | |
| 4259 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 4260 | VkDeviceSize size = struct_size; |
| 4261 | if (drawCount == 1 || stride == size) { |
| 4262 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4263 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4264 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4265 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4266 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4267 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4268 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4269 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4270 | } |
| 4271 | } else { |
| 4272 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4273 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4274 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4275 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4276 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4277 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
| 4278 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4279 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4280 | break; |
| 4281 | } |
| 4282 | } |
| 4283 | } |
| 4284 | return skip; |
| 4285 | } |
| 4286 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 4287 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag tag, const VkDeviceSize struct_size, |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4288 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 4289 | uint32_t stride) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4290 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 4291 | VkDeviceSize size = struct_size; |
| 4292 | if (drawCount == 1 || stride == size) { |
| 4293 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4294 | const ResourceAccessRange range = MakeRange(offset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4295 | 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] | 4296 | } else { |
| 4297 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4298 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4299 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, |
| 4300 | tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4301 | } |
| 4302 | } |
| 4303 | } |
| 4304 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4305 | bool SyncValidator::ValidateCountBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4306 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4307 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4308 | bool skip = false; |
| 4309 | |
| 4310 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4311 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4312 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4313 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 4314 | skip |= LogError(count_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4315 | "%s: Hazard %s for countBuffer %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4316 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4317 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4318 | } |
| 4319 | return skip; |
| 4320 | } |
| 4321 | |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 4322 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag tag, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4323 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4324 | const ResourceAccessRange range = MakeRange(offset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4325 | 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] | 4326 | } |
| 4327 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4328 | 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] | 4329 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4330 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4331 | assert(cb_access_context); |
| 4332 | if (!cb_access_context) return skip; |
| 4333 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4334 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4335 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | 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] | 4339 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4340 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4341 | assert(cb_access_context); |
| 4342 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4343 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4344 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4345 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4346 | |
| 4347 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4348 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4349 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4350 | assert(cb_access_context); |
| 4351 | if (!cb_access_context) return skip; |
| 4352 | |
| 4353 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4354 | assert(context); |
| 4355 | if (!context) return skip; |
| 4356 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4357 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4358 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, |
| 4359 | 1, sizeof(VkDispatchIndirectCommand), "vkCmdDispatchIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4360 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4364 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4365 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4366 | assert(cb_access_context); |
| 4367 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 4368 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4369 | assert(context); |
| 4370 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4371 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 4372 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4376 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4377 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4378 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4379 | assert(cb_access_context); |
| 4380 | if (!cb_access_context) return skip; |
| 4381 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4382 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw"); |
| 4383 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, "vkCmdDraw"); |
| 4384 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDraw"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4385 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4386 | } |
| 4387 | |
| 4388 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4389 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4390 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4391 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4392 | assert(cb_access_context); |
| 4393 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4394 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4395 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4396 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 4397 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4398 | } |
| 4399 | |
| 4400 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4401 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4402 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4403 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4404 | assert(cb_access_context); |
| 4405 | if (!cb_access_context) return skip; |
| 4406 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4407 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed"); |
| 4408 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, "vkCmdDrawIndexed"); |
| 4409 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexed"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4410 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4414 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4415 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4416 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4417 | assert(cb_access_context); |
| 4418 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4419 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4420 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4421 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 4422 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4426 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4427 | bool skip = false; |
| 4428 | if (drawCount == 0) return skip; |
| 4429 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4430 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4431 | assert(cb_access_context); |
| 4432 | if (!cb_access_context) return skip; |
| 4433 | |
| 4434 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4435 | assert(context); |
| 4436 | if (!context) return skip; |
| 4437 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4438 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect"); |
| 4439 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4440 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4441 | drawCount, stride, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4442 | |
| 4443 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4444 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4445 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4446 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4447 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4451 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4452 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4453 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4454 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4455 | assert(cb_access_context); |
| 4456 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 4457 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4458 | assert(context); |
| 4459 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4460 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4461 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4462 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4463 | |
| 4464 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4465 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4466 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4467 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4468 | } |
| 4469 | |
| 4470 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4471 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4472 | bool skip = false; |
| 4473 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4474 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4475 | assert(cb_access_context); |
| 4476 | if (!cb_access_context) return skip; |
| 4477 | |
| 4478 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4479 | assert(context); |
| 4480 | if (!context) return skip; |
| 4481 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4482 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect"); |
| 4483 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexedIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4484 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4485 | offset, drawCount, stride, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4486 | |
| 4487 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4488 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4489 | // We will validate the index and vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4490 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4491 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4495 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4496 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4497 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4498 | assert(cb_access_context); |
| 4499 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 4500 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4501 | assert(context); |
| 4502 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4503 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4504 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4505 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4506 | |
| 4507 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4508 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4509 | // 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] | 4510 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4514 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4515 | uint32_t stride, const char *function) const { |
| 4516 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4517 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4518 | assert(cb_access_context); |
| 4519 | if (!cb_access_context) return skip; |
| 4520 | |
| 4521 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4522 | assert(context); |
| 4523 | if (!context) return skip; |
| 4524 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4525 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4526 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4527 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4528 | maxDrawCount, stride, function); |
| 4529 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4530 | |
| 4531 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4532 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4533 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4534 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4535 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4539 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4540 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4541 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4542 | "vkCmdDrawIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4543 | } |
| 4544 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4545 | void SyncValidator::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4546 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4547 | uint32_t stride, CMD_TYPE cmd_type) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4548 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4549 | assert(cb_access_context); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4550 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4551 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4552 | assert(context); |
| 4553 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4554 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4555 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4556 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 4557 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4558 | |
| 4559 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4560 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4561 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4562 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4563 | } |
| 4564 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4565 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4566 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4567 | uint32_t stride) { |
| 4568 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4569 | stride); |
| 4570 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4571 | CMD_DRAWINDIRECTCOUNT); |
| 4572 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4573 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4574 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4575 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4576 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4577 | "vkCmdDrawIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4578 | } |
| 4579 | |
| 4580 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4581 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4582 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4583 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4584 | stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4585 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4586 | CMD_DRAWINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4587 | } |
| 4588 | |
| 4589 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4590 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4591 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4592 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4593 | "vkCmdDrawIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4597 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4598 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4599 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4600 | stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4601 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4602 | CMD_DRAWINDIRECTCOUNTAMD); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4603 | } |
| 4604 | |
| 4605 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4606 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4607 | uint32_t stride, const char *function) const { |
| 4608 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4609 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4610 | assert(cb_access_context); |
| 4611 | if (!cb_access_context) return skip; |
| 4612 | |
| 4613 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4614 | assert(context); |
| 4615 | if (!context) return skip; |
| 4616 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4617 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4618 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4619 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4620 | offset, maxDrawCount, stride, function); |
| 4621 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4622 | |
| 4623 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4624 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4625 | // We will validate the index and vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4626 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4627 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4628 | } |
| 4629 | |
| 4630 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4631 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4632 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4633 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4634 | "vkCmdDrawIndexedIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4635 | } |
| 4636 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4637 | void SyncValidator::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4638 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4639 | uint32_t stride, CMD_TYPE cmd_type) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4640 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4641 | assert(cb_access_context); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4642 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4643 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4644 | assert(context); |
| 4645 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4646 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4647 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4648 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 4649 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4650 | |
| 4651 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4652 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4653 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 4654 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4655 | } |
| 4656 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4657 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4658 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4659 | uint32_t maxDrawCount, uint32_t stride) { |
| 4660 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4661 | maxDrawCount, stride); |
| 4662 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4663 | CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 4664 | } |
| 4665 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4666 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4667 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4668 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4669 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4670 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4671 | "vkCmdDrawIndexedIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4675 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4676 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4677 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4678 | maxDrawCount, stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4679 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4680 | CMD_DRAWINDEXEDINDIRECTCOUNTKHR); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4681 | } |
| 4682 | |
| 4683 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4684 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4685 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4686 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4687 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4688 | "vkCmdDrawIndexedIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4692 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4693 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4694 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4695 | maxDrawCount, stride); |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 4696 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4697 | CMD_DRAWINDEXEDINDIRECTCOUNTAMD); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4701 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4702 | const VkImageSubresourceRange *pRanges) const { |
| 4703 | bool skip = false; |
| 4704 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4705 | assert(cb_access_context); |
| 4706 | if (!cb_access_context) return skip; |
| 4707 | |
| 4708 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4709 | assert(context); |
| 4710 | if (!context) return skip; |
| 4711 | |
| 4712 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4713 | |
| 4714 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4715 | const auto &range = pRanges[index]; |
| 4716 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4717 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4718 | if (hazard.hazard) { |
| 4719 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4720 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4721 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4722 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4723 | } |
| 4724 | } |
| 4725 | } |
| 4726 | return skip; |
| 4727 | } |
| 4728 | |
| 4729 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4730 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4731 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4732 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4733 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4734 | assert(cb_access_context); |
| 4735 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 4736 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4737 | assert(context); |
| 4738 | |
| 4739 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4740 | |
| 4741 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4742 | const auto &range = pRanges[index]; |
| 4743 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4744 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4745 | } |
| 4746 | } |
| 4747 | } |
| 4748 | |
| 4749 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 4750 | VkImageLayout imageLayout, |
| 4751 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4752 | const VkImageSubresourceRange *pRanges) const { |
| 4753 | bool skip = false; |
| 4754 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4755 | assert(cb_access_context); |
| 4756 | if (!cb_access_context) return skip; |
| 4757 | |
| 4758 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4759 | assert(context); |
| 4760 | if (!context) return skip; |
| 4761 | |
| 4762 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4763 | |
| 4764 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4765 | const auto &range = pRanges[index]; |
| 4766 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4767 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4768 | if (hazard.hazard) { |
| 4769 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4770 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4771 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4772 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4773 | } |
| 4774 | } |
| 4775 | } |
| 4776 | return skip; |
| 4777 | } |
| 4778 | |
| 4779 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4780 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4781 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4782 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4783 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4784 | assert(cb_access_context); |
| 4785 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 4786 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4787 | assert(context); |
| 4788 | |
| 4789 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4790 | |
| 4791 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4792 | const auto &range = pRanges[index]; |
| 4793 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4794 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4795 | } |
| 4796 | } |
| 4797 | } |
| 4798 | |
| 4799 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4800 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 4801 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 4802 | VkQueryResultFlags flags) const { |
| 4803 | bool skip = false; |
| 4804 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4805 | assert(cb_access_context); |
| 4806 | if (!cb_access_context) return skip; |
| 4807 | |
| 4808 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4809 | assert(context); |
| 4810 | if (!context) return skip; |
| 4811 | |
| 4812 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4813 | |
| 4814 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4815 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4816 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4817 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4818 | skip |= |
| 4819 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4820 | "vkCmdCopyQueryPoolResults: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4821 | report_data->FormatHandle(dstBuffer).c_str(), cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4822 | } |
| 4823 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4824 | |
| 4825 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4826 | return skip; |
| 4827 | } |
| 4828 | |
| 4829 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 4830 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4831 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4832 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 4833 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4834 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4835 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4836 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4837 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4838 | assert(context); |
| 4839 | |
| 4840 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4841 | |
| 4842 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4843 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4844 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4845 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4846 | |
| 4847 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4851 | VkDeviceSize size, uint32_t data) const { |
| 4852 | bool skip = false; |
| 4853 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4854 | assert(cb_access_context); |
| 4855 | if (!cb_access_context) return skip; |
| 4856 | |
| 4857 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4858 | assert(context); |
| 4859 | if (!context) return skip; |
| 4860 | |
| 4861 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4862 | |
| 4863 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4864 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4865 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4866 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4867 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4868 | "vkCmdFillBuffer: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4869 | report_data->FormatHandle(dstBuffer).c_str(), cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4870 | } |
| 4871 | } |
| 4872 | return skip; |
| 4873 | } |
| 4874 | |
| 4875 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4876 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4877 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4878 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4879 | assert(cb_access_context); |
| 4880 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 4881 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4882 | assert(context); |
| 4883 | |
| 4884 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4885 | |
| 4886 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4887 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4888 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4889 | } |
| 4890 | } |
| 4891 | |
| 4892 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4893 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4894 | const VkImageResolve *pRegions) const { |
| 4895 | bool skip = false; |
| 4896 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4897 | assert(cb_access_context); |
| 4898 | if (!cb_access_context) return skip; |
| 4899 | |
| 4900 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4901 | assert(context); |
| 4902 | if (!context) return skip; |
| 4903 | |
| 4904 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4905 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4906 | |
| 4907 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4908 | const auto &resolve_region = pRegions[region]; |
| 4909 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4910 | auto hazard = context->DetectHazard(*src_image, SYNC_RESOLVE_TRANSFER_READ, resolve_region.srcSubresource, |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4911 | resolve_region.srcOffset, resolve_region.extent); |
| 4912 | if (hazard.hazard) { |
| 4913 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4914 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4915 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4916 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4917 | } |
| 4918 | } |
| 4919 | |
| 4920 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4921 | auto hazard = context->DetectHazard(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, resolve_region.dstSubresource, |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4922 | resolve_region.dstOffset, resolve_region.extent); |
| 4923 | if (hazard.hazard) { |
| 4924 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4925 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4926 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4927 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4928 | } |
| 4929 | if (skip) break; |
| 4930 | } |
| 4931 | } |
| 4932 | |
| 4933 | return skip; |
| 4934 | } |
| 4935 | |
| 4936 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4937 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4938 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4939 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4940 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4941 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4942 | assert(cb_access_context); |
| 4943 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 4944 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4945 | assert(context); |
| 4946 | |
| 4947 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4948 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4949 | |
| 4950 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4951 | const auto &resolve_region = pRegions[region]; |
| 4952 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4953 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4954 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4955 | } |
| 4956 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4957 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4958 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4959 | } |
| 4960 | } |
| 4961 | } |
| 4962 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4963 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4964 | const VkResolveImageInfo2KHR *pResolveImageInfo) const { |
| 4965 | bool skip = false; |
| 4966 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4967 | assert(cb_access_context); |
| 4968 | if (!cb_access_context) return skip; |
| 4969 | |
| 4970 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4971 | assert(context); |
| 4972 | if (!context) return skip; |
| 4973 | |
| 4974 | const auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4975 | const auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4976 | |
| 4977 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4978 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4979 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4980 | auto hazard = context->DetectHazard(*src_image, SYNC_RESOLVE_TRANSFER_READ, resolve_region.srcSubresource, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4981 | resolve_region.srcOffset, resolve_region.extent); |
| 4982 | if (hazard.hazard) { |
| 4983 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 4984 | "vkCmdResolveImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 4985 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4986 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4987 | } |
| 4988 | } |
| 4989 | |
| 4990 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4991 | auto hazard = context->DetectHazard(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, resolve_region.dstSubresource, |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4992 | resolve_region.dstOffset, resolve_region.extent); |
| 4993 | if (hazard.hazard) { |
| 4994 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 4995 | "vkCmdResolveImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 4996 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4997 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4998 | } |
| 4999 | if (skip) break; |
| 5000 | } |
| 5001 | } |
| 5002 | |
| 5003 | return skip; |
| 5004 | } |
| 5005 | |
| 5006 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 5007 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 5008 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 5009 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5010 | assert(cb_access_context); |
| 5011 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE2KHR); |
| 5012 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5013 | assert(context); |
| 5014 | |
| 5015 | auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 5016 | auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 5017 | |
| 5018 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 5019 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 5020 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5021 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5022 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5023 | } |
| 5024 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5025 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 5026 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 5027 | } |
| 5028 | } |
| 5029 | } |
| 5030 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5031 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5032 | VkDeviceSize dataSize, const void *pData) const { |
| 5033 | bool skip = false; |
| 5034 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5035 | assert(cb_access_context); |
| 5036 | if (!cb_access_context) return skip; |
| 5037 | |
| 5038 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5039 | assert(context); |
| 5040 | if (!context) return skip; |
| 5041 | |
| 5042 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5043 | |
| 5044 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5045 | // VK_WHOLE_SIZE not allowed |
| 5046 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5047 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5048 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 5049 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5050 | "vkCmdUpdateBuffer: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5051 | report_data->FormatHandle(dstBuffer).c_str(), cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5052 | } |
| 5053 | } |
| 5054 | return skip; |
| 5055 | } |
| 5056 | |
| 5057 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 5058 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5059 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5060 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5061 | assert(cb_access_context); |
| 5062 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 5063 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5064 | assert(context); |
| 5065 | |
| 5066 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5067 | |
| 5068 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5069 | // VK_WHOLE_SIZE not allowed |
| 5070 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5071 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 5072 | } |
| 5073 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5074 | |
| 5075 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 5076 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 5077 | bool skip = false; |
| 5078 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5079 | assert(cb_access_context); |
| 5080 | if (!cb_access_context) return skip; |
| 5081 | |
| 5082 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5083 | assert(context); |
| 5084 | if (!context) return skip; |
| 5085 | |
| 5086 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5087 | |
| 5088 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5089 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5090 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5091 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 5092 | skip |= |
| 5093 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5094 | "vkCmdWriteBufferMarkerAMD: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 5095 | report_data->FormatHandle(dstBuffer).c_str(), cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5096 | } |
| 5097 | } |
| 5098 | return skip; |
| 5099 | } |
| 5100 | |
| 5101 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 5102 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 5103 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5104 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5105 | assert(cb_access_context); |
| 5106 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 5107 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5108 | assert(context); |
| 5109 | |
| 5110 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5111 | |
| 5112 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 5113 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5114 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 5115 | } |
| 5116 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5117 | |
| 5118 | bool SyncValidator::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
| 5119 | bool skip = false; |
| 5120 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5121 | assert(cb_context); |
| 5122 | if (!cb_context) return skip; |
| 5123 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5124 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5125 | return set_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5126 | } |
| 5127 | |
| 5128 | void SyncValidator::PostCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 5129 | StateTracker::PostCallRecordCmdSetEvent(commandBuffer, event, stageMask); |
| 5130 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5131 | assert(cb_context); |
| 5132 | if (!cb_context) return; |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5133 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5134 | set_event_op.Record(cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5135 | } |
| 5136 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5137 | bool SyncValidator::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5138 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 5139 | bool skip = false; |
| 5140 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5141 | assert(cb_context); |
| 5142 | if (!cb_context || !pDependencyInfo) return skip; |
| 5143 | |
| 5144 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 5145 | return set_event_op.Validate(*cb_context); |
| 5146 | } |
| 5147 | |
| 5148 | void SyncValidator::PostCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5149 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 5150 | StateTracker::PostCallRecordCmdSetEvent2KHR(commandBuffer, event, pDependencyInfo); |
| 5151 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5152 | assert(cb_context); |
| 5153 | if (!cb_context || !pDependencyInfo) return; |
| 5154 | |
| 5155 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 5156 | set_event_op.Record(cb_context); |
| 5157 | } |
| 5158 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5159 | bool SyncValidator::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 5160 | VkPipelineStageFlags stageMask) const { |
| 5161 | bool skip = false; |
| 5162 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5163 | assert(cb_context); |
| 5164 | if (!cb_context) return skip; |
| 5165 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5166 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5167 | return reset_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5168 | } |
| 5169 | |
| 5170 | void SyncValidator::PostCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 5171 | StateTracker::PostCallRecordCmdResetEvent(commandBuffer, event, stageMask); |
| 5172 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5173 | assert(cb_context); |
| 5174 | if (!cb_context) return; |
| 5175 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5176 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5177 | reset_event_op.Record(cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5178 | } |
| 5179 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5180 | bool SyncValidator::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5181 | VkPipelineStageFlags2KHR stageMask) const { |
| 5182 | bool skip = false; |
| 5183 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5184 | assert(cb_context); |
| 5185 | if (!cb_context) return skip; |
| 5186 | |
| 5187 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5188 | return reset_event_op.Validate(*cb_context); |
| 5189 | } |
| 5190 | |
| 5191 | void SyncValidator::PostCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 5192 | VkPipelineStageFlags2KHR stageMask) { |
| 5193 | StateTracker::PostCallRecordCmdResetEvent2KHR(commandBuffer, event, stageMask); |
| 5194 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5195 | assert(cb_context); |
| 5196 | if (!cb_context) return; |
| 5197 | |
| 5198 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 5199 | reset_event_op.Record(cb_context); |
| 5200 | } |
| 5201 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5202 | bool SyncValidator::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5203 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5204 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5205 | uint32_t bufferMemoryBarrierCount, |
| 5206 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5207 | uint32_t imageMemoryBarrierCount, |
| 5208 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 5209 | bool skip = false; |
| 5210 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5211 | assert(cb_context); |
| 5212 | if (!cb_context) return skip; |
| 5213 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5214 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 5215 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 5216 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5217 | return wait_events_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | void SyncValidator::PostCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5221 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5222 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5223 | uint32_t bufferMemoryBarrierCount, |
| 5224 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5225 | uint32_t imageMemoryBarrierCount, |
| 5226 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 5227 | StateTracker::PostCallRecordCmdWaitEvents(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
| 5228 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 5229 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 5230 | |
| 5231 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5232 | assert(cb_context); |
| 5233 | if (!cb_context) return; |
| 5234 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5235 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 5236 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 5237 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5238 | wait_events_op.Record(cb_context); |
| 5239 | return; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5240 | } |
| 5241 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5242 | bool SyncValidator::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5243 | const VkDependencyInfoKHR *pDependencyInfos) const { |
| 5244 | bool skip = false; |
| 5245 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5246 | assert(cb_context); |
| 5247 | if (!cb_context) return skip; |
| 5248 | |
| 5249 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 5250 | skip |= wait_events_op.Validate(*cb_context); |
| 5251 | return skip; |
| 5252 | } |
| 5253 | |
| 5254 | void SyncValidator::PostCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5255 | const VkDependencyInfoKHR *pDependencyInfos) { |
| 5256 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 5257 | |
| 5258 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5259 | assert(cb_context); |
| 5260 | if (!cb_context) return; |
| 5261 | |
| 5262 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 5263 | wait_events_op.Record(cb_context); |
| 5264 | } |
| 5265 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5266 | void SyncEventState::ResetFirstScope() { |
| 5267 | for (const auto address_type : kAddressTypes) { |
| 5268 | first_scope[static_cast<size_t>(address_type)].clear(); |
| 5269 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 5270 | scope = SyncExecScope(); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | // Keep the "ignore this event" logic in same place for ValidateWait and RecordWait to use |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5274 | SyncEventState::IgnoreReason SyncEventState::IsIgnoredByWait(CMD_TYPE cmd, VkPipelineStageFlags2KHR srcStageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5275 | IgnoreReason reason = NotIgnored; |
| 5276 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5277 | if ((CMD_WAITEVENTS2KHR == cmd) && (CMD_SETEVENT == last_command)) { |
| 5278 | reason = SetVsWait2; |
| 5279 | } else if ((last_command == CMD_RESETEVENT || last_command == CMD_RESETEVENT2KHR) && !HasBarrier(0U, 0U)) { |
| 5280 | reason = (last_command == CMD_RESETEVENT) ? ResetWaitRace : Reset2WaitRace; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5281 | } else if (unsynchronized_set) { |
| 5282 | reason = SetRace; |
| 5283 | } else { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5284 | const VkPipelineStageFlags2KHR missing_bits = scope.mask_param & ~srcStageMask; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5285 | if (missing_bits) reason = MissingStageBits; |
| 5286 | } |
| 5287 | |
| 5288 | return reason; |
| 5289 | } |
| 5290 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5291 | bool SyncEventState::HasBarrier(VkPipelineStageFlags2KHR stageMask, VkPipelineStageFlags2KHR exec_scope_arg) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5292 | bool has_barrier = (last_command == CMD_NONE) || (stageMask & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) || |
| 5293 | (barriers & exec_scope_arg) || (barriers & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 5294 | return has_barrier; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5295 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5296 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5297 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5298 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5299 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5300 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5301 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5302 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5303 | : SyncOpBase(cmd), barriers_(1) { |
| 5304 | auto &barrier_set = barriers_[0]; |
| 5305 | barrier_set.dependency_flags = dependencyFlags; |
| 5306 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, srcStageMask); |
| 5307 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, dstStageMask); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5308 | // 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] | 5309 | barrier_set.MakeMemoryBarriers(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, memoryBarrierCount, |
| 5310 | pMemoryBarriers); |
| 5311 | barrier_set.MakeBufferMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 5312 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
| 5313 | barrier_set.MakeImageMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 5314 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5315 | } |
| 5316 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5317 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t event_count, |
| 5318 | const VkDependencyInfoKHR *dep_infos) |
| 5319 | : SyncOpBase(cmd), barriers_(event_count) { |
| 5320 | for (uint32_t i = 0; i < event_count; i++) { |
| 5321 | const auto &dep_info = dep_infos[i]; |
| 5322 | auto &barrier_set = barriers_[i]; |
| 5323 | barrier_set.dependency_flags = dep_info.dependencyFlags; |
| 5324 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 5325 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, stage_masks.src); |
| 5326 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, stage_masks.dst); |
| 5327 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
| 5328 | barrier_set.MakeMemoryBarriers(queue_flags, dep_info.dependencyFlags, dep_info.memoryBarrierCount, |
| 5329 | dep_info.pMemoryBarriers); |
| 5330 | barrier_set.MakeBufferMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.bufferMemoryBarrierCount, |
| 5331 | dep_info.pBufferMemoryBarriers); |
| 5332 | barrier_set.MakeImageMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.imageMemoryBarrierCount, |
| 5333 | dep_info.pImageMemoryBarriers); |
| 5334 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5335 | } |
| 5336 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5337 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5338 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5339 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 5340 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5341 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5342 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5343 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5344 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers) {} |
| 5345 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5346 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5347 | const VkDependencyInfoKHR &dep_info) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5348 | : SyncOpBarriers(cmd, sync_state, queue_flags, 1, &dep_info) {} |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5349 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5350 | bool SyncOpPipelineBarrier::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5351 | bool skip = false; |
| 5352 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5353 | assert(context); |
| 5354 | if (!context) return skip; |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5355 | assert(barriers_.size() == 1); // PipelineBarriers only support a single barrier set. |
| 5356 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5357 | // Validate Image Layout transitions |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5358 | const auto &barrier_set = barriers_[0]; |
| 5359 | for (const auto &image_barrier : barrier_set.image_memory_barriers) { |
| 5360 | if (image_barrier.new_layout == image_barrier.old_layout) continue; // Only interested in layout transitions at this point. |
| 5361 | const auto *image_state = image_barrier.image.get(); |
| 5362 | if (!image_state) continue; |
| 5363 | const auto hazard = context->DetectImageBarrierHazard(image_barrier); |
| 5364 | if (hazard.hazard) { |
| 5365 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 5366 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5367 | const auto image_handle = image_state->image(); |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5368 | skip |= sync_state.LogError(image_handle, string_SyncHazardVUID(hazard.hazard), |
| 5369 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5370 | string_SyncHazard(hazard.hazard), image_barrier.index, |
| 5371 | sync_state.report_data->FormatHandle(image_handle).c_str(), |
| 5372 | cb_context.FormatUsage(hazard).c_str()); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5373 | } |
| 5374 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5375 | return skip; |
| 5376 | } |
| 5377 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5378 | struct SyncOpPipelineBarrierFunctorFactory { |
| 5379 | using BarrierOpFunctor = PipelineBarrierOp; |
| 5380 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5381 | using GlobalBarrierOpFunctor = PipelineBarrierOp; |
| 5382 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5383 | using BufferRange = ResourceAccessRange; |
| 5384 | using ImageRange = subresource_adapter::ImageRangeGenerator; |
| 5385 | using GlobalRange = ResourceAccessRange; |
| 5386 | |
| 5387 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier, bool layout_transition) const { |
| 5388 | return ApplyFunctor(BarrierOpFunctor(barrier, layout_transition)); |
| 5389 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 5390 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5391 | return GlobalApplyFunctor(true /* resolve */, size_hint, tag); |
| 5392 | } |
| 5393 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier) const { |
| 5394 | return GlobalBarrierOpFunctor(barrier, false); |
| 5395 | } |
| 5396 | |
| 5397 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range) const { |
| 5398 | if (!SimpleBinding(buffer)) return ResourceAccessRange(); |
| 5399 | const auto base_address = ResourceBaseAddress(buffer); |
| 5400 | return (range + base_address); |
| 5401 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5402 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 5403 | if (!SimpleBinding(image)) return subresource_adapter::ImageRangeGenerator(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5404 | |
| 5405 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5406 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5407 | return range_gen; |
| 5408 | } |
| 5409 | GlobalRange MakeGlobalRangeGen(AccessAddressType) const { return kFullRange; } |
| 5410 | }; |
| 5411 | |
| 5412 | template <typename Barriers, typename FunctorFactory> |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 5413 | void SyncOpBarriers::ApplyBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag tag, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5414 | AccessContext *context) { |
| 5415 | for (const auto &barrier : barriers) { |
| 5416 | const auto *state = barrier.GetState(); |
| 5417 | if (state) { |
| 5418 | auto *const accesses = &context->GetAccessStateMap(GetAccessAddressType(*state)); |
| 5419 | auto update_action = factory.MakeApplyFunctor(barrier.barrier, barrier.IsLayoutTransition()); |
| 5420 | auto range_gen = factory.MakeRangeGen(*state, barrier.Range()); |
| 5421 | UpdateMemoryAccessState(accesses, update_action, &range_gen); |
| 5422 | } |
| 5423 | } |
| 5424 | } |
| 5425 | |
| 5426 | template <typename Barriers, typename FunctorFactory> |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 5427 | void SyncOpBarriers::ApplyGlobalBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag tag, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5428 | AccessContext *access_context) { |
| 5429 | auto barriers_functor = factory.MakeGlobalApplyFunctor(barriers.size(), tag); |
| 5430 | for (const auto &barrier : barriers) { |
| 5431 | barriers_functor.EmplaceBack(factory.MakeGlobalBarrierOpFunctor(barrier)); |
| 5432 | } |
| 5433 | for (const auto address_type : kAddressTypes) { |
| 5434 | auto range_gen = factory.MakeGlobalRangeGen(address_type); |
| 5435 | UpdateMemoryAccessState(&(access_context->GetAccessStateMap(address_type)), barriers_functor, &range_gen); |
| 5436 | } |
| 5437 | } |
| 5438 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5439 | ResourceUsageTag SyncOpPipelineBarrier::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5440 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5441 | auto *events_context = cb_context->GetCurrentEventsContext(); |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5442 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 5443 | DoRecord(tag, access_context, events_context); |
| 5444 | return tag; |
| 5445 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5446 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 5447 | void SyncOpPipelineBarrier::DoRecord(const ResourceUsageTag tag, AccessContext *access_context, |
| 5448 | SyncEventsContext *events_context) const { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5449 | SyncOpPipelineBarrierFunctorFactory factory; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5450 | // Pipeline barriers only have a single barrier set, unlike WaitEvents2 |
| 5451 | assert(barriers_.size() == 1); |
| 5452 | const auto &barrier_set = barriers_[0]; |
| 5453 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5454 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5455 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5456 | if (barrier_set.single_exec_scope) { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5457 | 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] | 5458 | } else { |
| 5459 | for (const auto &barrier : barrier_set.memory_barriers) { |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5460 | events_context->ApplyBarrier(barrier.src_exec_scope, barrier.dst_exec_scope); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5461 | } |
| 5462 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5463 | } |
| 5464 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5465 | bool SyncOpPipelineBarrier::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
| 5466 | CommandBufferAccessContext *active_context) const { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 5467 | // No Validation for replay, as the layout transition accesses are checked directly, and the src*Mask ordering is captured |
| 5468 | // with first access information. |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5469 | return false; |
| 5470 | } |
| 5471 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5472 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5473 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(const SyncExecScope &src, const SyncExecScope &dst, |
| 5474 | VkDependencyFlags dependency_flags, uint32_t memory_barrier_count, |
| 5475 | const VkMemoryBarrier *barriers) { |
| 5476 | memory_barriers.reserve(std::max<uint32_t>(1, memory_barrier_count)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5477 | 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] | 5478 | const auto &barrier = barriers[barrier_index]; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5479 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5480 | memory_barriers.emplace_back(sync_barrier); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5481 | } |
| 5482 | if (0 == memory_barrier_count) { |
| 5483 | // If there are no global memory barriers, force an exec barrier |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5484 | memory_barriers.emplace_back(SyncBarrier(src, dst)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5485 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5486 | single_exec_scope = true; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5487 | } |
| 5488 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5489 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5490 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5491 | uint32_t barrier_count, const VkBufferMemoryBarrier *barriers) { |
| 5492 | buffer_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5493 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5494 | const auto &barrier = barriers[index]; |
| 5495 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5496 | if (buffer) { |
| 5497 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5498 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5499 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5500 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5501 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5502 | buffer_memory_barriers.emplace_back(); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5503 | } |
| 5504 | } |
| 5505 | } |
| 5506 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5507 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(VkQueueFlags queue_flags, VkDependencyFlags dependency_flags, |
| 5508 | uint32_t memory_barrier_count, const VkMemoryBarrier2KHR *barriers) { |
| 5509 | memory_barriers.reserve(memory_barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5510 | 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] | 5511 | const auto &barrier = barriers[barrier_index]; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5512 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5513 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5514 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5515 | memory_barriers.emplace_back(sync_barrier); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5516 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5517 | single_exec_scope = false; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5518 | } |
| 5519 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5520 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5521 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5522 | const VkBufferMemoryBarrier2KHR *barriers) { |
| 5523 | buffer_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5524 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5525 | const auto &barrier = barriers[index]; |
| 5526 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5527 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5528 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5529 | if (buffer) { |
| 5530 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5531 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5532 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5533 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5534 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5535 | buffer_memory_barriers.emplace_back(); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5536 | } |
| 5537 | } |
| 5538 | } |
| 5539 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5540 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5541 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5542 | uint32_t barrier_count, const VkImageMemoryBarrier *barriers) { |
| 5543 | image_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5544 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5545 | const auto &barrier = barriers[index]; |
| 5546 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5547 | if (image) { |
| 5548 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5549 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5550 | 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] | 5551 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5552 | image_memory_barriers.emplace_back(); |
| 5553 | 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] | 5554 | } |
| 5555 | } |
| 5556 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5557 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5558 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5559 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5560 | const VkImageMemoryBarrier2KHR *barriers) { |
| 5561 | image_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5562 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5563 | const auto &barrier = barriers[index]; |
| 5564 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5565 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5566 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5567 | if (image) { |
| 5568 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5569 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5570 | 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] | 5571 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5572 | image_memory_barriers.emplace_back(); |
| 5573 | 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] | 5574 | } |
| 5575 | } |
| 5576 | } |
| 5577 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5578 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t eventCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5579 | const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5580 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5581 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5582 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5583 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, VkDependencyFlags(0U), memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5584 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 5585 | pImageMemoryBarriers) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5586 | MakeEventsList(sync_state, eventCount, pEvents); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5587 | } |
| 5588 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5589 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t eventCount, |
| 5590 | const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfo) |
| 5591 | : SyncOpBarriers(cmd, sync_state, queue_flags, eventCount, pDependencyInfo) { |
| 5592 | MakeEventsList(sync_state, eventCount, pEvents); |
| 5593 | assert(events_.size() == barriers_.size()); // Just so nobody gets clever and decides to cull the event or barrier arrays |
| 5594 | } |
| 5595 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5596 | bool SyncOpWaitEvents::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5597 | const char *const ignored = "Wait operation is ignored for this event."; |
| 5598 | bool skip = false; |
| 5599 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5600 | const auto command_buffer_handle = cb_context.GetCBState().commandBuffer(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5601 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5602 | for (size_t barrier_set_index = 0; barrier_set_index < barriers_.size(); barrier_set_index++) { |
| 5603 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5604 | if (barrier_set.single_exec_scope) { |
| 5605 | if (barrier_set.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5606 | const std::string vuid = std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 5607 | skip = sync_state.LogInfo(command_buffer_handle, vuid, |
| 5608 | "%s, srcStageMask includes %s, unsupported by synchronization validation.", CmdName(), |
| 5609 | string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT)); |
| 5610 | } else { |
| 5611 | const auto &barriers = barrier_set.memory_barriers; |
| 5612 | for (size_t barrier_index = 0; barrier_index < barriers.size(); barrier_index++) { |
| 5613 | const auto &barrier = barriers[barrier_index]; |
| 5614 | if (barrier.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5615 | const std::string vuid = |
| 5616 | std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 5617 | skip = |
| 5618 | sync_state.LogInfo(command_buffer_handle, vuid, |
| 5619 | "%s, srcStageMask %s of %s %zu, %s %zu, unsupported by synchronization validation.", |
| 5620 | CmdName(), string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT), |
| 5621 | "pDependencyInfo", barrier_set_index, "pMemoryBarriers", barrier_index); |
| 5622 | } |
| 5623 | } |
| 5624 | } |
| 5625 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5626 | } |
| 5627 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5628 | VkPipelineStageFlags2KHR event_stage_masks = 0U; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5629 | VkPipelineStageFlags2KHR barrier_mask_params = 0U; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5630 | bool events_not_found = false; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5631 | const auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5632 | assert(events_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5633 | size_t barrier_set_index = 0; |
| 5634 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame^] | 5635 | for (const auto &event : events_) { |
| 5636 | const auto *sync_event = events_context->Get(event.get()); |
| 5637 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5638 | if (!sync_event) { |
| 5639 | // NOTE PHASE2: This is where we'll need queue submit time validation to come back and check the srcStageMask bits |
| 5640 | // or solve this with replay creating the SyncEventState in the queue context... also this will be a |
| 5641 | // new validation error... wait without previously submitted set event... |
| 5642 | 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] | 5643 | barrier_set_index += barrier_set_incr; |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame^] | 5644 | continue; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5645 | } |
John Zulauf | 78394fc | 2021-07-12 15:41:40 -0600 | [diff] [blame^] | 5646 | const auto event_handle = sync_event->event->event(); |
| 5647 | // TODO add "destroyed" checks |
| 5648 | |
| 5649 | barrier_mask_params |= barrier_set.src_exec_scope.mask_param; |
| 5650 | const auto &src_exec_scope = barrier_set.src_exec_scope; |
| 5651 | event_stage_masks |= sync_event->scope.mask_param; |
| 5652 | const auto ignore_reason = sync_event->IsIgnoredByWait(cmd_, src_exec_scope.mask_param); |
| 5653 | if (ignore_reason) { |
| 5654 | switch (ignore_reason) { |
| 5655 | case SyncEventState::ResetWaitRace: |
| 5656 | case SyncEventState::Reset2WaitRace: { |
| 5657 | // Four permuations of Reset and Wait calls... |
| 5658 | const char *vuid = |
| 5659 | (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent-event-03834" : "VUID-vkCmdResetEvent-event-03835"; |
| 5660 | if (ignore_reason == SyncEventState::Reset2WaitRace) { |
| 5661 | vuid = (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent2KHR-event-03831" |
| 5662 | : "VUID-vkCmdResetEvent2KHR-event-03832"; |
| 5663 | } |
| 5664 | const char *const message = |
| 5665 | "%s: %s %s operation following %s without intervening execution barrier, may cause race condition. %s"; |
| 5666 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5667 | sync_state.report_data->FormatHandle(event_handle).c_str(), CmdName(), |
| 5668 | CommandTypeString(sync_event->last_command), ignored); |
| 5669 | break; |
| 5670 | } |
| 5671 | case SyncEventState::SetRace: { |
| 5672 | // Issue error message that Wait is waiting on an signal subject to race condition, and is thus ignored for |
| 5673 | // this event |
| 5674 | const char *const vuid = "SYNC-vkCmdWaitEvents-unsynchronized-setops"; |
| 5675 | const char *const message = |
| 5676 | "%s: %s Unsychronized %s calls result in race conditions w.r.t. event signalling, %s %s"; |
| 5677 | const char *const reason = "First synchronization scope is undefined."; |
| 5678 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5679 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5680 | CommandTypeString(sync_event->last_command), reason, ignored); |
| 5681 | break; |
| 5682 | } |
| 5683 | case SyncEventState::MissingStageBits: { |
| 5684 | const auto missing_bits = sync_event->scope.mask_param & ~src_exec_scope.mask_param; |
| 5685 | // Issue error message that event waited for is not in wait events scope |
| 5686 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 5687 | const char *const message = "%s: %s stageMask %" PRIx64 " includes bits not present in srcStageMask 0x%" PRIx64 |
| 5688 | ". Bits missing from srcStageMask %s. %s"; |
| 5689 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5690 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5691 | sync_event->scope.mask_param, src_exec_scope.mask_param, |
| 5692 | sync_utils::StringPipelineStageFlags(missing_bits).c_str(), ignored); |
| 5693 | break; |
| 5694 | } |
| 5695 | case SyncEventState::SetVsWait2: { |
| 5696 | skip |= sync_state.LogError(event_handle, "VUID-vkCmdWaitEvents2KHR-pEvents-03837", |
| 5697 | "%s: Follows set of %s by %s. Disallowed.", CmdName(), |
| 5698 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5699 | CommandTypeString(sync_event->last_command)); |
| 5700 | break; |
| 5701 | } |
| 5702 | default: |
| 5703 | assert(ignore_reason == SyncEventState::NotIgnored); |
| 5704 | } |
| 5705 | } else if (barrier_set.image_memory_barriers.size()) { |
| 5706 | const auto &image_memory_barriers = barrier_set.image_memory_barriers; |
| 5707 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5708 | assert(context); |
| 5709 | for (const auto &image_memory_barrier : image_memory_barriers) { |
| 5710 | if (image_memory_barrier.old_layout == image_memory_barrier.new_layout) continue; |
| 5711 | const auto *image_state = image_memory_barrier.image.get(); |
| 5712 | if (!image_state) continue; |
| 5713 | const auto &subresource_range = image_memory_barrier.range; |
| 5714 | const auto &src_access_scope = image_memory_barrier.barrier.src_access_scope; |
| 5715 | const auto hazard = |
| 5716 | context->DetectImageBarrierHazard(*image_state, sync_event->scope.exec_scope, src_access_scope, |
| 5717 | subresource_range, *sync_event, AccessContext::DetectOptions::kDetectAll); |
| 5718 | if (hazard.hazard) { |
| 5719 | skip |= sync_state.LogError(image_state->image(), string_SyncHazardVUID(hazard.hazard), |
| 5720 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5721 | string_SyncHazard(hazard.hazard), image_memory_barrier.index, |
| 5722 | sync_state.report_data->FormatHandle(image_state->image()).c_str(), |
| 5723 | cb_context.FormatUsage(hazard).c_str()); |
| 5724 | break; |
| 5725 | } |
| 5726 | } |
| 5727 | } |
| 5728 | // TODO: Add infrastructure for checking pDependencyInfo's vs. CmdSetEvent2 VUID - vkCmdWaitEvents2KHR - pEvents - |
| 5729 | // 03839 |
| 5730 | barrier_set_index += barrier_set_incr; |
| 5731 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5732 | |
| 5733 | // 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] | 5734 | 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] | 5735 | if (extra_stage_bits) { |
| 5736 | // 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] | 5737 | // NOTE: This isn't exactly the right VUID for WaitEvents2, but it's as close as we currently have support for |
| 5738 | const char *const vuid = |
| 5739 | (CMD_WAITEVENTS == cmd_) ? "VUID-vkCmdWaitEvents-srcStageMask-01158" : "VUID-vkCmdWaitEvents2KHR-pEvents-03838"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5740 | const char *const message = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5741 | "%s: srcStageMask 0x%" PRIx64 " contains stages not present in pEvents stageMask. Extra stages are %s.%s"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5742 | if (events_not_found) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5743 | skip |= sync_state.LogInfo(command_buffer_handle, vuid, message, CmdName(), barrier_mask_params, |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5744 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5745 | " vkCmdSetEvent may be in previously submitted command buffer."); |
| 5746 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5747 | skip |= sync_state.LogError(command_buffer_handle, vuid, message, CmdName(), barrier_mask_params, |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5748 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), ""); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5749 | } |
| 5750 | } |
| 5751 | return skip; |
| 5752 | } |
| 5753 | |
| 5754 | struct SyncOpWaitEventsFunctorFactory { |
| 5755 | using BarrierOpFunctor = WaitEventBarrierOp; |
| 5756 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5757 | using GlobalBarrierOpFunctor = WaitEventBarrierOp; |
| 5758 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5759 | using BufferRange = EventSimpleRangeGenerator; |
| 5760 | using ImageRange = EventImageRangeGenerator; |
| 5761 | using GlobalRange = EventSimpleRangeGenerator; |
| 5762 | |
| 5763 | // Need to restrict to only valid exec and access scope for this event |
| 5764 | // Pass by value is intentional to get a copy we can change without modifying the passed barrier |
| 5765 | SyncBarrier RestrictToEvent(SyncBarrier barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 5766 | 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] | 5767 | barrier.src_access_scope = sync_event->scope.valid_accesses & barrier.src_access_scope; |
| 5768 | return barrier; |
| 5769 | } |
| 5770 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier_arg, bool layout_transition) const { |
| 5771 | auto barrier = RestrictToEvent(barrier_arg); |
| 5772 | return ApplyFunctor(BarrierOpFunctor(sync_event->first_scope_tag, barrier, layout_transition)); |
| 5773 | } |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 5774 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, ResourceUsageTag tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5775 | return GlobalApplyFunctor(false /* don't resolve */, size_hint, tag); |
| 5776 | } |
| 5777 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier_arg) const { |
| 5778 | auto barrier = RestrictToEvent(barrier_arg); |
| 5779 | return GlobalBarrierOpFunctor(sync_event->first_scope_tag, barrier, false); |
| 5780 | } |
| 5781 | |
| 5782 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range_arg) const { |
| 5783 | const AccessAddressType address_type = GetAccessAddressType(buffer); |
| 5784 | const auto base_address = ResourceBaseAddress(buffer); |
| 5785 | ResourceAccessRange range = SimpleBinding(buffer) ? (range_arg + base_address) : ResourceAccessRange(); |
| 5786 | EventSimpleRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), range); |
| 5787 | return filtered_range_gen; |
| 5788 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5789 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5790 | if (!SimpleBinding(image)) return ImageRange(); |
| 5791 | const auto address_type = GetAccessAddressType(image); |
| 5792 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5793 | subresource_adapter::ImageRangeGenerator image_range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5794 | EventImageRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), image_range_gen); |
| 5795 | |
| 5796 | return filtered_range_gen; |
| 5797 | } |
| 5798 | GlobalRange MakeGlobalRangeGen(AccessAddressType address_type) const { |
| 5799 | return EventSimpleRangeGenerator(sync_event->FirstScope(address_type), kFullRange); |
| 5800 | } |
| 5801 | SyncOpWaitEventsFunctorFactory(SyncEventState *sync_event_) : sync_event(sync_event_) { assert(sync_event); } |
| 5802 | SyncEventState *sync_event; |
| 5803 | }; |
| 5804 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5805 | ResourceUsageTag SyncOpWaitEvents::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5806 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5807 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5808 | assert(access_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5809 | if (!access_context) return tag; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5810 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5811 | assert(events_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5812 | if (!events_context) return tag; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5813 | |
| 5814 | // Unlike PipelineBarrier, WaitEvent is *not* limited to accesses within the current subpass (if any) and thus needs to import |
| 5815 | // all accesses. Can instead import for all first_scopes, or a union of them, if this becomes a performance/memory issue, |
| 5816 | // but with no idea of the performance of the union, nor of whether it even matters... take the simplest approach here, |
| 5817 | access_context->ResolvePreviousAccesses(); |
| 5818 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5819 | // TODO... this needs change the SyncEventContext it's using depending on whether this is replay... the recorded |
| 5820 | // sync_event will be in the recorded context, but we need to update the sync_events in the current context.... |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5821 | size_t barrier_set_index = 0; |
| 5822 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 5823 | assert(barriers_.size() == 1 || (barriers_.size() == events_.size())); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5824 | for (auto &event_shared : events_) { |
| 5825 | if (!event_shared.get()) continue; |
| 5826 | auto *sync_event = events_context->GetFromShared(event_shared); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5827 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5828 | sync_event->last_command = cmd_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5829 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5830 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5831 | const auto &dst = barrier_set.dst_exec_scope; |
| 5832 | if (!sync_event->IsIgnoredByWait(cmd_, barrier_set.src_exec_scope.mask_param)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5833 | // These apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 5834 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 5835 | // of the barriers is maintained. |
| 5836 | SyncOpWaitEventsFunctorFactory factory(sync_event); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5837 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5838 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5839 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5840 | |
| 5841 | // Apply the global barrier to the event itself (for race condition tracking) |
| 5842 | // Events don't happen at a stage, so we need to store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 5843 | sync_event->barriers = dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 5844 | sync_event->barriers |= dst.exec_scope; |
| 5845 | } else { |
| 5846 | // We ignored this wait, so we don't have any effective synchronization barriers for it. |
| 5847 | sync_event->barriers = 0U; |
| 5848 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5849 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5850 | } |
| 5851 | |
| 5852 | // Apply the pending barriers |
| 5853 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
| 5854 | access_context->ApplyToContext(apply_pending_action); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5855 | |
| 5856 | return tag; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5857 | } |
| 5858 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5859 | bool SyncOpWaitEvents::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
| 5860 | CommandBufferAccessContext *active_context) const { |
| 5861 | return false; |
| 5862 | } |
| 5863 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 5864 | void SyncOpWaitEvents::DoRecord(ResourceUsageTag tag, AccessContext *access_context, SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5865 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5866 | bool SyncValidator::PreCallValidateCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 5867 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 5868 | bool skip = false; |
| 5869 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5870 | assert(cb_access_context); |
| 5871 | if (!cb_access_context) return skip; |
| 5872 | |
| 5873 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5874 | assert(context); |
| 5875 | if (!context) return skip; |
| 5876 | |
| 5877 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5878 | |
| 5879 | if (dst_buffer) { |
| 5880 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 5881 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
| 5882 | if (hazard.hazard) { |
| 5883 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5884 | "vkCmdWriteBufferMarkerAMD2: Hazard %s for dstBuffer %s. Access info %s.", |
| 5885 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), |
John Zulauf | 1494072 | 2021-04-12 15:19:02 -0600 | [diff] [blame] | 5886 | cb_access_context->FormatUsage(hazard).c_str()); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5887 | } |
| 5888 | } |
| 5889 | return skip; |
| 5890 | } |
| 5891 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5892 | 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] | 5893 | events_.reserve(event_count); |
| 5894 | for (uint32_t event_index = 0; event_index < event_count; event_index++) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5895 | events_.emplace_back(sync_state.GetShared<EVENT_STATE>(events[event_index])); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5896 | } |
| 5897 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5898 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5899 | SyncOpResetEvent::SyncOpResetEvent(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5900 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5901 | : SyncOpBase(cmd), |
| 5902 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
| 5903 | exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5904 | |
| 5905 | bool SyncOpResetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5906 | auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5907 | assert(events_context); |
| 5908 | bool skip = false; |
| 5909 | if (!events_context) return skip; |
| 5910 | |
| 5911 | const auto &sync_state = cb_context.GetSyncState(); |
| 5912 | const auto *sync_event = events_context->Get(event_); |
| 5913 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5914 | |
| 5915 | const char *const set_wait = |
| 5916 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 5917 | "hazards."; |
| 5918 | const char *message = set_wait; // Only one message this call. |
| 5919 | if (!sync_event->HasBarrier(exec_scope_.mask_param, exec_scope_.exec_scope)) { |
| 5920 | const char *vuid = nullptr; |
| 5921 | switch (sync_event->last_command) { |
| 5922 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5923 | case CMD_SETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5924 | // Needs a barrier between set and reset |
| 5925 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-set"; |
| 5926 | break; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5927 | case CMD_WAITEVENTS: |
| 5928 | case CMD_WAITEVENTS2KHR: { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5929 | // Needs to be in the barriers chain (either because of a barrier, or because of dstStageMask |
| 5930 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-wait"; |
| 5931 | break; |
| 5932 | } |
| 5933 | default: |
| 5934 | // The only other valid last command that wasn't one. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5935 | assert((sync_event->last_command == CMD_NONE) || (sync_event->last_command == CMD_RESETEVENT) || |
| 5936 | (sync_event->last_command == CMD_RESETEVENT2KHR)); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5937 | break; |
| 5938 | } |
| 5939 | if (vuid) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5940 | skip |= sync_state.LogError(event_->event(), vuid, message, CmdName(), |
| 5941 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5942 | CommandTypeString(sync_event->last_command)); |
| 5943 | } |
| 5944 | } |
| 5945 | return skip; |
| 5946 | } |
| 5947 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5948 | ResourceUsageTag SyncOpResetEvent::Record(CommandBufferAccessContext *cb_context) const { |
| 5949 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5950 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5951 | assert(events_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5952 | if (!events_context) return tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5953 | |
| 5954 | auto *sync_event = events_context->GetFromShared(event_); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5955 | 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] | 5956 | |
| 5957 | // Update the event state |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5958 | sync_event->last_command = cmd_; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5959 | sync_event->unsynchronized_set = CMD_NONE; |
| 5960 | sync_event->ResetFirstScope(); |
| 5961 | sync_event->barriers = 0U; |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5962 | |
| 5963 | return tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5964 | } |
| 5965 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5966 | bool SyncOpResetEvent::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
| 5967 | CommandBufferAccessContext *active_context) const { |
| 5968 | return false; |
| 5969 | } |
| 5970 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 5971 | void SyncOpResetEvent::DoRecord(ResourceUsageTag tag, AccessContext *access_context, SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 5972 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5973 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5974 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5975 | : SyncOpBase(cmd), |
| 5976 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5977 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)), |
| 5978 | dep_info_() {} |
| 5979 | |
| 5980 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
| 5981 | const VkDependencyInfoKHR &dep_info) |
| 5982 | : SyncOpBase(cmd), |
| 5983 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
| 5984 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, sync_utils::GetGlobalStageMasks(dep_info).src)), |
| 5985 | dep_info_(new safe_VkDependencyInfoKHR(&dep_info)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5986 | |
| 5987 | bool SyncOpSetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5988 | // I'll put this here just in case we need to pass this in for future extension support |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5989 | bool skip = false; |
| 5990 | |
| 5991 | const auto &sync_state = cb_context.GetSyncState(); |
| 5992 | auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5993 | assert(events_context); |
| 5994 | if (!events_context) return skip; |
| 5995 | |
| 5996 | const auto *sync_event = events_context->Get(event_); |
| 5997 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5998 | |
| 5999 | const char *const reset_set = |
| 6000 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 6001 | "hazards."; |
| 6002 | const char *const wait = |
| 6003 | "%s: %s %s operation following %s without intervening vkCmdResetEvent, may result in data hazard and is ignored."; |
| 6004 | |
| 6005 | 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] | 6006 | const char *vuid_stem = nullptr; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6007 | const char *message = nullptr; |
| 6008 | switch (sync_event->last_command) { |
| 6009 | case CMD_RESETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6010 | case CMD_RESETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6011 | // Needs a barrier between reset and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6012 | vuid_stem = "-missingbarrier-reset"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6013 | message = reset_set; |
| 6014 | break; |
| 6015 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6016 | case CMD_SETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6017 | // Needs a barrier between set and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6018 | vuid_stem = "-missingbarrier-set"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6019 | message = reset_set; |
| 6020 | break; |
| 6021 | case CMD_WAITEVENTS: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6022 | case CMD_WAITEVENTS2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6023 | // Needs a barrier or is in second execution scope |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6024 | vuid_stem = "-missingbarrier-wait"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6025 | message = wait; |
| 6026 | break; |
| 6027 | default: |
| 6028 | // The only other valid last command that wasn't one. |
| 6029 | assert(sync_event->last_command == CMD_NONE); |
| 6030 | break; |
| 6031 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6032 | if (vuid_stem) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6033 | assert(nullptr != message); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6034 | std::string vuid("SYNC-"); |
| 6035 | vuid.append(CmdName()).append(vuid_stem); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 6036 | skip |= sync_state.LogError(event_->event(), vuid.c_str(), message, CmdName(), |
| 6037 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6038 | CommandTypeString(sync_event->last_command)); |
| 6039 | } |
| 6040 | } |
| 6041 | |
| 6042 | return skip; |
| 6043 | } |
| 6044 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6045 | ResourceUsageTag SyncOpSetEvent::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 6046 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6047 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 6048 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 6049 | assert(events_context); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6050 | if (!events_context) return tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6051 | |
| 6052 | auto *sync_event = events_context->GetFromShared(event_); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6053 | 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] | 6054 | |
| 6055 | // NOTE: We're going to simply record the sync scope here, as anything else would be implementation defined/undefined |
| 6056 | // and we're issuing errors re: missing barriers between event commands, which if the user fixes would fix |
| 6057 | // any issues caused by naive scope setting here. |
| 6058 | |
| 6059 | // What happens with two SetEvent is that one cannot know what group of operations will be waited for. |
| 6060 | // Given: |
| 6061 | // Stuff1; SetEvent; Stuff2; SetEvent; WaitEvents; |
| 6062 | // WaitEvents cannot know which of Stuff1, Stuff2, or both has completed execution. |
| 6063 | |
| 6064 | if (!sync_event->HasBarrier(src_exec_scope_.mask_param, src_exec_scope_.exec_scope)) { |
| 6065 | sync_event->unsynchronized_set = sync_event->last_command; |
| 6066 | sync_event->ResetFirstScope(); |
| 6067 | } else if (sync_event->scope.exec_scope == 0) { |
| 6068 | // We only set the scope if there isn't one |
| 6069 | sync_event->scope = src_exec_scope_; |
| 6070 | |
| 6071 | auto set_scope = [&sync_event](AccessAddressType address_type, const ResourceAccessRangeMap::value_type &access) { |
| 6072 | auto &scope_map = sync_event->first_scope[static_cast<size_t>(address_type)]; |
| 6073 | if (access.second.InSourceScopeOrChain(sync_event->scope.exec_scope, sync_event->scope.valid_accesses)) { |
| 6074 | scope_map.insert(scope_map.end(), std::make_pair(access.first, true)); |
| 6075 | } |
| 6076 | }; |
| 6077 | access_context->ForAll(set_scope); |
| 6078 | sync_event->unsynchronized_set = CMD_NONE; |
| 6079 | sync_event->first_scope_tag = tag; |
| 6080 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 6081 | // TODO: Store dep_info_ shared ptr in sync_state for WaitEvents2 validation |
| 6082 | sync_event->last_command = cmd_; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6083 | sync_event->barriers = 0U; |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6084 | |
| 6085 | return tag; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 6086 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6087 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6088 | bool SyncOpSetEvent::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
| 6089 | CommandBufferAccessContext *active_context) const { |
| 6090 | return false; |
| 6091 | } |
| 6092 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6093 | void SyncOpSetEvent::DoRecord(ResourceUsageTag tag, AccessContext *access_context, SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6094 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6095 | SyncOpBeginRenderPass::SyncOpBeginRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, |
| 6096 | const VkRenderPassBeginInfo *pRenderPassBegin, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 6097 | const VkSubpassBeginInfo *pSubpassBeginInfo) |
| 6098 | : SyncOpBase(cmd) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6099 | if (pRenderPassBegin) { |
| 6100 | rp_state_ = sync_state.GetShared<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
| 6101 | renderpass_begin_info_ = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
| 6102 | const auto *fb_state = sync_state.Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
| 6103 | if (fb_state) { |
| 6104 | shared_attachments_ = sync_state.GetSharedAttachmentViews(*renderpass_begin_info_.ptr(), *fb_state); |
| 6105 | // TODO: Revisit this when all attachment validation is through SyncOps to see if we can discard the plain pointer copy |
| 6106 | // Note that this a safe to presist as long as shared_attachments is not cleared |
| 6107 | attachments_.reserve(shared_attachments_.size()); |
sfricke-samsung | 01c9ae9 | 2021-02-09 22:30:52 -0800 | [diff] [blame] | 6108 | for (const auto &attachment : shared_attachments_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6109 | attachments_.emplace_back(attachment.get()); |
| 6110 | } |
| 6111 | } |
| 6112 | if (pSubpassBeginInfo) { |
| 6113 | subpass_begin_info_ = safe_VkSubpassBeginInfo(pSubpassBeginInfo); |
| 6114 | } |
| 6115 | } |
| 6116 | } |
| 6117 | |
| 6118 | bool SyncOpBeginRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6119 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 6120 | bool skip = false; |
| 6121 | |
| 6122 | assert(rp_state_.get()); |
| 6123 | if (nullptr == rp_state_.get()) return skip; |
| 6124 | auto &rp_state = *rp_state_.get(); |
| 6125 | |
| 6126 | const uint32_t subpass = 0; |
| 6127 | |
| 6128 | // Construct the state we can use to validate against... (since validation is const and RecordCmdBeginRenderPass |
| 6129 | // hasn't happened yet) |
| 6130 | const std::vector<AccessContext> empty_context_vector; |
| 6131 | AccessContext temp_context(subpass, cb_context.GetQueueFlags(), rp_state.subpass_dependencies, empty_context_vector, |
| 6132 | cb_context.GetCurrentAccessContext()); |
| 6133 | |
| 6134 | // Validate attachment operations |
| 6135 | if (attachments_.size() == 0) return skip; |
| 6136 | const auto &render_area = renderpass_begin_info_.renderArea; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 6137 | |
| 6138 | // Since the isn't a valid RenderPassAccessContext until Record, needs to create the view/generator list... we could limit this |
| 6139 | // by predicating on whether subpass 0 uses the attachment if it is too expensive to create the full list redundantly here. |
| 6140 | // More broadly we could look at thread specific state shared between Validate and Record as is done for other heavyweight |
| 6141 | // operations (though it's currently a messy approach) |
| 6142 | AttachmentViewGenVector view_gens = RenderPassAccessContext::CreateAttachmentViewGen(render_area, attachments_); |
| 6143 | skip |= temp_context.ValidateLayoutTransitions(cb_context, rp_state, render_area, subpass, view_gens, CmdName()); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6144 | |
| 6145 | // Validate load operations if there were no layout transition hazards |
| 6146 | if (!skip) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 6147 | temp_context.RecordLayoutTransitions(rp_state, subpass, view_gens, kCurrentCommandTag); |
| 6148 | skip |= temp_context.ValidateLoadOperation(cb_context, rp_state, render_area, subpass, view_gens, CmdName()); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6149 | } |
| 6150 | |
| 6151 | return skip; |
| 6152 | } |
| 6153 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6154 | ResourceUsageTag SyncOpBeginRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
| 6155 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6156 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 6157 | assert(rp_state_.get()); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6158 | if (nullptr == rp_state_.get()) return tag; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6159 | cb_context->RecordBeginRenderPass(*rp_state_.get(), renderpass_begin_info_.renderArea, attachments_, tag); |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6160 | |
| 6161 | return tag; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6162 | } |
| 6163 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6164 | bool SyncOpBeginRenderPass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
| 6165 | CommandBufferAccessContext *active_context) const { |
| 6166 | return false; |
| 6167 | } |
| 6168 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6169 | void SyncOpBeginRenderPass::DoRecord(ResourceUsageTag tag, AccessContext *access_context, SyncEventsContext *events_context) const { |
| 6170 | } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6171 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6172 | SyncOpNextSubpass::SyncOpNextSubpass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassBeginInfo *pSubpassBeginInfo, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 6173 | const VkSubpassEndInfo *pSubpassEndInfo) |
| 6174 | : SyncOpBase(cmd) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6175 | if (pSubpassBeginInfo) { |
| 6176 | subpass_begin_info_.initialize(pSubpassBeginInfo); |
| 6177 | } |
| 6178 | if (pSubpassEndInfo) { |
| 6179 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | bool SyncOpNextSubpass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6184 | bool skip = false; |
| 6185 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 6186 | if (!renderpass_context) return skip; |
| 6187 | |
| 6188 | skip |= renderpass_context->ValidateNextSubpass(cb_context.GetExecutionContext(), CmdName()); |
| 6189 | return skip; |
| 6190 | } |
| 6191 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6192 | ResourceUsageTag SyncOpNextSubpass::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6193 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6194 | // TODO PHASE2 Need to fix renderpass tagging/segregation of barrier and access operations for QueueSubmit time validation |
| 6195 | auto prev_tag = cb_context->NextCommandTag(cmd_); |
| 6196 | auto next_tag = cb_context->NextSubcommandTag(cmd_); |
| 6197 | |
| 6198 | cb_context->RecordNextSubpass(prev_tag, next_tag); |
| 6199 | // TODO PHASE2 This needs to be the tag of the barrier operations |
| 6200 | return prev_tag; |
| 6201 | } |
| 6202 | |
| 6203 | bool SyncOpNextSubpass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
| 6204 | CommandBufferAccessContext *active_context) const { |
| 6205 | return false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6206 | } |
| 6207 | |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 6208 | SyncOpEndRenderPass::SyncOpEndRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassEndInfo *pSubpassEndInfo) |
| 6209 | : SyncOpBase(cmd) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6210 | if (pSubpassEndInfo) { |
| 6211 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 6212 | } |
| 6213 | } |
| 6214 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6215 | void SyncOpNextSubpass::DoRecord(ResourceUsageTag tag, AccessContext *access_context, SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6216 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6217 | bool SyncOpEndRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 6218 | bool skip = false; |
| 6219 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 6220 | |
| 6221 | if (!renderpass_context) return skip; |
| 6222 | skip |= renderpass_context->ValidateEndRenderPass(cb_context.GetExecutionContext(), CmdName()); |
| 6223 | return skip; |
| 6224 | } |
| 6225 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6226 | ResourceUsageTag SyncOpEndRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6227 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6228 | const auto tag = cb_context->NextCommandTag(cmd_); |
| 6229 | cb_context->RecordEndRenderPass(tag); |
| 6230 | return tag; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 6231 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6232 | |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6233 | bool SyncOpEndRenderPass::ReplayValidate(ResourceUsageTag recorded_tag, const CommandBufferAccessContext &recorded_context, |
| 6234 | CommandBufferAccessContext *active_context) const { |
| 6235 | return false; |
| 6236 | } |
| 6237 | |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6238 | void SyncOpEndRenderPass::DoRecord(ResourceUsageTag tag, AccessContext *access_context, SyncEventsContext *events_context) const {} |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6239 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 6240 | void SyncValidator::PreCallRecordCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 6241 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
| 6242 | StateTracker::PreCallRecordCmdWriteBufferMarker2AMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
| 6243 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 6244 | assert(cb_access_context); |
| 6245 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 6246 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 6247 | assert(context); |
| 6248 | |
| 6249 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 6250 | |
| 6251 | if (dst_buffer) { |
| 6252 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 6253 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
| 6254 | } |
| 6255 | } |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 6256 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6257 | bool SyncValidator::PreCallValidateCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 6258 | const VkCommandBuffer *pCommandBuffers) const { |
| 6259 | bool skip = StateTracker::PreCallValidateCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
| 6260 | const char *func_name = "vkCmdExecuteCommands"; |
| 6261 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 6262 | assert(cb_context); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6263 | |
| 6264 | // Heavyweight, but we need a proxy copy of the active command buffer access context |
| 6265 | CommandBufferAccessContext proxy_cb_context(*cb_context, CommandBufferAccessContext::AsProxyContext()); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6266 | |
| 6267 | // Make working copies of the access and events contexts |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6268 | proxy_cb_context.NextCommandTag(CMD_EXECUTECOMMANDS); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6269 | |
| 6270 | for (uint32_t cb_index = 0; cb_index < commandBufferCount; ++cb_index) { |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6271 | proxy_cb_context.NextSubcommandTag(CMD_EXECUTECOMMANDS); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6272 | const auto *recorded_cb_context = GetAccessContext(pCommandBuffers[cb_index]); |
| 6273 | if (!recorded_cb_context) continue; |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6274 | |
| 6275 | const auto *recorded_context = recorded_cb_context->GetCurrentAccessContext(); |
| 6276 | assert(recorded_context); |
| 6277 | skip |= recorded_cb_context->ValidateFirstUse(&proxy_cb_context, func_name, cb_index); |
| 6278 | |
| 6279 | // The barriers have already been applied in ValidatFirstUse |
| 6280 | ResourceUsageRange tag_range = proxy_cb_context.ImportRecordedAccessLog(*recorded_cb_context); |
| 6281 | proxy_cb_context.ResolveRecordedContext(*recorded_context, tag_range.begin); |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6282 | } |
| 6283 | |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6284 | return skip; |
| 6285 | } |
| 6286 | |
| 6287 | void SyncValidator::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 6288 | const VkCommandBuffer *pCommandBuffers) { |
| 6289 | StateTracker::PreCallRecordCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
John Zulauf | 4fa6846 | 2021-04-26 21:04:22 -0600 | [diff] [blame] | 6290 | auto *cb_context = GetAccessContext(commandBuffer); |
| 6291 | assert(cb_context); |
| 6292 | cb_context->NextCommandTag(CMD_EXECUTECOMMANDS); |
| 6293 | for (uint32_t cb_index = 0; cb_index < commandBufferCount; ++cb_index) { |
| 6294 | cb_context->NextSubcommandTag(CMD_EXECUTECOMMANDS); |
| 6295 | const auto *recorded_cb_context = GetAccessContext(pCommandBuffers[cb_index]); |
| 6296 | if (!recorded_cb_context) continue; |
| 6297 | cb_context->RecordExecutedCommandBuffer(*recorded_cb_context, CMD_EXECUTECOMMANDS); |
| 6298 | } |
John Zulauf | ae84200 | 2021-04-15 18:20:55 -0600 | [diff] [blame] | 6299 | } |
| 6300 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 6301 | AttachmentViewGen::AttachmentViewGen(const IMAGE_VIEW_STATE *view, const VkOffset3D &offset, const VkExtent3D &extent) |
| 6302 | : view_(view), view_mask_(), gen_store_() { |
| 6303 | if (!view_ || !view_->image_state || !SimpleBinding(*view_->image_state)) return; |
| 6304 | const IMAGE_STATE &image_state = *view_->image_state.get(); |
| 6305 | const auto base_address = ResourceBaseAddress(image_state); |
| 6306 | const auto *encoder = image_state.fragment_encoder.get(); |
| 6307 | if (!encoder) return; |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 6308 | // Get offset and extent for the view, accounting for possible depth slicing |
| 6309 | const VkOffset3D zero_offset = view->GetOffset(); |
| 6310 | const VkExtent3D &image_extent = view->GetExtent(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 6311 | // Intentional copy |
| 6312 | VkImageSubresourceRange subres_range = view_->normalized_subresource_range; |
| 6313 | view_mask_ = subres_range.aspectMask; |
| 6314 | gen_store_[Gen::kViewSubresource].emplace(*encoder, subres_range, zero_offset, image_extent, base_address); |
| 6315 | gen_store_[Gen::kRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 6316 | |
| 6317 | const auto depth = view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT; |
| 6318 | if (depth && (depth != view_mask_)) { |
| 6319 | subres_range.aspectMask = depth; |
| 6320 | gen_store_[Gen::kDepthOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 6321 | } |
| 6322 | const auto stencil = view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT; |
| 6323 | if (stencil && (stencil != view_mask_)) { |
| 6324 | subres_range.aspectMask = stencil; |
| 6325 | gen_store_[Gen::kStencilOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 6326 | } |
| 6327 | } |
| 6328 | |
| 6329 | const ImageRangeGen *AttachmentViewGen::GetRangeGen(AttachmentViewGen::Gen gen_type) const { |
| 6330 | const ImageRangeGen *got = nullptr; |
| 6331 | switch (gen_type) { |
| 6332 | case kViewSubresource: |
| 6333 | got = &gen_store_[kViewSubresource]; |
| 6334 | break; |
| 6335 | case kRenderArea: |
| 6336 | got = &gen_store_[kRenderArea]; |
| 6337 | break; |
| 6338 | case kDepthOnlyRenderArea: |
| 6339 | got = |
| 6340 | (view_mask_ == VK_IMAGE_ASPECT_DEPTH_BIT) ? &gen_store_[Gen::kRenderArea] : &gen_store_[Gen::kDepthOnlyRenderArea]; |
| 6341 | break; |
| 6342 | case kStencilOnlyRenderArea: |
| 6343 | got = (view_mask_ == VK_IMAGE_ASPECT_STENCIL_BIT) ? &gen_store_[Gen::kRenderArea] |
| 6344 | : &gen_store_[Gen::kStencilOnlyRenderArea]; |
| 6345 | break; |
| 6346 | default: |
| 6347 | assert(got); |
| 6348 | } |
| 6349 | return got; |
| 6350 | } |
| 6351 | |
| 6352 | AttachmentViewGen::Gen AttachmentViewGen::GetDepthStencilRenderAreaGenType(bool depth_op, bool stencil_op) const { |
| 6353 | assert(IsValid()); |
| 6354 | assert(view_mask_ & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); |
| 6355 | if (depth_op) { |
| 6356 | assert(view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 6357 | if (stencil_op) { |
| 6358 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 6359 | return kRenderArea; |
| 6360 | } |
| 6361 | return kDepthOnlyRenderArea; |
| 6362 | } |
| 6363 | if (stencil_op) { |
| 6364 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 6365 | return kStencilOnlyRenderArea; |
| 6366 | } |
| 6367 | |
| 6368 | assert(depth_op || stencil_op); |
| 6369 | return kRenderArea; |
| 6370 | } |
| 6371 | |
| 6372 | AccessAddressType AttachmentViewGen::GetAddressType() const { return AccessContext::ImageAddressType(*view_->image_state); } |
John Zulauf | 8eda156 | 2021-04-13 17:06:41 -0600 | [diff] [blame] | 6373 | |
| 6374 | void SyncEventsContext::ApplyBarrier(const SyncExecScope &src, const SyncExecScope &dst) { |
| 6375 | const bool all_commands_bit = 0 != (src.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 6376 | for (auto &event_pair : map_) { |
| 6377 | assert(event_pair.second); // Shouldn't be storing empty |
| 6378 | auto &sync_event = *event_pair.second; |
| 6379 | // Events don't happen at a stage, so we need to check and store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 6380 | if ((sync_event.barriers & src.exec_scope) || all_commands_bit) { |
| 6381 | sync_event.barriers |= dst.exec_scope; |
| 6382 | sync_event.barriers |= dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 6383 | } |
| 6384 | } |
| 6385 | } |