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 | |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 29 | #ifdef SYNCVAL_DIAGNOSTICS |
| 30 | struct SyncDiagnostics { |
| 31 | void DebugAction() const { |
| 32 | #if defined(_WIN32) |
| 33 | __debugbreak(); |
| 34 | #endif |
| 35 | } |
| 36 | void Detect(const ResourceAccessRange &range) { |
| 37 | std::lock_guard<std::mutex> lock(diag_mutex); |
| 38 | if (range.distance() == kConditionValue) { |
| 39 | ++condition; |
| 40 | DebugAction(); |
| 41 | } |
| 42 | detect_histogram[range.distance()] += 1; |
| 43 | } |
| 44 | void InstanceDump(VkInstance instance) { |
| 45 | std::cout << "# instance handle\n" << instance << "\n"; |
| 46 | std::cout << "# condition count\n" << condition << "\n"; |
| 47 | std::cout << "# Detection Size Histogram\n"; |
| 48 | for (const auto &entry : detect_histogram) { |
| 49 | std::cout << "{ " << entry.first << ", " << entry.second << "}\n"; |
| 50 | } |
| 51 | std::cout << std::endl; |
| 52 | detect_histogram.clear(); |
| 53 | } |
| 54 | std::map<ResourceAccessRange::index_type, size_t> detect_histogram; |
| 55 | uint64_t condition; |
| 56 | std::mutex diag_mutex; |
| 57 | static const ResourceAccessRangeIndex kConditionValue = ~ResourceAccessRangeIndex(0); |
| 58 | }; |
| 59 | static SyncDiagnostics sync_diagnostics; |
| 60 | #endif |
| 61 | |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 62 | static bool SimpleBinding(const BINDABLE &bindable) { return !bindable.sparse && bindable.binding.mem_state; } |
| 63 | |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 64 | static bool SimpleBinding(const IMAGE_STATE &image_state) { |
| 65 | bool simple = SimpleBinding(static_cast<const BINDABLE &>(image_state)) || image_state.is_swapchain_image || |
| 66 | (VK_NULL_HANDLE != image_state.bind_swapchain); |
| 67 | |
| 68 | // If it's not simple we must have an encoder. |
| 69 | assert(!simple || image_state.fragment_encoder.get()); |
| 70 | return simple; |
| 71 | } |
| 72 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 73 | const static std::array<AccessAddressType, static_cast<size_t>(AccessAddressType::kTypeCount)> kAddressTypes = { |
| 74 | AccessAddressType::kLinear, AccessAddressType::kIdealized}; |
| 75 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 76 | static constexpr AccessAddressType GetAccessAddressType(const BUFFER_STATE &) { return AccessAddressType::kLinear; }; |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 77 | static AccessAddressType GetAccessAddressType(const IMAGE_STATE &image) { |
| 78 | return SimpleBinding(image) ? AccessContext::ImageAddressType(image) : AccessAddressType::kIdealized; |
| 79 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 80 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 81 | static const char *string_SyncHazardVUID(SyncHazard hazard) { |
| 82 | switch (hazard) { |
| 83 | case SyncHazard::NONE: |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 84 | return "SYNC-HAZARD-NONE"; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 85 | break; |
| 86 | case SyncHazard::READ_AFTER_WRITE: |
| 87 | return "SYNC-HAZARD-READ_AFTER_WRITE"; |
| 88 | break; |
| 89 | case SyncHazard::WRITE_AFTER_READ: |
| 90 | return "SYNC-HAZARD-WRITE_AFTER_READ"; |
| 91 | break; |
| 92 | case SyncHazard::WRITE_AFTER_WRITE: |
| 93 | return "SYNC-HAZARD-WRITE_AFTER_WRITE"; |
| 94 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 95 | case SyncHazard::READ_RACING_WRITE: |
| 96 | return "SYNC-HAZARD-READ-RACING-WRITE"; |
| 97 | break; |
| 98 | case SyncHazard::WRITE_RACING_WRITE: |
| 99 | return "SYNC-HAZARD-WRITE-RACING-WRITE"; |
| 100 | break; |
| 101 | case SyncHazard::WRITE_RACING_READ: |
| 102 | return "SYNC-HAZARD-WRITE-RACING-READ"; |
| 103 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 104 | default: |
| 105 | assert(0); |
| 106 | } |
| 107 | return "SYNC-HAZARD-INVALID"; |
| 108 | } |
| 109 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 110 | static bool IsHazardVsRead(SyncHazard hazard) { |
| 111 | switch (hazard) { |
| 112 | case SyncHazard::NONE: |
| 113 | return false; |
| 114 | break; |
| 115 | case SyncHazard::READ_AFTER_WRITE: |
| 116 | return false; |
| 117 | break; |
| 118 | case SyncHazard::WRITE_AFTER_READ: |
| 119 | return true; |
| 120 | break; |
| 121 | case SyncHazard::WRITE_AFTER_WRITE: |
| 122 | return false; |
| 123 | break; |
| 124 | case SyncHazard::READ_RACING_WRITE: |
| 125 | return false; |
| 126 | break; |
| 127 | case SyncHazard::WRITE_RACING_WRITE: |
| 128 | return false; |
| 129 | break; |
| 130 | case SyncHazard::WRITE_RACING_READ: |
| 131 | return true; |
| 132 | break; |
| 133 | default: |
| 134 | assert(0); |
| 135 | } |
| 136 | return false; |
| 137 | } |
| 138 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 139 | static const char *string_SyncHazard(SyncHazard hazard) { |
| 140 | switch (hazard) { |
| 141 | case SyncHazard::NONE: |
| 142 | return "NONR"; |
| 143 | break; |
| 144 | case SyncHazard::READ_AFTER_WRITE: |
| 145 | return "READ_AFTER_WRITE"; |
| 146 | break; |
| 147 | case SyncHazard::WRITE_AFTER_READ: |
| 148 | return "WRITE_AFTER_READ"; |
| 149 | break; |
| 150 | case SyncHazard::WRITE_AFTER_WRITE: |
| 151 | return "WRITE_AFTER_WRITE"; |
| 152 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 153 | case SyncHazard::READ_RACING_WRITE: |
| 154 | return "READ_RACING_WRITE"; |
| 155 | break; |
| 156 | case SyncHazard::WRITE_RACING_WRITE: |
| 157 | return "WRITE_RACING_WRITE"; |
| 158 | break; |
| 159 | case SyncHazard::WRITE_RACING_READ: |
| 160 | return "WRITE_RACING_READ"; |
| 161 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 162 | default: |
| 163 | assert(0); |
| 164 | } |
| 165 | return "INVALID HAZARD"; |
| 166 | } |
| 167 | |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 168 | static const SyncStageAccessInfoType *SyncStageAccessInfoFromMask(SyncStageAccessFlags flags) { |
| 169 | // Return the info for the first bit found |
| 170 | const SyncStageAccessInfoType *info = nullptr; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 171 | for (size_t i = 0; i < flags.size(); i++) { |
| 172 | if (flags.test(i)) { |
| 173 | info = &syncStageAccessInfoByStageAccessIndex[i]; |
| 174 | break; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | return info; |
| 178 | } |
| 179 | |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 180 | static std::string string_SyncStageAccessFlags(const SyncStageAccessFlags &flags, const char *sep = "|") { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 181 | std::string out_str; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 182 | if (flags.none()) { |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 183 | out_str = "0"; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 184 | } else { |
| 185 | for (size_t i = 0; i < syncStageAccessInfoByStageAccessIndex.size(); i++) { |
| 186 | const auto &info = syncStageAccessInfoByStageAccessIndex[i]; |
| 187 | if ((flags & info.stage_access_bit).any()) { |
| 188 | if (!out_str.empty()) { |
| 189 | out_str.append(sep); |
| 190 | } |
| 191 | out_str.append(info.name); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 192 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 193 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 194 | if (out_str.length() == 0) { |
| 195 | out_str.append("Unhandled SyncStageAccess"); |
| 196 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 197 | } |
| 198 | return out_str; |
| 199 | } |
| 200 | |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 201 | static std::string string_UsageTag(const ResourceUsageTag &tag) { |
| 202 | std::stringstream out; |
| 203 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 204 | out << "command: " << CommandTypeString(tag.command); |
| 205 | out << ", seq_no: " << tag.seq_num; |
| 206 | if (tag.sub_command != 0) { |
| 207 | out << ", subcmd: " << tag.sub_command; |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 208 | } |
| 209 | return out.str(); |
| 210 | } |
| 211 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 212 | std::string CommandBufferAccessContext::FormatUsage(const HazardResult &hazard) const { |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 213 | const auto &tag = hazard.tag; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 214 | assert(hazard.usage_index < static_cast<SyncStageAccessIndex>(syncStageAccessInfoByStageAccessIndex.size())); |
| 215 | const auto &usage_info = syncStageAccessInfoByStageAccessIndex[hazard.usage_index]; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 216 | std::stringstream out; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 217 | const auto *info = SyncStageAccessInfoFromMask(hazard.prior_access); |
| 218 | const char *stage_access_name = info ? info->name : "INVALID_STAGE_ACCESS"; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 219 | out << "(usage: " << usage_info.name << ", prior_usage: " << stage_access_name; |
| 220 | if (IsHazardVsRead(hazard.hazard)) { |
| 221 | const auto barriers = hazard.access_state->GetReadBarriers(hazard.prior_access); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 222 | out << ", read_barriers: " << string_VkPipelineStageFlags2KHR(barriers); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 223 | } else { |
| 224 | SyncStageAccessFlags write_barrier = hazard.access_state->GetWriteBarriers(); |
| 225 | out << ", write_barriers: " << string_SyncStageAccessFlags(write_barrier); |
| 226 | } |
| 227 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 228 | // PHASE2 TODO -- add comand buffer and reset from secondary if applicable |
ZaOniRinku | 56b8647 | 2021-03-23 20:25:05 +0100 | [diff] [blame] | 229 | out << ", " << string_UsageTag(tag) << ", reset_no: " << reset_count_ << ")"; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 230 | return out.str(); |
| 231 | } |
| 232 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 233 | // NOTE: the attachement read flag is put *only* in the access scope and not in the exect scope, since the ordering |
| 234 | // rules apply only to this specific access for this stage, and not the stage as a whole. The ordering detection |
| 235 | // 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] | 236 | 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] | 237 | static const SyncStageAccessFlags kColorAttachmentAccessScope = |
| 238 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_BIT | |
| 239 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT | |
| 240 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE_BIT | |
| 241 | 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] | 242 | static constexpr VkPipelineStageFlags2KHR kDepthStencilAttachmentExecScope = |
| 243 | 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] | 244 | static const SyncStageAccessFlags kDepthStencilAttachmentAccessScope = |
| 245 | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 246 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 247 | 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] | 248 | static constexpr VkPipelineStageFlags2KHR kRasterAttachmentExecScope = kDepthStencilAttachmentExecScope | kColorAttachmentExecScope; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 249 | static const SyncStageAccessFlags kRasterAttachmentAccessScope = kDepthStencilAttachmentAccessScope | kColorAttachmentAccessScope; |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 250 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 251 | ResourceAccessState::OrderingBarriers ResourceAccessState::kOrderingRules = { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 252 | {{VK_PIPELINE_STAGE_2_NONE_KHR, SyncStageAccessFlags()}, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 253 | {kColorAttachmentExecScope, kColorAttachmentAccessScope}, |
| 254 | {kDepthStencilAttachmentExecScope, kDepthStencilAttachmentAccessScope}, |
| 255 | {kRasterAttachmentExecScope, kRasterAttachmentAccessScope}}}; |
| 256 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 257 | // Sometimes we have an internal access conflict, and we using the kCurrentCommandTag to set and detect in temporary/proxy contexts |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 258 | static const ResourceUsageTag kCurrentCommandTag(ResourceUsageTag::kMaxIndex, ResourceUsageTag::kMaxCount, |
| 259 | ResourceUsageTag::kMaxCount, CMD_NONE); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 260 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 261 | static VkDeviceSize ResourceBaseAddress(const BINDABLE &bindable) { |
| 262 | return bindable.binding.offset + bindable.binding.mem_state->fake_base_address; |
| 263 | } |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 264 | static VkDeviceSize ResourceBaseAddress(const IMAGE_STATE &image_state) { |
| 265 | VkDeviceSize base_address; |
| 266 | if (image_state.is_swapchain_image || (VK_NULL_HANDLE != image_state.bind_swapchain)) { |
| 267 | base_address = image_state.swapchain_fake_address; |
| 268 | } else { |
| 269 | base_address = ResourceBaseAddress(static_cast<const BINDABLE &>(image_state)); |
| 270 | } |
| 271 | return base_address; |
| 272 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 273 | |
locke-lunarg | 3c03800 | 2020-04-30 23:08:08 -0600 | [diff] [blame] | 274 | inline VkDeviceSize GetRealWholeSize(VkDeviceSize offset, VkDeviceSize size, VkDeviceSize whole_size) { |
| 275 | if (size == VK_WHOLE_SIZE) { |
| 276 | return (whole_size - offset); |
| 277 | } |
| 278 | return size; |
| 279 | } |
| 280 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 281 | static inline VkDeviceSize GetBufferWholeSize(const BUFFER_STATE &buf_state, VkDeviceSize offset, VkDeviceSize size) { |
| 282 | return GetRealWholeSize(offset, size, buf_state.createInfo.size); |
| 283 | } |
| 284 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 285 | template <typename T> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 286 | static ResourceAccessRange MakeRange(const T &has_offset_and_size) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 287 | return ResourceAccessRange(has_offset_and_size.offset, (has_offset_and_size.offset + has_offset_and_size.size)); |
| 288 | } |
| 289 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 290 | static ResourceAccessRange MakeRange(VkDeviceSize start, VkDeviceSize size) { return ResourceAccessRange(start, (start + size)); } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 291 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 292 | static inline ResourceAccessRange MakeRange(const BUFFER_STATE &buffer, VkDeviceSize offset, VkDeviceSize size) { |
| 293 | return MakeRange(offset, GetBufferWholeSize(buffer, offset, size)); |
| 294 | } |
| 295 | |
| 296 | static inline ResourceAccessRange MakeRange(const BUFFER_VIEW_STATE &buf_view_state) { |
| 297 | return MakeRange(*buf_view_state.buffer_state.get(), buf_view_state.create_info.offset, buf_view_state.create_info.range); |
| 298 | } |
| 299 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 300 | // Range generators for to allow event scope filtration to be limited to the top of the resource access traversal pipeline |
| 301 | // |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 302 | // Note: there is no "begin/end" or reset facility. These are each written as "one time through" generators. |
| 303 | // |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 304 | // Usage: |
| 305 | // Constructor() -- initializes the generator to point to the begin of the space declared. |
| 306 | // * -- the current range of the generator empty signfies end |
| 307 | // ++ -- advance to the next non-empty range (or end) |
| 308 | |
| 309 | // A wrapper for a single range with the same semantics as the actual generators below |
| 310 | template <typename KeyType> |
| 311 | class SingleRangeGenerator { |
| 312 | public: |
| 313 | SingleRangeGenerator(const KeyType &range) : current_(range) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 314 | const KeyType &operator*() const { return current_; } |
| 315 | const KeyType *operator->() const { return ¤t_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 316 | SingleRangeGenerator &operator++() { |
| 317 | current_ = KeyType(); // just one real range |
| 318 | return *this; |
| 319 | } |
| 320 | |
| 321 | bool operator==(const SingleRangeGenerator &other) const { return current_ == other.current_; } |
| 322 | |
| 323 | private: |
| 324 | SingleRangeGenerator() = default; |
| 325 | const KeyType range_; |
| 326 | KeyType current_; |
| 327 | }; |
| 328 | |
| 329 | // Generate the ranges that are the intersection of range and the entries in the FilterMap |
| 330 | template <typename FilterMap, typename KeyType = typename FilterMap::key_type> |
| 331 | class FilteredRangeGenerator { |
| 332 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 333 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 334 | FilteredRangeGenerator() : range_(), filter_(nullptr), filter_pos_(), current_() { |
| 335 | // Default construction for KeyType *must* be empty range |
| 336 | assert(current_.empty()); |
| 337 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 338 | FilteredRangeGenerator(const FilterMap &filter, const KeyType &range) |
| 339 | : range_(range), filter_(&filter), filter_pos_(), current_() { |
| 340 | SeekBegin(); |
| 341 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 342 | FilteredRangeGenerator(const FilteredRangeGenerator &from) = default; |
| 343 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 344 | const KeyType &operator*() const { return current_; } |
| 345 | const KeyType *operator->() const { return ¤t_; } |
| 346 | FilteredRangeGenerator &operator++() { |
| 347 | ++filter_pos_; |
| 348 | UpdateCurrent(); |
| 349 | return *this; |
| 350 | } |
| 351 | |
| 352 | bool operator==(const FilteredRangeGenerator &other) const { return current_ == other.current_; } |
| 353 | |
| 354 | private: |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 355 | void UpdateCurrent() { |
| 356 | if (filter_pos_ != filter_->cend()) { |
| 357 | current_ = range_ & filter_pos_->first; |
| 358 | } else { |
| 359 | current_ = KeyType(); |
| 360 | } |
| 361 | } |
| 362 | void SeekBegin() { |
| 363 | filter_pos_ = filter_->lower_bound(range_); |
| 364 | UpdateCurrent(); |
| 365 | } |
| 366 | const KeyType range_; |
| 367 | const FilterMap *filter_; |
| 368 | typename FilterMap::const_iterator filter_pos_; |
| 369 | KeyType current_; |
| 370 | }; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 371 | using SingleAccessRangeGenerator = SingleRangeGenerator<ResourceAccessRange>; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 372 | using EventSimpleRangeGenerator = FilteredRangeGenerator<SyncEventState::ScopeMap>; |
| 373 | |
| 374 | // Templated to allow for different Range generators or map sources... |
| 375 | |
| 376 | // Generate the ranges that are the intersection of the RangeGen ranges and the entries in the FilterMap |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 377 | template <typename FilterMap, typename RangeGen, typename KeyType = typename FilterMap::key_type> |
| 378 | class FilteredGeneratorGenerator { |
| 379 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 380 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 381 | FilteredGeneratorGenerator() : filter_(nullptr), gen_(), filter_pos_(), current_() { |
| 382 | // Default construction for KeyType *must* be empty range |
| 383 | assert(current_.empty()); |
| 384 | } |
| 385 | FilteredGeneratorGenerator(const FilterMap &filter, RangeGen &gen) : filter_(&filter), gen_(gen), filter_pos_(), current_() { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 386 | SeekBegin(); |
| 387 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 388 | FilteredGeneratorGenerator(const FilteredGeneratorGenerator &from) = default; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 389 | const KeyType &operator*() const { return current_; } |
| 390 | const KeyType *operator->() const { return ¤t_; } |
| 391 | FilteredGeneratorGenerator &operator++() { |
| 392 | KeyType gen_range = GenRange(); |
| 393 | KeyType filter_range = FilterRange(); |
| 394 | current_ = KeyType(); |
| 395 | while (gen_range.non_empty() && filter_range.non_empty() && current_.empty()) { |
| 396 | if (gen_range.end > filter_range.end) { |
| 397 | // if the generated range is beyond the filter_range, advance the filter range |
| 398 | filter_range = AdvanceFilter(); |
| 399 | } else { |
| 400 | gen_range = AdvanceGen(); |
| 401 | } |
| 402 | current_ = gen_range & filter_range; |
| 403 | } |
| 404 | return *this; |
| 405 | } |
| 406 | |
| 407 | bool operator==(const FilteredGeneratorGenerator &other) const { return current_ == other.current_; } |
| 408 | |
| 409 | private: |
| 410 | KeyType AdvanceFilter() { |
| 411 | ++filter_pos_; |
| 412 | auto filter_range = FilterRange(); |
| 413 | if (filter_range.valid()) { |
| 414 | FastForwardGen(filter_range); |
| 415 | } |
| 416 | return filter_range; |
| 417 | } |
| 418 | KeyType AdvanceGen() { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 419 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 420 | auto gen_range = GenRange(); |
| 421 | if (gen_range.valid()) { |
| 422 | FastForwardFilter(gen_range); |
| 423 | } |
| 424 | return gen_range; |
| 425 | } |
| 426 | |
| 427 | KeyType FilterRange() const { return (filter_pos_ != filter_->cend()) ? filter_pos_->first : KeyType(); } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 428 | KeyType GenRange() const { return *gen_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 429 | |
| 430 | KeyType FastForwardFilter(const KeyType &range) { |
| 431 | auto filter_range = FilterRange(); |
| 432 | int retry_count = 0; |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 433 | const static int kRetryLimit = 2; // TODO -- determine whether this limit is optimal |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 434 | while (!filter_range.empty() && (filter_range.end <= range.begin)) { |
| 435 | if (retry_count < kRetryLimit) { |
| 436 | ++filter_pos_; |
| 437 | filter_range = FilterRange(); |
| 438 | retry_count++; |
| 439 | } else { |
| 440 | // Okay we've tried walking, do a seek. |
| 441 | filter_pos_ = filter_->lower_bound(range); |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | return FilterRange(); |
| 446 | } |
| 447 | |
| 448 | // TODO: Consider adding "seek" (or an absolute bound "get" to range generators to make this walk |
| 449 | // faster. |
| 450 | KeyType FastForwardGen(const KeyType &range) { |
| 451 | auto gen_range = GenRange(); |
| 452 | while (!gen_range.empty() && (gen_range.end <= range.begin)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 453 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 454 | gen_range = GenRange(); |
| 455 | } |
| 456 | return gen_range; |
| 457 | } |
| 458 | |
| 459 | void SeekBegin() { |
| 460 | auto gen_range = GenRange(); |
| 461 | if (gen_range.empty()) { |
| 462 | current_ = KeyType(); |
| 463 | filter_pos_ = filter_->cend(); |
| 464 | } else { |
| 465 | filter_pos_ = filter_->lower_bound(gen_range); |
| 466 | current_ = gen_range & FilterRange(); |
| 467 | } |
| 468 | } |
| 469 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 470 | const FilterMap *filter_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 471 | RangeGen gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 472 | typename FilterMap::const_iterator filter_pos_; |
| 473 | KeyType current_; |
| 474 | }; |
| 475 | |
| 476 | using EventImageRangeGenerator = FilteredGeneratorGenerator<SyncEventState::ScopeMap, subresource_adapter::ImageRangeGenerator>; |
| 477 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 478 | static const ResourceAccessRange kFullRange(std::numeric_limits<VkDeviceSize>::min(), std::numeric_limits<VkDeviceSize>::max()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 479 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 480 | ResourceAccessRange GetBufferRange(VkDeviceSize offset, VkDeviceSize buf_whole_size, uint32_t first_index, uint32_t count, |
| 481 | VkDeviceSize stride) { |
| 482 | VkDeviceSize range_start = offset + first_index * stride; |
| 483 | VkDeviceSize range_size = 0; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 484 | if (count == UINT32_MAX) { |
| 485 | range_size = buf_whole_size - range_start; |
| 486 | } else { |
| 487 | range_size = count * stride; |
| 488 | } |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 489 | return MakeRange(range_start, range_size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 490 | } |
| 491 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 492 | SyncStageAccessIndex GetSyncStageAccessIndexsByDescriptorSet(VkDescriptorType descriptor_type, const interface_var &descriptor_data, |
| 493 | VkShaderStageFlagBits stage_flag) { |
| 494 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 495 | assert(stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT); |
| 496 | return SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ; |
| 497 | } |
| 498 | auto stage_access = syncStageAccessMaskByShaderStage.find(stage_flag); |
| 499 | if (stage_access == syncStageAccessMaskByShaderStage.end()) { |
| 500 | assert(0); |
| 501 | } |
| 502 | if (descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) { |
| 503 | return stage_access->second.uniform_read; |
| 504 | } |
| 505 | |
| 506 | // If the desriptorSet is writable, we don't need to care SHADER_READ. SHADER_WRITE is enough. |
| 507 | // Because if write hazard happens, read hazard might or might not happen. |
| 508 | // But if write hazard doesn't happen, read hazard is impossible to happen. |
| 509 | if (descriptor_data.is_writable) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 510 | return stage_access->second.storage_write; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 511 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 512 | // TODO: sampled_read |
| 513 | return stage_access->second.storage_read; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 514 | } |
| 515 | |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 516 | bool IsImageLayoutDepthWritable(VkImageLayout image_layout) { |
| 517 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 518 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL || |
| 519 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) |
| 520 | ? true |
| 521 | : false; |
| 522 | } |
| 523 | |
| 524 | bool IsImageLayoutStencilWritable(VkImageLayout image_layout) { |
| 525 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 526 | image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL || |
| 527 | image_layout == VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL) |
| 528 | ? true |
| 529 | : false; |
| 530 | } |
| 531 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 532 | // 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] | 533 | template <typename Action> |
| 534 | static void ApplyOverImageRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &subresource_range_arg, |
| 535 | Action &action) { |
| 536 | // At this point the "apply over range" logic only supports a single memory binding |
| 537 | if (!SimpleBinding(image_state)) return; |
| 538 | auto subresource_range = NormalizeSubresourceRange(image_state.createInfo, subresource_range_arg); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 539 | const auto base_address = ResourceBaseAddress(image_state); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 540 | subresource_adapter::ImageRangeGenerator range_gen(*image_state.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
| 541 | image_state.createInfo.extent, base_address); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 542 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 543 | action(*range_gen); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 547 | // Tranverse the attachment resolves for this a specific subpass, and do action() to them. |
| 548 | // Used by both validation and record operations |
| 549 | // |
| 550 | // The signature for Action() reflect the needs of both uses. |
| 551 | template <typename Action> |
| 552 | void ResolveOperation(Action &action, const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 553 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass) { |
| 554 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 555 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 556 | const auto &rp_ci = rp_state.createInfo; |
| 557 | const auto *attachment_ci = rp_ci.pAttachments; |
| 558 | const auto &subpass_ci = rp_ci.pSubpasses[subpass]; |
| 559 | |
| 560 | // Color resolves -- require an inuse color attachment and a matching inuse resolve attachment |
| 561 | const auto *color_attachments = subpass_ci.pColorAttachments; |
| 562 | const auto *color_resolve = subpass_ci.pResolveAttachments; |
| 563 | if (color_resolve && color_attachments) { |
| 564 | for (uint32_t i = 0; i < subpass_ci.colorAttachmentCount; i++) { |
| 565 | const auto &color_attach = color_attachments[i].attachment; |
| 566 | const auto &resolve_attach = subpass_ci.pResolveAttachments[i].attachment; |
| 567 | if ((color_attach != VK_ATTACHMENT_UNUSED) && (resolve_attach != VK_ATTACHMENT_UNUSED)) { |
| 568 | action("color", "resolve read", color_attach, resolve_attach, attachment_views[color_attach], |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 569 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, SyncOrdering::kColorAttachment, offset, extent, 0); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 570 | action("color", "resolve write", color_attach, resolve_attach, attachment_views[resolve_attach], |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 571 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment, offset, extent, 0); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | // Depth stencil resolve only if the extension is present |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 577 | const auto ds_resolve = LvlFindInChain<VkSubpassDescriptionDepthStencilResolve>(subpass_ci.pNext); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 578 | if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment && |
| 579 | (ds_resolve->pDepthStencilResolveAttachment->attachment != VK_ATTACHMENT_UNUSED) && subpass_ci.pDepthStencilAttachment && |
| 580 | (subpass_ci.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) { |
| 581 | const auto src_at = subpass_ci.pDepthStencilAttachment->attachment; |
| 582 | const auto src_ci = attachment_ci[src_at]; |
| 583 | // The formats are required to match so we can pick either |
| 584 | const bool resolve_depth = (ds_resolve->depthResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasDepth(src_ci.format); |
| 585 | const bool resolve_stencil = (ds_resolve->stencilResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasStencil(src_ci.format); |
| 586 | const auto dst_at = ds_resolve->pDepthStencilResolveAttachment->attachment; |
| 587 | VkImageAspectFlags aspect_mask = 0u; |
| 588 | |
| 589 | // Figure out which aspects are actually touched during resolve operations |
| 590 | const char *aspect_string = nullptr; |
| 591 | if (resolve_depth && resolve_stencil) { |
| 592 | // Validate all aspects together |
| 593 | aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 594 | aspect_string = "depth/stencil"; |
| 595 | } else if (resolve_depth) { |
| 596 | // Validate depth only |
| 597 | aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 598 | aspect_string = "depth"; |
| 599 | } else if (resolve_stencil) { |
| 600 | // Validate all stencil only |
| 601 | aspect_mask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 602 | aspect_string = "stencil"; |
| 603 | } |
| 604 | |
| 605 | if (aspect_mask) { |
| 606 | action(aspect_string, "resolve read", src_at, dst_at, attachment_views[src_at], |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 607 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, SyncOrdering::kRaster, offset, extent, aspect_mask); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 608 | action(aspect_string, "resolve write", src_at, dst_at, attachment_views[dst_at], |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 609 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, offset, extent, aspect_mask); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | // Action for validating resolve operations |
| 615 | class ValidateResolveAction { |
| 616 | public: |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 617 | ValidateResolveAction(VkRenderPass render_pass, uint32_t subpass, const AccessContext &context, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 618 | const CommandExecutionContext &ex_context, const char *func_name) |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 619 | : render_pass_(render_pass), |
| 620 | subpass_(subpass), |
| 621 | context_(context), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 622 | ex_context_(ex_context), |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 623 | func_name_(func_name), |
| 624 | skip_(false) {} |
| 625 | void operator()(const char *aspect_name, const char *attachment_name, uint32_t src_at, uint32_t dst_at, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 626 | const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 627 | const VkOffset3D &offset, const VkExtent3D &extent, VkImageAspectFlags aspect_mask) { |
| 628 | HazardResult hazard; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 629 | hazard = context_.DetectHazard(view, current_usage, ordering_rule, offset, extent, aspect_mask); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 630 | if (hazard.hazard) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 631 | skip_ |= |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 632 | ex_context_.GetSyncState().LogError(render_pass_, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 633 | "%s: Hazard %s in subpass %" PRIu32 "during %s %s, from attachment %" PRIu32 |
| 634 | " to resolve attachment %" PRIu32 ". Access info %s.", |
| 635 | func_name_, string_SyncHazard(hazard.hazard), subpass_, aspect_name, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 636 | attachment_name, src_at, dst_at, ex_context_.FormatUsage(hazard).c_str()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | // Providing a mechanism for the constructing caller to get the result of the validation |
| 640 | bool GetSkip() const { return skip_; } |
| 641 | |
| 642 | private: |
| 643 | VkRenderPass render_pass_; |
| 644 | const uint32_t subpass_; |
| 645 | const AccessContext &context_; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 646 | const CommandExecutionContext &ex_context_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 647 | const char *func_name_; |
| 648 | bool skip_; |
| 649 | }; |
| 650 | |
| 651 | // Update action for resolve operations |
| 652 | class UpdateStateResolveAction { |
| 653 | public: |
| 654 | UpdateStateResolveAction(AccessContext &context, const ResourceUsageTag &tag) : context_(context), tag_(tag) {} |
| 655 | void operator()(const char *aspect_name, const char *attachment_name, uint32_t src_at, uint32_t dst_at, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 656 | const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 657 | const VkOffset3D &offset, const VkExtent3D &extent, VkImageAspectFlags aspect_mask) { |
| 658 | // Ignores validation only arguments... |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 659 | context_.UpdateAccessState(view, current_usage, ordering_rule, offset, extent, aspect_mask, tag_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | private: |
| 663 | AccessContext &context_; |
| 664 | const ResourceUsageTag &tag_; |
| 665 | }; |
| 666 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 667 | void HazardResult::Set(const ResourceAccessState *access_state_, SyncStageAccessIndex usage_index_, SyncHazard hazard_, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 668 | const SyncStageAccessFlags &prior_, const ResourceUsageTag &tag_) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 669 | access_state = std::unique_ptr<const ResourceAccessState>(new ResourceAccessState(*access_state_)); |
| 670 | usage_index = usage_index_; |
| 671 | hazard = hazard_; |
| 672 | prior_access = prior_; |
| 673 | tag = tag_; |
| 674 | } |
| 675 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 676 | AccessContext::AccessContext(uint32_t subpass, VkQueueFlags queue_flags, |
| 677 | const std::vector<SubpassDependencyGraphNode> &dependencies, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 678 | const std::vector<AccessContext> &contexts, const AccessContext *external_context) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 679 | Reset(); |
| 680 | const auto &subpass_dep = dependencies[subpass]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 681 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 682 | prev_.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 683 | 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] | 684 | for (const auto &prev_dep : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 685 | const auto prev_pass = prev_dep.first->pass; |
| 686 | const auto &prev_barriers = prev_dep.second; |
| 687 | assert(prev_dep.second.size()); |
| 688 | prev_.emplace_back(&contexts[prev_pass], queue_flags, prev_barriers); |
| 689 | prev_by_subpass_[prev_pass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 690 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 691 | |
| 692 | async_.reserve(subpass_dep.async.size()); |
| 693 | for (const auto async_subpass : subpass_dep.async) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 694 | async_.emplace_back(&contexts[async_subpass]); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 695 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 696 | if (has_barrier_from_external) { |
| 697 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 698 | prev_.emplace_back(external_context, queue_flags, subpass_dep.barrier_from_external); |
| 699 | src_external_ = &prev_.back(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 700 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 701 | if (subpass_dep.barrier_to_external.size()) { |
| 702 | dst_external_ = TrackBack(this, queue_flags, subpass_dep.barrier_to_external); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 703 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 704 | } |
| 705 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 706 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 707 | HazardResult AccessContext::DetectPreviousHazard(AccessAddressType type, const Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 708 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 709 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 710 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 711 | |
| 712 | HazardResult hazard; |
| 713 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 714 | hazard = detector.Detect(prev); |
| 715 | } |
| 716 | return hazard; |
| 717 | } |
| 718 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 719 | template <typename Action> |
| 720 | void AccessContext::ForAll(Action &&action) { |
| 721 | for (const auto address_type : kAddressTypes) { |
| 722 | auto &accesses = GetAccessStateMap(address_type); |
| 723 | for (const auto &access : accesses) { |
| 724 | action(address_type, access); |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 729 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 730 | // the DAG of the contexts (for example subpasses) |
| 731 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 732 | HazardResult AccessContext::DetectHazard(AccessAddressType type, const Detector &detector, const ResourceAccessRange &range, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 733 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 734 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 735 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 736 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 737 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 738 | // so we'll check these first |
| 739 | for (const auto &async_context : async_) { |
| 740 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 741 | if (hazard.hazard) return hazard; |
| 742 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 743 | } |
| 744 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 745 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 746 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 747 | const auto &accesses = GetAccessStateMap(type); |
| 748 | const auto from = accesses.lower_bound(range); |
| 749 | const auto to = accesses.upper_bound(range); |
| 750 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 751 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 752 | for (auto pos = from; pos != to; ++pos) { |
| 753 | // Cover any leading gap, or gap between entries |
| 754 | if (detect_prev) { |
| 755 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 756 | // Cover any leading gap, or gap between entries |
| 757 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 758 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 759 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 760 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 761 | if (hazard.hazard) return hazard; |
| 762 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 763 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 764 | gap.begin = pos->first.end; |
| 765 | } |
| 766 | |
| 767 | hazard = detector.Detect(pos); |
| 768 | if (hazard.hazard) return hazard; |
| 769 | } |
| 770 | |
| 771 | if (detect_prev) { |
| 772 | // Detect in the trailing empty as needed |
| 773 | gap.end = range.end; |
| 774 | if (gap.non_empty()) { |
| 775 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 776 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | return hazard; |
| 780 | } |
| 781 | |
| 782 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 783 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 784 | HazardResult AccessContext::DetectAsyncHazard(AccessAddressType type, const Detector &detector, |
| 785 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 786 | auto &accesses = GetAccessStateMap(type); |
| 787 | const auto from = accesses.lower_bound(range); |
| 788 | const auto to = accesses.upper_bound(range); |
| 789 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 790 | HazardResult hazard; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 791 | for (auto pos = from; pos != to && !hazard.hazard; ++pos) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 792 | hazard = detector.DetectAsync(pos, start_tag_); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 793 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 794 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 795 | return hazard; |
| 796 | } |
| 797 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 798 | struct ApplySubpassTransitionBarriersAction { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 799 | explicit ApplySubpassTransitionBarriersAction(const std::vector<SyncBarrier> &barriers_) : barriers(barriers_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 800 | void operator()(ResourceAccessState *access) const { |
| 801 | assert(access); |
| 802 | access->ApplyBarriers(barriers, true); |
| 803 | } |
| 804 | const std::vector<SyncBarrier> &barriers; |
| 805 | }; |
| 806 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 807 | struct ApplyTrackbackStackAction { |
| 808 | explicit ApplyTrackbackStackAction(const std::vector<SyncBarrier> &barriers_, |
| 809 | const ResourceAccessStateFunction *previous_barrier_ = nullptr) |
| 810 | : barriers(barriers_), previous_barrier(previous_barrier_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 811 | void operator()(ResourceAccessState *access) const { |
| 812 | assert(access); |
| 813 | assert(!access->HasPendingState()); |
| 814 | access->ApplyBarriers(barriers, false); |
| 815 | access->ApplyPendingBarriers(kCurrentCommandTag); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 816 | if (previous_barrier) { |
| 817 | assert(bool(*previous_barrier)); |
| 818 | (*previous_barrier)(access); |
| 819 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 820 | } |
| 821 | const std::vector<SyncBarrier> &barriers; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 822 | const ResourceAccessStateFunction *previous_barrier; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 823 | }; |
| 824 | |
| 825 | // Splits a single map entry into piece matching the entries in [first, last) the total range over [first, last) must be |
| 826 | // contained with entry. Entry must be an iterator pointing to dest, first and last must be iterators pointing to a |
| 827 | // *different* map from dest. |
| 828 | // Returns the position past the last resolved range -- the entry covering the remainder of entry->first not included in the |
| 829 | // range [first, last) |
| 830 | template <typename BarrierAction> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 831 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 832 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 833 | BarrierAction &barrier_action) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 834 | auto at = entry; |
| 835 | for (auto pos = first; pos != last; ++pos) { |
| 836 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 837 | assert(at->first.includes(pos->first)); |
| 838 | assert(at != dest->end()); |
| 839 | // Trim up at to the same size as the entry to resolve |
| 840 | at = sparse_container::split(at, *dest, pos->first); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 841 | auto access = pos->second; // intentional copy |
| 842 | barrier_action(&access); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 843 | at->second.Resolve(access); |
| 844 | ++at; // Go to the remaining unused section of entry |
| 845 | } |
| 846 | } |
| 847 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 848 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 849 | SyncBarrier merged = {}; |
| 850 | for (const auto &barrier : barriers) { |
| 851 | merged.Merge(barrier); |
| 852 | } |
| 853 | return merged; |
| 854 | } |
| 855 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 856 | template <typename BarrierAction> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 857 | void AccessContext::ResolveAccessRange(AccessAddressType type, const ResourceAccessRange &range, BarrierAction &barrier_action, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 858 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 859 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 860 | if (!range.non_empty()) return; |
| 861 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 862 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 863 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 864 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 865 | if (current->pos_B->valid) { |
| 866 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 867 | auto access = src_pos->second; // intentional copy |
| 868 | barrier_action(&access); |
| 869 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 870 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 871 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 872 | trimmed->second.Resolve(access); |
| 873 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 874 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 875 | 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] | 876 | 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] | 877 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 878 | } else { |
| 879 | // we have to descend to fill this gap |
| 880 | if (recur_to_infill) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 881 | ResourceAccessRange recurrence_range = current_range; |
| 882 | // The current context is empty for the current range, so recur to fill the gap. |
| 883 | // Since we will be recurring back up the DAG, expand the gap descent to cover the full range for which B |
| 884 | // is not valid, to minimize that recurrence |
| 885 | if (current->pos_B.at_end()) { |
| 886 | // Do the remainder here.... |
| 887 | recurrence_range.end = range.end; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 888 | } else { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 889 | // Recur only over the range until B becomes valid (within the limits of range). |
| 890 | 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] | 891 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 892 | ResolvePreviousAccessStack(type, recurrence_range, resolve_map, infill_state, barrier_action); |
| 893 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 894 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 895 | // iterator of the outer while. |
| 896 | |
| 897 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 898 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 899 | // we stepped on the dest map |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 900 | 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] | 901 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 902 | current.seek(seek_to); |
| 903 | } else if (!current->pos_A->valid && infill_state) { |
| 904 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 905 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 906 | 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] | 907 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 908 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 909 | ++current; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 910 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 911 | |
| 912 | // Infill if range goes passed both the current and resolve map prior contents |
| 913 | if (recur_to_infill && (current->range.end < range.end)) { |
| 914 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 915 | ResolvePreviousAccessStack<BarrierAction>(type, trailing_fill_range, resolve_map, infill_state, barrier_action); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 916 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 917 | } |
| 918 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 919 | template <typename BarrierAction> |
| 920 | void AccessContext::ResolvePreviousAccessStack(AccessAddressType type, const ResourceAccessRange &range, |
| 921 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 922 | const BarrierAction &previous_barrier) const { |
| 923 | ResourceAccessStateFunction stacked_barrier(std::ref(previous_barrier)); |
| 924 | ResolvePreviousAccess(type, range, descent_map, infill_state, &stacked_barrier); |
| 925 | } |
| 926 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 927 | void AccessContext::ResolvePreviousAccess(AccessAddressType type, const ResourceAccessRange &range, |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 928 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 929 | const ResourceAccessStateFunction *previous_barrier) const { |
| 930 | if (prev_.size() == 0) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 931 | if (range.non_empty() && infill_state) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 932 | // Fill the empty poritions of descent_map with the default_state with the barrier function applied (iff present) |
| 933 | ResourceAccessState state_copy; |
| 934 | if (previous_barrier) { |
| 935 | assert(bool(*previous_barrier)); |
| 936 | state_copy = *infill_state; |
| 937 | (*previous_barrier)(&state_copy); |
| 938 | infill_state = &state_copy; |
| 939 | } |
| 940 | sparse_container::update_range_value(*descent_map, range, *infill_state, |
| 941 | sparse_container::value_precedence::prefer_dest); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 942 | } |
| 943 | } else { |
| 944 | // Look for something to fill the gap further along. |
| 945 | for (const auto &prev_dep : prev_) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 946 | const ApplyTrackbackStackAction barrier_action(prev_dep.barriers, previous_barrier); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 947 | prev_dep.context->ResolveAccessRange(type, range, barrier_action, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 948 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 949 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 950 | } |
| 951 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 952 | // Non-lazy import of all accesses, WaitEvents needs this. |
| 953 | void AccessContext::ResolvePreviousAccesses() { |
| 954 | ResourceAccessState default_state; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 955 | if (!prev_.size()) return; // If no previous contexts, nothing to do |
| 956 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 957 | for (const auto address_type : kAddressTypes) { |
| 958 | ResolvePreviousAccess(address_type, kFullRange, &GetAccessStateMap(address_type), &default_state); |
| 959 | } |
| 960 | } |
| 961 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 962 | AccessAddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
| 963 | return (image.fragment_encoder->IsLinearImage()) ? AccessAddressType::kLinear : AccessAddressType::kIdealized; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 964 | } |
| 965 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 966 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
| 967 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 968 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE; |
| 969 | return stage_access; |
| 970 | } |
| 971 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
| 972 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 973 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE; |
| 974 | return stage_access; |
| 975 | } |
| 976 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 977 | // Caller must manage returned pointer |
| 978 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
| 979 | uint32_t subpass, const VkRect2D &render_area, |
| 980 | std::vector<const IMAGE_VIEW_STATE *> attachment_views) { |
| 981 | auto *proxy = new AccessContext(context); |
| 982 | proxy->UpdateAttachmentResolveAccess(rp_state, render_area, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 983 | proxy->UpdateAttachmentStoreAccess(rp_state, render_area, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 984 | return proxy; |
| 985 | } |
| 986 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 987 | template <typename BarrierAction> |
John Zulauf | 52446eb | 2020-10-22 16:40:08 -0600 | [diff] [blame] | 988 | class ResolveAccessRangeFunctor { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 989 | public: |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 990 | ResolveAccessRangeFunctor(const AccessContext &context, AccessAddressType address_type, ResourceAccessRangeMap *descent_map, |
| 991 | const ResourceAccessState *infill_state, BarrierAction &barrier_action) |
John Zulauf | 52446eb | 2020-10-22 16:40:08 -0600 | [diff] [blame] | 992 | : context_(context), |
| 993 | address_type_(address_type), |
| 994 | descent_map_(descent_map), |
| 995 | infill_state_(infill_state), |
| 996 | barrier_action_(barrier_action) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 997 | ResolveAccessRangeFunctor() = delete; |
| 998 | void operator()(const ResourceAccessRange &range) const { |
| 999 | context_.ResolveAccessRange(address_type_, range, barrier_action_, descent_map_, infill_state_); |
| 1000 | } |
| 1001 | |
| 1002 | private: |
John Zulauf | 52446eb | 2020-10-22 16:40:08 -0600 | [diff] [blame] | 1003 | const AccessContext &context_; |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1004 | const AccessAddressType address_type_; |
John Zulauf | 52446eb | 2020-10-22 16:40:08 -0600 | [diff] [blame] | 1005 | ResourceAccessRangeMap *const descent_map_; |
| 1006 | const ResourceAccessState *infill_state_; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1007 | BarrierAction &barrier_action_; |
| 1008 | }; |
| 1009 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1010 | template <typename BarrierAction> |
| 1011 | void AccessContext::ResolveAccessRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1012 | BarrierAction &barrier_action, AccessAddressType address_type, |
| 1013 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state) const { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1014 | const ResolveAccessRangeFunctor<BarrierAction> action(*this, address_type, descent_map, infill_state, barrier_action); |
| 1015 | ApplyOverImageRange(image_state, subresource_range, action); |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 1016 | } |
| 1017 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1018 | // 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] | 1019 | 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] | 1020 | const VkRect2D &render_area, uint32_t subpass, |
| 1021 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 1022 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1023 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1024 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 1025 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 1026 | // those affects have not been recorded yet. |
| 1027 | // |
| 1028 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 1029 | // to apply and only copy then, if this proves a hot spot. |
| 1030 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 1031 | TrackBack proxy_track_back; |
| 1032 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1033 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 1034 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1035 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 1036 | |
| 1037 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 1038 | assert(track_back); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1039 | if (prev_needs_proxy) { |
| 1040 | if (!proxy_for_prev) { |
| 1041 | proxy_for_prev.reset(CreateStoreResolveProxyContext(*track_back->context, rp_state, transition.prev_pass, |
| 1042 | render_area, attachment_views)); |
| 1043 | proxy_track_back = *track_back; |
| 1044 | proxy_track_back.context = proxy_for_prev.get(); |
| 1045 | } |
| 1046 | track_back = &proxy_track_back; |
| 1047 | } |
| 1048 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1049 | if (hazard.hazard) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1050 | skip |= ex_context.GetSyncState().LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1051 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1052 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 1053 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1054 | string_VkImageLayout(transition.old_layout), |
| 1055 | string_VkImageLayout(transition.new_layout), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1056 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | return skip; |
| 1060 | } |
| 1061 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1062 | 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] | 1063 | const VkRect2D &render_area, uint32_t subpass, |
| 1064 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 1065 | const char *func_name) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1066 | bool skip = false; |
| 1067 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 1068 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1069 | VkOffset3D offset = CastTo3D(render_area.offset); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1070 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1071 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1072 | if (subpass == rp_state.attachment_first_subpass[i]) { |
| 1073 | if (attachment_views[i] == nullptr) continue; |
| 1074 | const IMAGE_VIEW_STATE &view = *attachment_views[i]; |
| 1075 | const IMAGE_STATE *image = view.image_state.get(); |
| 1076 | if (image == nullptr) continue; |
| 1077 | const auto &ci = attachment_ci[i]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1078 | |
| 1079 | // Need check in the following way |
| 1080 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 1081 | // vs. transition |
| 1082 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 1083 | // for each aspect loaded. |
| 1084 | |
| 1085 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1086 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1087 | const bool is_color = !(has_depth || has_stencil); |
| 1088 | |
| 1089 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1090 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1091 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1092 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1093 | const char *aspect = nullptr; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1094 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1095 | auto hazard_range = view.normalized_subresource_range; |
| 1096 | bool checked_stencil = false; |
| 1097 | if (is_color) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1098 | hazard = DetectHazard(*image, load_index, view.normalized_subresource_range, SyncOrdering::kColorAttachment, offset, |
John Zulauf | 859089b | 2020-10-29 17:37:03 -0600 | [diff] [blame] | 1099 | extent); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1100 | aspect = "color"; |
| 1101 | } else { |
| 1102 | if (has_depth) { |
| 1103 | hazard_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1104 | hazard = DetectHazard(*image, load_index, hazard_range, SyncOrdering::kDepthStencilAttachment, offset, extent); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1105 | aspect = "depth"; |
| 1106 | } |
| 1107 | if (!hazard.hazard && has_stencil) { |
| 1108 | hazard_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1109 | hazard = DetectHazard(*image, stencil_load_index, hazard_range, SyncOrdering::kDepthStencilAttachment, offset, |
| 1110 | extent); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1111 | aspect = "stencil"; |
| 1112 | checked_stencil = true; |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | if (hazard.hazard) { |
| 1117 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1118 | const auto &sync_state = ex_context.GetSyncState(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1119 | if (hazard.tag == kCurrentCommandTag) { |
| 1120 | // Hazard vs. ILT |
| 1121 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 1122 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1123 | " aspect %s during load with loadOp %s.", |
| 1124 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string); |
| 1125 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1126 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 1127 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1128 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1129 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1130 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | return skip; |
| 1136 | } |
| 1137 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1138 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 1139 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 1140 | // store is part of the same Next/End operation. |
| 1141 | // The latter is handled in layout transistion validation directly |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1142 | 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] | 1143 | const VkRect2D &render_area, uint32_t subpass, |
| 1144 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 1145 | const char *func_name) const { |
| 1146 | bool skip = false; |
| 1147 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 1148 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1149 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 1150 | |
| 1151 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1152 | if (subpass == rp_state.attachment_last_subpass[i]) { |
| 1153 | if (attachment_views[i] == nullptr) continue; |
| 1154 | const IMAGE_VIEW_STATE &view = *attachment_views[i]; |
| 1155 | const IMAGE_STATE *image = view.image_state.get(); |
| 1156 | if (image == nullptr) continue; |
| 1157 | const auto &ci = attachment_ci[i]; |
| 1158 | |
| 1159 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1160 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 1161 | // sake, we treat DONT_CARE as writing. |
| 1162 | const bool has_depth = FormatHasDepth(ci.format); |
| 1163 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1164 | const bool is_color = !(has_depth || has_stencil); |
| 1165 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1166 | if (!has_stencil && !store_op_stores) continue; |
| 1167 | |
| 1168 | HazardResult hazard; |
| 1169 | const char *aspect = nullptr; |
| 1170 | bool checked_stencil = false; |
| 1171 | if (is_color) { |
| 1172 | hazard = DetectHazard(*image, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1173 | view.normalized_subresource_range, SyncOrdering::kRaster, offset, extent); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1174 | aspect = "color"; |
| 1175 | } else { |
| 1176 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1177 | auto hazard_range = view.normalized_subresource_range; |
| 1178 | if (has_depth && store_op_stores) { |
| 1179 | hazard_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 1180 | hazard = DetectHazard(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, hazard_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1181 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1182 | aspect = "depth"; |
| 1183 | } |
| 1184 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
| 1185 | hazard_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 1186 | hazard = DetectHazard(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, hazard_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1187 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1188 | aspect = "stencil"; |
| 1189 | checked_stencil = true; |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | if (hazard.hazard) { |
| 1194 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 1195 | const char *const store_op_string = string_VkAttachmentStoreOp(checked_stencil ? ci.stencilStoreOp : ci.storeOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1196 | skip |= ex_context.GetSyncState().LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1197 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1198 | " %s aspect during store with %s %s. Access info %s", |
| 1199 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1200 | op_type_string, store_op_string, ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | return skip; |
| 1205 | } |
| 1206 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1207 | bool AccessContext::ValidateResolveOperations(const CommandExecutionContext &ex_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1208 | const VkRect2D &render_area, |
| 1209 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, const char *func_name, |
| 1210 | uint32_t subpass) const { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1211 | ValidateResolveAction validate_action(rp_state.renderPass, subpass, *this, ex_context, func_name); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1212 | ResolveOperation(validate_action, rp_state, render_area, attachment_views, subpass); |
| 1213 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1214 | } |
| 1215 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1216 | class HazardDetector { |
| 1217 | SyncStageAccessIndex usage_index_; |
| 1218 | |
| 1219 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1220 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { return pos->second.DetectHazard(usage_index_); } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1221 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1222 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1223 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1224 | explicit HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1225 | }; |
| 1226 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1227 | class HazardDetectorWithOrdering { |
| 1228 | const SyncStageAccessIndex usage_index_; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1229 | const SyncOrdering ordering_rule_; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1230 | |
| 1231 | public: |
| 1232 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1233 | return pos->second.DetectHazard(usage_index_, ordering_rule_); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1234 | } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1235 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1236 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1237 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1238 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, SyncOrdering ordering) : usage_index_(usage), ordering_rule_(ordering) {} |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1239 | }; |
| 1240 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1241 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1242 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1243 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1244 | const auto base_address = ResourceBaseAddress(buffer); |
| 1245 | HazardDetector detector(usage_index); |
| 1246 | return DetectHazard(AccessAddressType::kLinear, detector, (range + base_address), DetectOptions::kDetectAll); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 1247 | } |
| 1248 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1249 | template <typename Detector> |
| 1250 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1251 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1252 | const VkExtent3D &extent, DetectOptions options) const { |
| 1253 | if (!SimpleBinding(image)) return HazardResult(); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1254 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1255 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1256 | base_address); |
| 1257 | const auto address_type = ImageAddressType(image); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1258 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 1259 | #ifdef SYNCVAL_DIAGNOSTICS |
| 1260 | sync_diagnostics.Detect(*range_gen); |
| 1261 | #endif |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1262 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1263 | if (hazard.hazard) return hazard; |
| 1264 | } |
| 1265 | return HazardResult(); |
| 1266 | } |
| 1267 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1268 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1269 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1270 | const VkExtent3D &extent) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1271 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1272 | subresource.layerCount}; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1273 | return DetectHazard(image, current_usage, subresource_range, offset, extent); |
| 1274 | } |
| 1275 | |
| 1276 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1277 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1278 | const VkExtent3D &extent) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1279 | HazardDetector detector(current_usage); |
| 1280 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
| 1281 | } |
| 1282 | |
| 1283 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1284 | const VkImageSubresourceRange &subresource_range, SyncOrdering ordering_rule, |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1285 | const VkOffset3D &offset, const VkExtent3D &extent) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1286 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1287 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1288 | } |
| 1289 | |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1290 | // Some common code for looking at attachments, if there's anything wrong, we return no hazard, core validation |
| 1291 | // should have reported the issue regarding an invalid attachment entry |
| 1292 | HazardResult AccessContext::DetectHazard(const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1293 | SyncOrdering ordering_rule, const VkOffset3D &offset, const VkExtent3D &extent, |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1294 | VkImageAspectFlags aspect_mask) const { |
| 1295 | if (view != nullptr) { |
| 1296 | const IMAGE_STATE *image = view->image_state.get(); |
| 1297 | if (image != nullptr) { |
| 1298 | auto *detect_range = &view->normalized_subresource_range; |
| 1299 | VkImageSubresourceRange masked_range; |
| 1300 | if (aspect_mask) { // If present and non-zero, restrict the normalized range to aspects present in aspect_mask |
| 1301 | masked_range = view->normalized_subresource_range; |
| 1302 | masked_range.aspectMask = aspect_mask & masked_range.aspectMask; |
| 1303 | detect_range = &masked_range; |
| 1304 | } |
| 1305 | |
| 1306 | // NOTE: The range encoding code is not robust to invalid ranges, so we protect it from our change |
| 1307 | if (detect_range->aspectMask) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1308 | return DetectHazard(*image, current_usage, *detect_range, ordering_rule, offset, extent); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | return HazardResult(); |
| 1313 | } |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1314 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1315 | class BarrierHazardDetector { |
| 1316 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1317 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1318 | SyncStageAccessFlags src_access_scope) |
| 1319 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1320 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1321 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1322 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1323 | } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1324 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1325 | // 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] | 1326 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | private: |
| 1330 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1331 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1332 | SyncStageAccessFlags src_access_scope_; |
| 1333 | }; |
| 1334 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1335 | class EventBarrierHazardDetector { |
| 1336 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1337 | EventBarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1338 | SyncStageAccessFlags src_access_scope, const SyncEventState::ScopeMap &event_scope, |
| 1339 | const ResourceUsageTag &scope_tag) |
| 1340 | : usage_index_(usage_index), |
| 1341 | src_exec_scope_(src_exec_scope), |
| 1342 | src_access_scope_(src_access_scope), |
| 1343 | event_scope_(event_scope), |
| 1344 | scope_pos_(event_scope.cbegin()), |
| 1345 | scope_end_(event_scope.cend()), |
| 1346 | scope_tag_(scope_tag) {} |
| 1347 | |
| 1348 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1349 | // TODO NOTE: This is almost the slowest way to do this... need to intelligently walk this... |
| 1350 | // Need to find a more efficient sync, since we know pos->first is strictly increasing call to call |
| 1351 | // NOTE: "cached_lower_bound_impl" with upgrades could do this. |
| 1352 | if (scope_pos_ == scope_end_) return HazardResult(); |
| 1353 | if (!scope_pos_->first.intersects(pos->first)) { |
| 1354 | event_scope_.lower_bound(pos->first); |
| 1355 | if ((scope_pos_ == scope_end_) || !scope_pos_->first.intersects(pos->first)) return HazardResult(); |
| 1356 | } |
| 1357 | |
| 1358 | // Some portion of this pos is in the event_scope, so check for a barrier hazard |
| 1359 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_, scope_tag_); |
| 1360 | } |
| 1361 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1362 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1363 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
| 1364 | } |
| 1365 | |
| 1366 | private: |
| 1367 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1368 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1369 | SyncStageAccessFlags src_access_scope_; |
| 1370 | const SyncEventState::ScopeMap &event_scope_; |
| 1371 | SyncEventState::ScopeMap::const_iterator scope_pos_; |
| 1372 | SyncEventState::ScopeMap::const_iterator scope_end_; |
| 1373 | const ResourceUsageTag &scope_tag_; |
| 1374 | }; |
| 1375 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1376 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1377 | const SyncStageAccessFlags &src_access_scope, |
| 1378 | const VkImageSubresourceRange &subresource_range, |
| 1379 | const SyncEventState &sync_event, DetectOptions options) const { |
| 1380 | // It's not particularly DRY to get the address type in this function as well as lower down, but we have to select the |
| 1381 | // first access scope map to use, and there's no easy way to plumb it in below. |
| 1382 | const auto address_type = ImageAddressType(image); |
| 1383 | const auto &event_scope = sync_event.FirstScope(address_type); |
| 1384 | |
| 1385 | EventBarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope, |
| 1386 | event_scope, sync_event.first_scope_tag); |
| 1387 | VkOffset3D zero_offset = {0, 0, 0}; |
| 1388 | return DetectHazard(detector, image, subresource_range, zero_offset, image.createInfo.extent, options); |
| 1389 | } |
| 1390 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1391 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1392 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1393 | const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1394 | const DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1395 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope); |
| 1396 | VkOffset3D zero_offset = {0, 0, 0}; |
| 1397 | return DetectHazard(detector, image, subresource_range, zero_offset, image.createInfo.extent, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1400 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1401 | const SyncStageAccessFlags &src_stage_accesses, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1402 | const VkImageMemoryBarrier &barrier) const { |
| 1403 | auto subresource_range = NormalizeSubresourceRange(image.createInfo, barrier.subresourceRange); |
| 1404 | const auto src_access_scope = SyncStageAccess::AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 1405 | return DetectImageBarrierHazard(image, src_exec_scope, src_access_scope, subresource_range, kDetectAll); |
| 1406 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1407 | HazardResult AccessContext::DetectImageBarrierHazard(const SyncImageMemoryBarrier &image_barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1408 | return DetectImageBarrierHazard(*image_barrier.image.get(), image_barrier.barrier.src_exec_scope.exec_scope, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1409 | image_barrier.barrier.src_access_scope, image_barrier.range.subresource_range, kDetectAll); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1410 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1411 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1412 | template <typename Flags, typename Map> |
| 1413 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1414 | SyncStageAccessFlags scope = 0; |
| 1415 | for (const auto &bit_scope : map) { |
| 1416 | if (flag_mask < bit_scope.first) break; |
| 1417 | |
| 1418 | if (flag_mask & bit_scope.first) { |
| 1419 | scope |= bit_scope.second; |
| 1420 | } |
| 1421 | } |
| 1422 | return scope; |
| 1423 | } |
| 1424 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1425 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags2KHR stages) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1426 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1427 | } |
| 1428 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1429 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags2KHR accesses) { |
| 1430 | return AccessScopeImpl(sync_utils::ExpandAccessFlags(accesses), syncStageAccessMaskByAccessBit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1431 | } |
| 1432 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1433 | // Getting from stage mask and access mask to stage/access masks is something we need to be good at... |
| 1434 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags2KHR stages, VkAccessFlags2KHR accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1435 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1436 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1437 | // 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] | 1438 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1439 | } |
| 1440 | |
| 1441 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1442 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1443 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1444 | // that do incrementalupdates |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1445 | assert(accesses); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1446 | auto pos = accesses->lower_bound(range); |
| 1447 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1448 | // The range is empty, fill it with a default value. |
| 1449 | pos = action.Infill(accesses, pos, range); |
| 1450 | } else if (range.begin < pos->first.begin) { |
| 1451 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1452 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1453 | } else if (pos->first.begin < range.begin) { |
| 1454 | // Trim the beginning if needed |
| 1455 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1456 | ++pos; |
| 1457 | } |
| 1458 | |
| 1459 | const auto the_end = accesses->end(); |
| 1460 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1461 | if (pos->first.end > range.end) { |
| 1462 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1463 | } |
| 1464 | |
| 1465 | pos = action(accesses, pos); |
| 1466 | if (pos == the_end) break; |
| 1467 | |
| 1468 | auto next = pos; |
| 1469 | ++next; |
| 1470 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1471 | // Need to infill if next is disjoint |
| 1472 | 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] | 1473 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1474 | next = action.Infill(accesses, next, new_range); |
| 1475 | } |
| 1476 | pos = next; |
| 1477 | } |
| 1478 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1479 | |
| 1480 | // Give a comparable interface for range generators and ranges |
| 1481 | template <typename Action> |
| 1482 | inline void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, ResourceAccessRange *range) { |
| 1483 | assert(range); |
| 1484 | UpdateMemoryAccessState(accesses, *range, action); |
| 1485 | } |
| 1486 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1487 | template <typename Action, typename RangeGen> |
| 1488 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, RangeGen *range_gen_arg) { |
| 1489 | assert(range_gen_arg); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1490 | 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] | 1491 | for (; range_gen->non_empty(); ++range_gen) { |
| 1492 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1493 | } |
| 1494 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1495 | |
| 1496 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1497 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1498 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1499 | // this is only called on gaps, and never returns a gap. |
| 1500 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1501 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1502 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1503 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1504 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1505 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1506 | auto &access_state = pos->second; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1507 | access_state.Update(usage, ordering_rule, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1508 | return pos; |
| 1509 | } |
| 1510 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1511 | UpdateMemoryAccessStateFunctor(AccessAddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1512 | SyncOrdering ordering_rule_, const ResourceUsageTag &tag_) |
| 1513 | : type(type_), context(context_), usage(usage_), ordering_rule(ordering_rule_), tag(tag_) {} |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1514 | const AccessAddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1515 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1516 | const SyncStageAccessIndex usage; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1517 | const SyncOrdering ordering_rule; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1518 | const ResourceUsageTag &tag; |
| 1519 | }; |
| 1520 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1521 | // The barrier operation for pipeline and subpass dependencies` |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1522 | struct PipelineBarrierOp { |
| 1523 | SyncBarrier barrier; |
| 1524 | bool layout_transition; |
| 1525 | PipelineBarrierOp(const SyncBarrier &barrier_, bool layout_transition_) |
| 1526 | : barrier(barrier_), layout_transition(layout_transition_) {} |
| 1527 | PipelineBarrierOp() = default; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1528 | PipelineBarrierOp(const PipelineBarrierOp &) = default; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1529 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(barrier, layout_transition); } |
| 1530 | }; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1531 | // The barrier operation for wait events |
| 1532 | struct WaitEventBarrierOp { |
| 1533 | const ResourceUsageTag *scope_tag; |
| 1534 | SyncBarrier barrier; |
| 1535 | bool layout_transition; |
| 1536 | WaitEventBarrierOp(const ResourceUsageTag &scope_tag_, const SyncBarrier &barrier_, bool layout_transition_) |
| 1537 | : scope_tag(&scope_tag_), barrier(barrier_), layout_transition(layout_transition_) {} |
| 1538 | WaitEventBarrierOp() = default; |
| 1539 | void operator()(ResourceAccessState *access_state) const { |
| 1540 | assert(scope_tag); // Not valid to have a non-scope op executed, default construct included for std::vector support |
| 1541 | access_state->ApplyBarrier(*scope_tag, barrier, layout_transition); |
| 1542 | } |
| 1543 | }; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1544 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1545 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1546 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1547 | // of a collection is known/present. |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1548 | template <typename BarrierOp> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1549 | class ApplyBarrierOpsFunctor { |
| 1550 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1551 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1552 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1553 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1554 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1555 | auto &access_state = pos->second; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1556 | for (const auto &op : barrier_ops_) { |
| 1557 | op(&access_state); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1558 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1559 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1560 | if (resolve_) { |
| 1561 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1562 | // another walk |
| 1563 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1564 | } |
| 1565 | return pos; |
| 1566 | } |
| 1567 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1568 | // A valid tag is required IFF layout_transition is true, as transitions are write ops |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1569 | ApplyBarrierOpsFunctor(bool resolve, size_t size_hint, const ResourceUsageTag &tag) |
| 1570 | : resolve_(resolve), barrier_ops_(), tag_(tag) { |
| 1571 | barrier_ops_.reserve(size_hint); |
| 1572 | } |
| 1573 | void EmplaceBack(const BarrierOp &op) { barrier_ops_.emplace_back(op); } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1574 | |
| 1575 | private: |
| 1576 | bool resolve_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1577 | std::vector<BarrierOp> barrier_ops_; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1578 | const ResourceUsageTag &tag_; |
| 1579 | }; |
| 1580 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1581 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1582 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1583 | template <typename BarrierOp> |
| 1584 | class ApplyBarrierFunctor { |
| 1585 | public: |
| 1586 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1587 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
| 1588 | |
| 1589 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
| 1590 | auto &access_state = pos->second; |
| 1591 | barrier_op_(&access_state); |
| 1592 | return pos; |
| 1593 | } |
| 1594 | |
| 1595 | ApplyBarrierFunctor(const BarrierOp &barrier_op) : barrier_op_(barrier_op) {} |
| 1596 | |
| 1597 | private: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1598 | BarrierOp barrier_op_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1599 | }; |
| 1600 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1601 | // This functor resolves the pendinging state. |
| 1602 | class ResolvePendingBarrierFunctor { |
| 1603 | public: |
| 1604 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1605 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
| 1606 | |
| 1607 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
| 1608 | auto &access_state = pos->second; |
| 1609 | access_state.ApplyPendingBarriers(tag_); |
| 1610 | return pos; |
| 1611 | } |
| 1612 | |
| 1613 | ResolvePendingBarrierFunctor(const ResourceUsageTag &tag) : tag_(tag) {} |
| 1614 | |
| 1615 | private: |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1616 | const ResourceUsageTag &tag_; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1617 | }; |
| 1618 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1619 | void AccessContext::UpdateAccessState(AccessAddressType type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
| 1620 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
| 1621 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1622 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1623 | } |
| 1624 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1625 | void AccessContext::UpdateAccessState(const BUFFER_STATE &buffer, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1626 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1627 | if (!SimpleBinding(buffer)) return; |
| 1628 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1629 | UpdateAccessState(AccessAddressType::kLinear, current_usage, ordering_rule, range + base_address, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1630 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1631 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1632 | 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] | 1633 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1634 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1635 | if (!SimpleBinding(image)) return; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1636 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1637 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1638 | base_address); |
| 1639 | const auto address_type = ImageAddressType(image); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1640 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1641 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1642 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), *range_gen, action); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1643 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1644 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1645 | void AccessContext::UpdateAccessState(const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
| 1646 | const VkOffset3D &offset, const VkExtent3D &extent, VkImageAspectFlags aspect_mask, |
| 1647 | const ResourceUsageTag &tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1648 | if (view != nullptr) { |
| 1649 | const IMAGE_STATE *image = view->image_state.get(); |
| 1650 | if (image != nullptr) { |
| 1651 | auto *update_range = &view->normalized_subresource_range; |
| 1652 | VkImageSubresourceRange masked_range; |
| 1653 | if (aspect_mask) { // If present and non-zero, restrict the normalized range to aspects present in aspect_mask |
| 1654 | masked_range = view->normalized_subresource_range; |
| 1655 | masked_range.aspectMask = aspect_mask & masked_range.aspectMask; |
| 1656 | update_range = &masked_range; |
| 1657 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1658 | UpdateAccessState(*image, current_usage, ordering_rule, *update_range, offset, extent, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1659 | } |
| 1660 | } |
| 1661 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1662 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1663 | 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] | 1664 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1665 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1666 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1667 | subresource.layerCount}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1668 | UpdateAccessState(image, current_usage, ordering_rule, subresource_range, offset, extent, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1669 | } |
| 1670 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1671 | template <typename Action> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1672 | void AccessContext::UpdateResourceAccess(const BUFFER_STATE &buffer, const ResourceAccessRange &range, const Action action) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1673 | if (!SimpleBinding(buffer)) return; |
| 1674 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1675 | UpdateMemoryAccessState(&GetAccessStateMap(AccessAddressType::kLinear), (range + base_address), action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | template <typename Action> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1679 | void AccessContext::UpdateResourceAccess(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range, |
| 1680 | const Action action) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1681 | if (!SimpleBinding(image)) return; |
| 1682 | const auto address_type = ImageAddressType(image); |
| 1683 | auto *accesses = &GetAccessStateMap(address_type); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1684 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1685 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1686 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
| 1687 | image.createInfo.extent, base_address); |
| 1688 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1689 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1690 | UpdateMemoryAccessState(accesses, *range_gen, action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1691 | } |
| 1692 | } |
| 1693 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1694 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 1695 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass, |
| 1696 | const ResourceUsageTag &tag) { |
| 1697 | UpdateStateResolveAction update(*this, tag); |
| 1698 | ResolveOperation(update, rp_state, render_area, attachment_views, subpass); |
| 1699 | } |
| 1700 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1701 | void AccessContext::UpdateAttachmentStoreAccess(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 1702 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass, |
| 1703 | const ResourceUsageTag &tag) { |
| 1704 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 1705 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1706 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 1707 | |
| 1708 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1709 | if (rp_state.attachment_last_subpass[i] == subpass) { |
| 1710 | if (attachment_views[i] == nullptr) continue; // UNUSED |
| 1711 | const auto &view = *attachment_views[i]; |
| 1712 | const IMAGE_STATE *image = view.image_state.get(); |
| 1713 | if (image == nullptr) continue; |
| 1714 | |
| 1715 | const auto &ci = attachment_ci[i]; |
| 1716 | const bool has_depth = FormatHasDepth(ci.format); |
| 1717 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1718 | const bool is_color = !(has_depth || has_stencil); |
| 1719 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1720 | |
| 1721 | if (is_color && store_op_stores) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1722 | UpdateAccessState(*image, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, |
| 1723 | view.normalized_subresource_range, offset, extent, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1724 | } else { |
| 1725 | auto update_range = view.normalized_subresource_range; |
| 1726 | if (has_depth && store_op_stores) { |
| 1727 | update_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1728 | UpdateAccessState(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, |
| 1729 | update_range, offset, extent, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1730 | } |
| 1731 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1732 | if (has_stencil && stencil_op_stores) { |
| 1733 | update_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1734 | UpdateAccessState(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, |
| 1735 | update_range, offset, extent, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1736 | } |
| 1737 | } |
| 1738 | } |
| 1739 | } |
| 1740 | } |
| 1741 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1742 | template <typename Action> |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1743 | void AccessContext::ApplyToContext(const Action &barrier_action) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1744 | // 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] | 1745 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1746 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), kFullRange, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1751 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1752 | auto &context = contexts[subpass_index]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame^] | 1753 | ApplyTrackbackStackAction barrier_action(context.GetDstExternalTrackBack().barriers); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1754 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1755 | context.ResolveAccessRange(address_type, kFullRange, barrier_action, &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1756 | } |
| 1757 | } |
| 1758 | } |
| 1759 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1760 | // Suitable only for *subpass* access contexts |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1761 | HazardResult AccessContext::DetectSubpassTransitionHazard(const TrackBack &track_back, const IMAGE_VIEW_STATE *attach_view) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1762 | if (!attach_view) return HazardResult(); |
| 1763 | const auto image_state = attach_view->image_state.get(); |
| 1764 | if (!image_state) return HazardResult(); |
| 1765 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1766 | // 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] | 1767 | assert(track_back.context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1768 | |
| 1769 | // 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] | 1770 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1771 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1772 | HazardResult hazard = track_back.context->DetectImageBarrierHazard(*image_state, merged_barrier.src_exec_scope.exec_scope, |
| 1773 | merged_barrier.src_access_scope, |
| 1774 | attach_view->normalized_subresource_range, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1775 | if (!hazard.hazard) { |
| 1776 | // The Async hazard check is against the current context's async set. |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1777 | hazard = DetectImageBarrierHazard(*image_state, merged_barrier.src_exec_scope.exec_scope, merged_barrier.src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1778 | attach_view->normalized_subresource_range, kDetectAsync); |
| 1779 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1780 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1781 | return hazard; |
| 1782 | } |
| 1783 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1784 | void AccessContext::RecordLayoutTransitions(const RENDER_PASS_STATE &rp_state, uint32_t subpass, |
| 1785 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 1786 | const ResourceUsageTag &tag) { |
| 1787 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1788 | const ResourceAccessState empty_infill; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1789 | for (const auto &transition : transitions) { |
| 1790 | const auto prev_pass = transition.prev_pass; |
| 1791 | const auto attachment_view = attachment_views[transition.attachment]; |
| 1792 | if (!attachment_view) continue; |
| 1793 | const auto *image = attachment_view->image_state.get(); |
| 1794 | if (!image) continue; |
| 1795 | if (!SimpleBinding(*image)) continue; |
| 1796 | |
| 1797 | const auto *trackback = GetTrackBackFromSubpass(prev_pass); |
| 1798 | assert(trackback); |
| 1799 | |
| 1800 | // Import the attachments into the current context |
| 1801 | const auto *prev_context = trackback->context; |
| 1802 | assert(prev_context); |
| 1803 | const auto address_type = ImageAddressType(*image); |
| 1804 | auto &target_map = GetAccessStateMap(address_type); |
| 1805 | ApplySubpassTransitionBarriersAction barrier_action(trackback->barriers); |
| 1806 | prev_context->ResolveAccessRange(*image, attachment_view->normalized_subresource_range, barrier_action, address_type, |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1807 | &target_map, &empty_infill); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1808 | } |
| 1809 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1810 | // If there were no transitions skip this global map walk |
| 1811 | if (transitions.size()) { |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1812 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1813 | ApplyToContext(apply_pending_action); |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1814 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1815 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1816 | |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1817 | void CommandBufferAccessContext::ApplyGlobalBarriersToEvents(const SyncExecScope &src, const SyncExecScope &dst) { |
| 1818 | const bool all_commands_bit = 0 != (src.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 1819 | |
| 1820 | auto *events_context = GetCurrentEventsContext(); |
| 1821 | assert(events_context); |
| 1822 | for (auto &event_pair : *events_context) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1823 | assert(event_pair.second); // Shouldn't be storing empty |
| 1824 | auto &sync_event = *event_pair.second; |
| 1825 | // Events don't happen at a stage, so we need to check and store the unexpanded ALL_COMMANDS if set for inter-event-calls |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1826 | if ((sync_event.barriers & src.exec_scope) || all_commands_bit) { |
| 1827 | sync_event.barriers |= dst.exec_scope; |
| 1828 | sync_event.barriers |= dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1829 | } |
| 1830 | } |
| 1831 | } |
| 1832 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1833 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1834 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1835 | const char *func_name) const { |
| 1836 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1837 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1838 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1839 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pipe, &per_sets); |
| 1840 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1841 | return skip; |
| 1842 | } |
| 1843 | |
| 1844 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1845 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1846 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1847 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1848 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1849 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1850 | for (const auto &stage_state : pipe->stage_state) { |
| 1851 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->graphicsPipelineCI.pRasterizationState && |
| 1852 | pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1853 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1854 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1855 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1856 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1857 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1858 | set_binding.first.second); |
| 1859 | const auto descriptor_type = binding_it.GetType(); |
| 1860 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1861 | auto array_idx = 0; |
| 1862 | |
| 1863 | if (binding_it.IsVariableDescriptorCount()) { |
| 1864 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1865 | } |
| 1866 | SyncStageAccessIndex sync_index = |
| 1867 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1868 | |
| 1869 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1870 | uint32_t index = i - index_range.start; |
| 1871 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1872 | switch (descriptor->GetClass()) { |
| 1873 | case DescriptorClass::ImageSampler: |
| 1874 | case DescriptorClass::Image: { |
| 1875 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1876 | VkImageLayout image_layout; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1877 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1878 | const auto image_sampler_descriptor = static_cast<const ImageSamplerDescriptor *>(descriptor); |
| 1879 | img_view_state = image_sampler_descriptor->GetImageViewState(); |
| 1880 | image_layout = image_sampler_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1881 | } else { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1882 | const auto image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 1883 | img_view_state = image_descriptor->GetImageViewState(); |
| 1884 | image_layout = image_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1885 | } |
| 1886 | if (!img_view_state) continue; |
| 1887 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
| 1888 | VkExtent3D extent = {}; |
| 1889 | VkOffset3D offset = {}; |
| 1890 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1891 | extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1892 | offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1893 | } else { |
| 1894 | extent = img_state->createInfo.extent; |
| 1895 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1896 | HazardResult hazard; |
| 1897 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
| 1898 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 1899 | // Input attachments are subject to raster ordering rules |
| 1900 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1901 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1902 | } else { |
| 1903 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, offset, extent); |
| 1904 | } |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1905 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1906 | skip |= sync_state_->LogError( |
| 1907 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1908 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 1909 | ", index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1910 | func_name, string_SyncHazard(hazard.hazard), |
| 1911 | sync_state_->report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1912 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1913 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1914 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1915 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1916 | set_binding.first.second, index, FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1917 | } |
| 1918 | break; |
| 1919 | } |
| 1920 | case DescriptorClass::TexelBuffer: { |
| 1921 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1922 | if (!buf_view_state) continue; |
| 1923 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1924 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1925 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1926 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1927 | skip |= sync_state_->LogError( |
| 1928 | buf_view_state->buffer_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1929 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1930 | func_name, string_SyncHazard(hazard.hazard), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1931 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view).c_str(), |
| 1932 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1933 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1934 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1935 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1936 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1937 | } |
| 1938 | break; |
| 1939 | } |
| 1940 | case DescriptorClass::GeneralBuffer: { |
| 1941 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1942 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1943 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1944 | const ResourceAccessRange range = |
| 1945 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1946 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 1947 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1948 | skip |= sync_state_->LogError( |
| 1949 | buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1950 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1951 | func_name, string_SyncHazard(hazard.hazard), |
| 1952 | sync_state_->report_data->FormatHandle(buf_state->buffer).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1953 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1954 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1955 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1956 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1957 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1958 | } |
| 1959 | break; |
| 1960 | } |
| 1961 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1962 | default: |
| 1963 | break; |
| 1964 | } |
| 1965 | } |
| 1966 | } |
| 1967 | } |
| 1968 | return skip; |
| 1969 | } |
| 1970 | |
| 1971 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1972 | const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1973 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1974 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1975 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pipe, &per_sets); |
| 1976 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1977 | return; |
| 1978 | } |
| 1979 | |
| 1980 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1981 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1982 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1983 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1984 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1985 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1986 | for (const auto &stage_state : pipe->stage_state) { |
| 1987 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->graphicsPipelineCI.pRasterizationState && |
| 1988 | pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1989 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1990 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1991 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1992 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1993 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1994 | set_binding.first.second); |
| 1995 | const auto descriptor_type = binding_it.GetType(); |
| 1996 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1997 | auto array_idx = 0; |
| 1998 | |
| 1999 | if (binding_it.IsVariableDescriptorCount()) { |
| 2000 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 2001 | } |
| 2002 | SyncStageAccessIndex sync_index = |
| 2003 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 2004 | |
| 2005 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 2006 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 2007 | switch (descriptor->GetClass()) { |
| 2008 | case DescriptorClass::ImageSampler: |
| 2009 | case DescriptorClass::Image: { |
| 2010 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
| 2011 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
| 2012 | img_view_state = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetImageViewState(); |
| 2013 | } else { |
| 2014 | img_view_state = static_cast<const ImageDescriptor *>(descriptor)->GetImageViewState(); |
| 2015 | } |
| 2016 | if (!img_view_state) continue; |
| 2017 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
| 2018 | VkExtent3D extent = {}; |
| 2019 | VkOffset3D offset = {}; |
| 2020 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 2021 | extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 2022 | offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 2023 | } else { |
| 2024 | extent = img_state->createInfo.extent; |
| 2025 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2026 | SyncOrdering ordering_rule = (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) |
| 2027 | ? SyncOrdering::kRaster |
| 2028 | : SyncOrdering::kNonAttachment; |
| 2029 | current_context_->UpdateAccessState(*img_state, sync_index, ordering_rule, |
| 2030 | img_view_state->normalized_subresource_range, offset, extent, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2031 | break; |
| 2032 | } |
| 2033 | case DescriptorClass::TexelBuffer: { |
| 2034 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 2035 | if (!buf_view_state) continue; |
| 2036 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2037 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2038 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2039 | break; |
| 2040 | } |
| 2041 | case DescriptorClass::GeneralBuffer: { |
| 2042 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 2043 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 2044 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2045 | const ResourceAccessRange range = |
| 2046 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2047 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2048 | break; |
| 2049 | } |
| 2050 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2051 | default: |
| 2052 | break; |
| 2053 | } |
| 2054 | } |
| 2055 | } |
| 2056 | } |
| 2057 | } |
| 2058 | |
| 2059 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const char *func_name) const { |
| 2060 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2061 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2062 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2063 | return skip; |
| 2064 | } |
| 2065 | |
| 2066 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2067 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2068 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2069 | |
| 2070 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2071 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2072 | if (binding_description.binding < binding_buffers_size) { |
| 2073 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2074 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->destroyed) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2075 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2076 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2077 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2078 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2079 | 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] | 2080 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2081 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2082 | buf_state->buffer, string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for vertex %s in %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2083 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(buf_state->buffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2084 | 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] | 2085 | } |
| 2086 | } |
| 2087 | } |
| 2088 | return skip; |
| 2089 | } |
| 2090 | |
| 2091 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2092 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2093 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2094 | return; |
| 2095 | } |
| 2096 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2097 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2098 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2099 | |
| 2100 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2101 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2102 | if (binding_description.binding < binding_buffers_size) { |
| 2103 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2104 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->destroyed) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2105 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2106 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2107 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2108 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2109 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ, |
| 2110 | SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2111 | } |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const char *func_name) const { |
| 2116 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2117 | 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] | 2118 | return skip; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2119 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2120 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2121 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2122 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2123 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2124 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2125 | 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] | 2126 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2127 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2128 | index_buf_state->buffer, string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for index %s in %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2129 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(index_buf_state->buffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2130 | 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] | 2131 | } |
| 2132 | |
| 2133 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2134 | // We will detect more accurate range in the future. |
| 2135 | skip |= ValidateDrawVertex(UINT32_MAX, 0, func_name); |
| 2136 | return skip; |
| 2137 | } |
| 2138 | |
| 2139 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag &tag) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2140 | 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] | 2141 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2142 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2143 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2144 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2145 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2146 | 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] | 2147 | |
| 2148 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2149 | // We will detect more accurate range in the future. |
| 2150 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 2151 | } |
| 2152 | |
| 2153 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(const char *func_name) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2154 | bool skip = false; |
| 2155 | if (!current_renderpass_context_) return skip; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2156 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(GetExecutionContext(), *cb_state_.get(), func_name); |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2157 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2161 | if (current_renderpass_context_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2162 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), tag); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2163 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2164 | } |
| 2165 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2166 | void CommandBufferAccessContext::RecordBeginRenderPass(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2167 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2168 | const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2169 | // Create an access context the current renderpass. |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2170 | 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] | 2171 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2172 | current_renderpass_context_->RecordBeginRenderPass(tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2173 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2174 | } |
| 2175 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2176 | void CommandBufferAccessContext::RecordNextSubpass(CMD_TYPE command) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2177 | assert(current_renderpass_context_); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2178 | auto prev_tag = NextCommandTag(command); |
| 2179 | auto next_tag = NextSubcommandTag(command); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2180 | current_renderpass_context_->RecordNextSubpass(prev_tag, next_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2181 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
| 2182 | } |
| 2183 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2184 | void CommandBufferAccessContext::RecordEndRenderPass(CMD_TYPE command) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2185 | assert(current_renderpass_context_); |
| 2186 | if (!current_renderpass_context_) return; |
| 2187 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2188 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, NextCommandTag(command)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2189 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2190 | current_renderpass_context_ = nullptr; |
| 2191 | } |
| 2192 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2193 | void CommandBufferAccessContext::RecordDestroyEvent(VkEvent event) { |
| 2194 | // Erase is okay with the key not being |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2195 | const auto *event_state = sync_state_->Get<EVENT_STATE>(event); |
| 2196 | if (event_state) { |
| 2197 | GetCurrentEventsContext()->Destroy(event_state); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2201 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const CommandExecutionContext &ex_context, const CMD_BUFFER_STATE &cmd, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2202 | const char *func_name) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2203 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2204 | const auto &sync_state = ex_context.GetSyncState(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2205 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2206 | if (!pipe || |
| 2207 | (pipe->graphicsPipelineCI.pRasterizationState && pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2208 | return skip; |
| 2209 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2210 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2211 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2212 | VkExtent3D extent = CastTo3D(render_area_.extent); |
| 2213 | VkOffset3D offset = CastTo3D(render_area_.offset); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2214 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2215 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2216 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2217 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2218 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2219 | if (location >= subpass.colorAttachmentCount || |
| 2220 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2221 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2222 | } |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2223 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pColorAttachments[location].attachment]; |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2224 | HazardResult hazard = current_context.DetectHazard(img_view_state, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2225 | SyncOrdering::kColorAttachment, offset, extent); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2226 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2227 | skip |= sync_state.LogError(img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2228 | "%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] | 2229 | func_name, string_SyncHazard(hazard.hazard), |
| 2230 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 2231 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2232 | location, ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2233 | } |
| 2234 | } |
| 2235 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2236 | |
| 2237 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2238 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2239 | if (pipe->graphicsPipelineCI.pDepthStencilState && subpass.pDepthStencilAttachment && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2240 | subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2241 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pDepthStencilAttachment->attachment]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2242 | bool depth_write = false, stencil_write = false; |
| 2243 | |
| 2244 | // PHASE1 TODO: These validation should be in core_checks. |
| 2245 | if (!FormatIsStencilOnly(img_view_state->create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2246 | pipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 2247 | pipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2248 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2249 | depth_write = true; |
| 2250 | } |
| 2251 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2252 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2253 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2254 | // PHASE1 TODO: These validation should be in core_checks. |
| 2255 | if (!FormatIsDepthOnly(img_view_state->create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2256 | pipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2257 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2258 | stencil_write = true; |
| 2259 | } |
| 2260 | |
| 2261 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2262 | if (depth_write) { |
| 2263 | HazardResult hazard = |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2264 | current_context.DetectHazard(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2265 | SyncOrdering::kDepthStencilAttachment, offset, extent, VK_IMAGE_ASPECT_DEPTH_BIT); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2266 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2267 | skip |= sync_state.LogError( |
| 2268 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2269 | "%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] | 2270 | func_name, string_SyncHazard(hazard.hazard), |
| 2271 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 2272 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2273 | ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2274 | } |
| 2275 | } |
| 2276 | if (stencil_write) { |
| 2277 | HazardResult hazard = |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2278 | current_context.DetectHazard(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2279 | SyncOrdering::kDepthStencilAttachment, offset, extent, VK_IMAGE_ASPECT_STENCIL_BIT); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2280 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2281 | skip |= sync_state.LogError( |
| 2282 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2283 | "%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] | 2284 | func_name, string_SyncHazard(hazard.hazard), |
| 2285 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 2286 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2287 | ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2288 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2289 | } |
| 2290 | } |
| 2291 | return skip; |
| 2292 | } |
| 2293 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2294 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd, const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2295 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2296 | if (!pipe || |
| 2297 | (pipe->graphicsPipelineCI.pRasterizationState && pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2298 | return; |
| 2299 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2300 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2301 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2302 | VkExtent3D extent = CastTo3D(render_area_.extent); |
| 2303 | VkOffset3D offset = CastTo3D(render_area_.offset); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2304 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2305 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2306 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2307 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2308 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2309 | if (location >= subpass.colorAttachmentCount || |
| 2310 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2311 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2312 | } |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2313 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pColorAttachments[location].attachment]; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2314 | current_context.UpdateAccessState(img_view_state, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 2315 | SyncOrdering::kColorAttachment, offset, extent, 0, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2316 | } |
| 2317 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2318 | |
| 2319 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2320 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2321 | if (pipe->graphicsPipelineCI.pDepthStencilState && subpass.pDepthStencilAttachment && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2322 | subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2323 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pDepthStencilAttachment->attachment]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2324 | bool depth_write = false, stencil_write = false; |
| 2325 | |
| 2326 | // PHASE1 TODO: These validation should be in core_checks. |
| 2327 | if (!FormatIsStencilOnly(img_view_state->create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2328 | pipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 2329 | pipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2330 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2331 | depth_write = true; |
| 2332 | } |
| 2333 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2334 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2335 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2336 | // PHASE1 TODO: These validation should be in core_checks. |
| 2337 | if (!FormatIsDepthOnly(img_view_state->create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2338 | pipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2339 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2340 | stencil_write = true; |
| 2341 | } |
| 2342 | |
| 2343 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2344 | if (depth_write) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2345 | current_context.UpdateAccessState(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2346 | SyncOrdering::kDepthStencilAttachment, offset, extent, VK_IMAGE_ASPECT_DEPTH_BIT, |
| 2347 | tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2348 | } |
| 2349 | if (stencil_write) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2350 | current_context.UpdateAccessState(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2351 | SyncOrdering::kDepthStencilAttachment, offset, extent, VK_IMAGE_ASPECT_STENCIL_BIT, |
| 2352 | tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2353 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2354 | } |
| 2355 | } |
| 2356 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2357 | bool RenderPassAccessContext::ValidateNextSubpass(const CommandExecutionContext &ex_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2358 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2359 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2360 | 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] | 2361 | current_subpass_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2362 | 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] | 2363 | func_name); |
| 2364 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2365 | const auto next_subpass = current_subpass_ + 1; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2366 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2367 | skip |= |
| 2368 | 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] | 2369 | if (!skip) { |
| 2370 | // To avoid complex (and buggy) duplication of the affect of layout transitions on load operations, we'll record them |
| 2371 | // on a copy of the (empty) next context. |
| 2372 | // Note: The resource access map should be empty so hopefully this copy isn't too horrible from a perf POV. |
| 2373 | AccessContext temp_context(next_context); |
| 2374 | temp_context.RecordLayoutTransitions(*rp_state_, next_subpass, attachment_views_, kCurrentCommandTag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2375 | skip |= |
| 2376 | 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] | 2377 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2378 | return skip; |
| 2379 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2380 | bool RenderPassAccessContext::ValidateEndRenderPass(const CommandExecutionContext &ex_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2381 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2382 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2383 | 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] | 2384 | current_subpass_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2385 | 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] | 2386 | func_name); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2387 | skip |= ValidateFinalSubpassLayoutTransitions(ex_context, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2388 | return skip; |
| 2389 | } |
| 2390 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2391 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy() const { |
| 2392 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, render_area_, attachment_views_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2393 | } |
| 2394 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2395 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const CommandExecutionContext &ex_context, |
| 2396 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2397 | bool skip = false; |
| 2398 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2399 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2400 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2401 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2402 | // to apply and only copy then, if this proves a hot spot. |
| 2403 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2404 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2405 | // Validate the "finalLayout" transitions to external |
| 2406 | // Get them from where there we're hidding in the extra entry. |
| 2407 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2408 | for (const auto &transition : final_transitions) { |
| 2409 | const auto &attach_view = attachment_views_[transition.attachment]; |
| 2410 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
| 2411 | 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] | 2412 | auto *context = trackback.context; |
| 2413 | |
| 2414 | if (transition.prev_pass == current_subpass_) { |
| 2415 | if (!proxy_for_current) { |
| 2416 | // 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] | 2417 | proxy_for_current.reset(CreateStoreResolveProxy()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2418 | } |
| 2419 | context = proxy_for_current.get(); |
| 2420 | } |
| 2421 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2422 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2423 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2424 | auto hazard = context->DetectImageBarrierHazard(*attach_view->image_state, merged_barrier.src_exec_scope.exec_scope, |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2425 | merged_barrier.src_access_scope, attach_view->normalized_subresource_range, |
| 2426 | AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2427 | if (hazard.hazard) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2428 | skip |= ex_context.GetSyncState().LogError( |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2429 | rp_state_->renderPass, string_SyncHazardVUID(hazard.hazard), |
| 2430 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
| 2431 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 2432 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2433 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2434 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | return skip; |
| 2438 | } |
| 2439 | |
| 2440 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag &tag) { |
| 2441 | // Add layout transitions... |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2442 | subpass_contexts_[current_subpass_].RecordLayoutTransitions(*rp_state_, current_subpass_, attachment_views_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2443 | } |
| 2444 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2445 | void RenderPassAccessContext::RecordLoadOperations(const ResourceUsageTag &tag) { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2446 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2447 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2448 | VkExtent3D extent = CastTo3D(render_area_.extent); |
| 2449 | VkOffset3D offset = CastTo3D(render_area_.offset); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2450 | |
| 2451 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2452 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
| 2453 | if (attachment_views_[i] == nullptr) continue; // UNUSED |
| 2454 | const auto &view = *attachment_views_[i]; |
| 2455 | const IMAGE_STATE *image = view.image_state.get(); |
| 2456 | if (image == nullptr) continue; |
| 2457 | |
| 2458 | const auto &ci = attachment_ci[i]; |
| 2459 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2460 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2461 | const bool is_color = !(has_depth || has_stencil); |
| 2462 | |
| 2463 | if (is_color) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2464 | subpass_context.UpdateAccessState(*image, ColorLoadUsage(ci.loadOp), SyncOrdering::kColorAttachment, |
| 2465 | view.normalized_subresource_range, offset, extent, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2466 | } else { |
| 2467 | auto update_range = view.normalized_subresource_range; |
| 2468 | if (has_depth) { |
| 2469 | update_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2470 | subpass_context.UpdateAccessState(*image, DepthStencilLoadUsage(ci.loadOp), |
| 2471 | SyncOrdering::kDepthStencilAttachment, update_range, offset, extent, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2472 | } |
| 2473 | if (has_stencil) { |
| 2474 | update_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2475 | subpass_context.UpdateAccessState(*image, DepthStencilLoadUsage(ci.stencilLoadOp), |
| 2476 | SyncOrdering::kDepthStencilAttachment, update_range, offset, extent, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2482 | RenderPassAccessContext::RenderPassAccessContext(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2483 | VkQueueFlags queue_flags, |
| 2484 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2485 | const AccessContext *external_context) |
| 2486 | : rp_state_(&rp_state), render_area_(render_area), current_subpass_(0U), attachment_views_(attachment_views) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2487 | // 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] | 2488 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2489 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2490 | 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] | 2491 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2492 | } |
| 2493 | void RenderPassAccessContext::RecordBeginRenderPass(const ResourceUsageTag &tag) { |
| 2494 | assert(0 == current_subpass_); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2495 | subpass_contexts_[current_subpass_].SetStartTag(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2496 | RecordLayoutTransitions(tag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2497 | RecordLoadOperations(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2498 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2499 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2500 | void RenderPassAccessContext::RecordNextSubpass(const ResourceUsageTag &prev_subpass_tag, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2501 | const ResourceUsageTag &next_subpass_tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2502 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2503 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, render_area_, attachment_views_, current_subpass_, prev_subpass_tag); |
| 2504 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, render_area_, attachment_views_, current_subpass_, prev_subpass_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2505 | |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 2506 | // Move to the next sub-command for the new subpass. The resolve and store are logically part of the previous |
| 2507 | // 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] | 2508 | current_subpass_++; |
| 2509 | assert(current_subpass_ < subpass_contexts_.size()); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2510 | subpass_contexts_[current_subpass_].SetStartTag(next_subpass_tag); |
| 2511 | RecordLayoutTransitions(next_subpass_tag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2512 | RecordLoadOperations(next_subpass_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2513 | } |
| 2514 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2515 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const ResourceUsageTag &tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2516 | // Add the resolve and store accesses |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2517 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, render_area_, attachment_views_, current_subpass_, tag); |
| 2518 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, render_area_, attachment_views_, current_subpass_, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2519 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2520 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2521 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2522 | |
| 2523 | // Add the "finalLayout" transitions to external |
| 2524 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2525 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2526 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2527 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2528 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2529 | for (const auto &transition : final_transitions) { |
| 2530 | const auto &attachment = attachment_views_[transition.attachment]; |
| 2531 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | aa97d8b | 2020-07-14 10:58:13 -0600 | [diff] [blame] | 2532 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2533 | ApplyBarrierOpsFunctor<PipelineBarrierOp> barrier_action(true /* resolve */, last_trackback.barriers.size(), tag); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2534 | for (const auto &barrier : last_trackback.barriers) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2535 | barrier_action.EmplaceBack(PipelineBarrierOp(barrier, true)); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2536 | } |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2537 | external_context->UpdateResourceAccess(*attachment->image_state, attachment->normalized_subresource_range, barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2538 | } |
| 2539 | } |
| 2540 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2541 | SyncExecScope SyncExecScope::MakeSrc(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2542 | SyncExecScope result; |
| 2543 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2544 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2545 | result.exec_scope = sync_utils::WithEarlierPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2546 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2547 | return result; |
| 2548 | } |
| 2549 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2550 | SyncExecScope SyncExecScope::MakeDst(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2551 | SyncExecScope result; |
| 2552 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2553 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2554 | result.exec_scope = sync_utils::WithLaterPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2555 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2556 | return result; |
| 2557 | } |
| 2558 | |
| 2559 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2560 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2561 | src_access_scope = 0; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2562 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2563 | dst_access_scope = 0; |
| 2564 | } |
| 2565 | |
| 2566 | template <typename Barrier> |
| 2567 | SyncBarrier::SyncBarrier(const Barrier &barrier, const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2568 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2569 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2570 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2571 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
| 2572 | } |
| 2573 | |
| 2574 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &subpass) { |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2575 | const auto barrier = lvl_find_in_chain<VkMemoryBarrier2KHR>(subpass.pNext); |
| 2576 | if (barrier) { |
| 2577 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier->srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2578 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2579 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier->srcAccessMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2580 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2581 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier->dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2582 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2583 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier->dstAccessMask); |
| 2584 | |
| 2585 | } else { |
| 2586 | auto src = SyncExecScope::MakeSrc(queue_flags, subpass.srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2587 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2588 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, subpass.srcAccessMask); |
| 2589 | |
| 2590 | auto dst = SyncExecScope::MakeDst(queue_flags, subpass.dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2591 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2592 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, subpass.dstAccessMask); |
| 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | template <typename Barrier> |
| 2597 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const Barrier &barrier) { |
| 2598 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 2599 | src_exec_scope = src.exec_scope; |
| 2600 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
| 2601 | |
| 2602 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2603 | dst_exec_scope = dst.exec_scope; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2604 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2605 | } |
| 2606 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2607 | // Apply a list of barriers, without resolving pending state, useful for subpass layout transitions |
| 2608 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
| 2609 | for (const auto &barrier : barriers) { |
| 2610 | ApplyBarrier(barrier, layout_transition); |
| 2611 | } |
| 2612 | } |
| 2613 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2614 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2615 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2616 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2617 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, const ResourceUsageTag &tag) { |
| 2618 | 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] | 2619 | assert(pending_write_barriers.none()); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2620 | assert(!pending_write_dep_chain); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2621 | for (const auto &barrier : barriers) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2622 | ApplyBarrier(barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2623 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2624 | ApplyPendingBarriers(tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2625 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2626 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2627 | HazardResult hazard; |
| 2628 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2629 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2630 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2631 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2632 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2633 | } |
| 2634 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2635 | // Write operation: |
| 2636 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2637 | // If reads exists -- test only against them because either: |
| 2638 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2639 | // * 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 |
| 2640 | // the current write happens after the reads, so just test the write against the reades |
| 2641 | // Otherwise test against last_write |
| 2642 | // |
| 2643 | // Look for casus belli for WAR |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2644 | if (last_reads.size()) { |
| 2645 | for (const auto &read_access : last_reads) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2646 | if (IsReadHazard(usage_stage, read_access)) { |
| 2647 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2648 | break; |
| 2649 | } |
| 2650 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2651 | } else if (last_write.any() && IsWriteHazard(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2652 | // Write-After-Write check -- if we have a previous write to test against |
| 2653 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2654 | } |
| 2655 | } |
| 2656 | return hazard; |
| 2657 | } |
| 2658 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2659 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrdering &ordering_rule) const { |
| 2660 | const auto &ordering = GetOrderingRules(ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2661 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 2662 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2663 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2664 | const auto usage_stage = PipelineStageBit(usage_index); |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2665 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
| 2666 | const bool last_write_is_ordered = (last_write & ordering.access_scope).any(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2667 | if (IsRead(usage_bit)) { |
| 2668 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 2669 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 2670 | if (is_raw_hazard) { |
| 2671 | // NOTE: we know last_write is non-zero |
| 2672 | // See if the ordering rules save us from the simple RAW check above |
| 2673 | // First check to see if the current usage is covered by the ordering rules |
| 2674 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 2675 | const bool usage_is_ordered = |
| 2676 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 2677 | if (usage_is_ordered) { |
| 2678 | // Now see of the most recent write (or a subsequent read) are ordered |
| 2679 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(ordering)); |
| 2680 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2681 | } |
| 2682 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2683 | if (is_raw_hazard) { |
| 2684 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 2685 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2686 | } else { |
| 2687 | // Only check for WAW if there are no reads since last_write |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2688 | bool usage_write_is_ordered = (usage_bit & ordering.access_scope).any(); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2689 | if (last_reads.size()) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2690 | // Look for any WAR hazards outside the ordered set of stages |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2691 | VkPipelineStageFlags2KHR ordered_stages = 0; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2692 | if (usage_write_is_ordered) { |
| 2693 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
| 2694 | ordered_stages = GetOrderedStages(ordering); |
| 2695 | } |
| 2696 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 2697 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2698 | for (const auto &read_access : last_reads) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2699 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 2700 | if (IsReadHazard(usage_stage, read_access)) { |
| 2701 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2702 | break; |
| 2703 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2704 | } |
| 2705 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2706 | } else if (!(last_write_is_ordered && usage_write_is_ordered)) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2707 | if (last_write.any() && IsWriteHazard(usage_bit)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2708 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2709 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2710 | } |
| 2711 | } |
| 2712 | return hazard; |
| 2713 | } |
| 2714 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2715 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2716 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index, const ResourceUsageTag &start_tag) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2717 | HazardResult hazard; |
| 2718 | auto usage = FlagBit(usage_index); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2719 | // Async checks need to not go back further than the start of the subpass, as we only want to find hazards between the async |
| 2720 | // subpasses. Anything older than that should have been checked at the start of each subpass, taking into account all of |
| 2721 | // the raster ordering rules. |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2722 | if (IsRead(usage)) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2723 | if (last_write.any() && (write_tag.index >= start_tag.index)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2724 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2725 | } |
| 2726 | } else { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2727 | if (last_write.any() && (write_tag.index >= start_tag.index)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2728 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2729 | } else if (last_reads.size() > 0) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2730 | // 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] | 2731 | for (const auto &read_access : last_reads) { |
| 2732 | if (read_access.tag.index >= start_tag.index) { |
| 2733 | 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] | 2734 | break; |
| 2735 | } |
| 2736 | } |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2737 | } |
| 2738 | } |
| 2739 | return hazard; |
| 2740 | } |
| 2741 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2742 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2743 | const SyncStageAccessFlags &src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2744 | // Only supporting image layout transitions for now |
| 2745 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2746 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2747 | // only test for WAW if there no intervening read operations. |
| 2748 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2749 | if (last_reads.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2750 | // Look at the reads if any |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2751 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2752 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2753 | 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] | 2754 | break; |
| 2755 | } |
| 2756 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2757 | } else if (last_write.any() && IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2758 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2759 | } |
| 2760 | |
| 2761 | return hazard; |
| 2762 | } |
| 2763 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2764 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2765 | const SyncStageAccessFlags &src_access_scope, |
| 2766 | const ResourceUsageTag &event_tag) const { |
| 2767 | // Only supporting image layout transitions for now |
| 2768 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2769 | HazardResult hazard; |
| 2770 | // only test for WAW if there no intervening read operations. |
| 2771 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 2772 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2773 | if (last_reads.size()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2774 | // Look at the reads if any... if reads exist, they are either the resaon the access is in the event |
| 2775 | // first scope, or they are a hazard. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2776 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2777 | if (read_access.tag.IsBefore(event_tag)) { |
| 2778 | // The read is in the events first synchronization scope, so we use a barrier hazard check |
| 2779 | // If the read stage is not in the src sync scope |
| 2780 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 2781 | // then the barrier access is unsafe (R/W after R) |
| 2782 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
| 2783 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2784 | break; |
| 2785 | } |
| 2786 | } else { |
| 2787 | // The read not in the event first sync scope and so is a hazard vs. the layout transition |
| 2788 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2789 | } |
| 2790 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2791 | } else if (last_write.any()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2792 | // if there are no reads, the write is either the reason the access is in the event scope... they are a hazard |
| 2793 | if (write_tag.IsBefore(event_tag)) { |
| 2794 | // The write is in the first sync scope of the event (sync their aren't any reads to be the reason) |
| 2795 | // So do a normal barrier hazard check |
| 2796 | if (IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2797 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2798 | } |
| 2799 | } else { |
| 2800 | // 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] | 2801 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2802 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2803 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2804 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2805 | return hazard; |
| 2806 | } |
| 2807 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2808 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 2809 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 2810 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 2811 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
| 2812 | if (write_tag.IsBefore(other.write_tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2813 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 2814 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2815 | *this = other; |
| 2816 | } else if (!other.write_tag.IsBefore(write_tag)) { |
| 2817 | // This is the *equals* case for write operations, we merged the write barriers and the read state (but without the |
| 2818 | // dependency chaining logic or any stage expansion) |
| 2819 | write_barriers |= other.write_barriers; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2820 | pending_write_barriers |= other.pending_write_barriers; |
| 2821 | pending_layout_transition |= other.pending_layout_transition; |
| 2822 | pending_write_dep_chain |= other.pending_write_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2823 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2824 | // Merge the read states |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2825 | const auto pre_merge_count = last_reads.size(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2826 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2827 | 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] | 2828 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2829 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2830 | // 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] | 2831 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 2832 | // but we should wait on profiling data for that. |
| 2833 | 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] | 2834 | auto &my_read = last_reads[my_read_index]; |
| 2835 | if (other_read.stage == my_read.stage) { |
| 2836 | if (my_read.tag.IsBefore(other_read.tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2837 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2838 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2839 | my_read.tag = other_read.tag; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2840 | my_read.pending_dep_chain = other_read.pending_dep_chain; |
| 2841 | // TODO: Phase 2 -- review the state merge logic to avoid false positive from overwriting the barriers |
| 2842 | // May require tracking more than one access per stage. |
| 2843 | my_read.barriers = other_read.barriers; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2844 | if (my_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2845 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 2846 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2847 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2848 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2849 | } else if (other_read.tag.IsBefore(my_read.tag)) { |
| 2850 | // The read tags match so merge the barriers |
| 2851 | my_read.barriers |= other_read.barriers; |
| 2852 | my_read.pending_dep_chain |= other_read.pending_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2853 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2854 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2855 | break; |
| 2856 | } |
| 2857 | } |
| 2858 | } else { |
| 2859 | // The other read stage doesn't exist in this, so add it. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2860 | last_reads.emplace_back(other_read); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2861 | last_read_stages |= other_read.stage; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2862 | if (other_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2863 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2864 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2865 | } |
| 2866 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2867 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2868 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 2869 | // ignore it. |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2870 | |
| 2871 | // Merge first access information by making a copy of this first_access and reconstructing with a shuffle |
| 2872 | // of the copy and other into this using the update first logic. |
| 2873 | // NOTE: All sorts of additional cleverness could be put into short circuts. (for example back is write and is before front |
| 2874 | // of the other first_accesses... ) |
| 2875 | if (!(first_accesses_ == other.first_accesses_) && !other.first_accesses_.empty()) { |
| 2876 | FirstAccesses firsts(std::move(first_accesses_)); |
| 2877 | first_accesses_.clear(); |
| 2878 | first_read_stages_ = 0U; |
| 2879 | auto a = firsts.begin(); |
| 2880 | auto a_end = firsts.end(); |
| 2881 | for (auto &b : other.first_accesses_) { |
| 2882 | // TODO: Determine whether "IsBefore" or "IsGloballyBefore" is needed... |
| 2883 | while (a != a_end && a->tag.IsBefore(b.tag)) { |
| 2884 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 2885 | ++a; |
| 2886 | } |
| 2887 | UpdateFirst(b.tag, b.usage_index, b.ordering_rule); |
| 2888 | } |
| 2889 | for (; a != a_end; ++a) { |
| 2890 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 2891 | } |
| 2892 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2893 | } |
| 2894 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2895 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, SyncOrdering ordering_rule, const ResourceUsageTag &tag) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2896 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 2897 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2898 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2899 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 2900 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 2901 | const auto usage_stage = PipelineStageBit(usage_index); |
| 2902 | if (usage_stage & last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2903 | for (auto &read_access : last_reads) { |
| 2904 | if (read_access.stage == usage_stage) { |
| 2905 | read_access.Set(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2906 | break; |
| 2907 | } |
| 2908 | } |
| 2909 | } else { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2910 | last_reads.emplace_back(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2911 | last_read_stages |= usage_stage; |
| 2912 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2913 | |
| 2914 | // 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] | 2915 | if (usage_stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2916 | // TODO Revisit re: multiple reads for a given stage |
| 2917 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2918 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2919 | } else { |
| 2920 | // Assume write |
| 2921 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2922 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2923 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2924 | UpdateFirst(tag, usage_index, ordering_rule); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2925 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2926 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2927 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 2928 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 2929 | // We can overwrite them as *this* write is now after them. |
| 2930 | // |
| 2931 | // Note: intentionally ignore pending barriers and chains (i.e. don't apply or clear them), let ApplyPendingBarriers handle them. |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2932 | void ResourceAccessState::SetWrite(const SyncStageAccessFlags &usage_bit, const ResourceUsageTag &tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2933 | last_reads.clear(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2934 | last_read_stages = 0; |
| 2935 | read_execution_barriers = 0; |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2936 | 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] | 2937 | |
| 2938 | write_barriers = 0; |
| 2939 | write_dependency_chain = 0; |
| 2940 | write_tag = tag; |
| 2941 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2942 | } |
| 2943 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2944 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 2945 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 2946 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 2947 | // replace the current write barriers or add to them, so accumulate to pending as well. |
| 2948 | void ResourceAccessState::ApplyBarrier(const SyncBarrier &barrier, bool layout_transition) { |
| 2949 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 2950 | // applying the memory barriers |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 2951 | // NOTE: We update the write barrier if the write is in the first access scope or if there is a layout |
| 2952 | // transistion, under the theory of "most recent access". If the read/write *isn't* safe |
| 2953 | // vs. this layout transition DetectBarrierHazard should report it. We treat the layout |
| 2954 | // 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] | 2955 | 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] | 2956 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2957 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2958 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2959 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 2960 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2961 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2962 | if (!pending_layout_transition) { |
| 2963 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 2964 | // 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] | 2965 | for (auto &read_access : last_reads) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2966 | // 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] | 2967 | if (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers)) { |
| 2968 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2969 | } |
| 2970 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2971 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2972 | } |
| 2973 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2974 | // Apply the tag scoped memory barrier without updating the existing barriers. The execution barrier |
| 2975 | // changes the "chaining" state, but to keep barriers independent. See discussion above. |
| 2976 | void ResourceAccessState::ApplyBarrier(const ResourceUsageTag &scope_tag, const SyncBarrier &barrier, bool layout_transition) { |
| 2977 | // The scope logic for events is, if we're here, the resource usage was flagged as "in the first execution scope" at |
| 2978 | // the time of the SetEvent, thus all we need check is whether the access is the same one (i.e. before the scope tag |
| 2979 | // in order to know if it's in the excecution scope |
| 2980 | // Notice that the layout transition sets the pending barriers *regardless*, as any lack of src_access_scope to |
| 2981 | // guard against the layout transition should be reported in the detect barrier hazard phase, and we only report |
| 2982 | // errors w.r.t. "most recent" accesses. |
| 2983 | if (layout_transition || ((write_tag.IsBefore(scope_tag)) && (barrier.src_access_scope & last_write).any())) { |
| 2984 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2985 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2986 | } |
| 2987 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 2988 | pending_layout_transition |= layout_transition; |
| 2989 | |
| 2990 | if (!pending_layout_transition) { |
| 2991 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 2992 | // 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] | 2993 | for (auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2994 | // If this read is the same one we included in the set event and in scope, then apply the execution barrier... |
| 2995 | // NOTE: That's not really correct... this read stage might *not* have been included in the setevent, and the barriers |
| 2996 | // representing the chain might have changed since then (that would be an odd usage), so as a first approximation |
| 2997 | // we'll assume the barriers *haven't* been changed since (if the tag hasn't), and while this could be a false |
| 2998 | // positive in the case of Set; SomeBarrier; Wait; we'll live with it until we can add more state to the first scope |
| 2999 | // capture (the specific write and read stages that *were* in scope at the moment of SetEvents. |
| 3000 | // TODO: eliminate the false positive by including write/read-stages "in scope" information in SetEvents first_scope |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 3001 | if (read_access.tag.IsBefore(scope_tag) && |
| 3002 | (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers))) { |
| 3003 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3004 | } |
| 3005 | } |
| 3006 | } |
| 3007 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3008 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag &tag) { |
| 3009 | if (pending_layout_transition) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3010 | // SetWrite clobbers the read count, and thus we don't have to clear the read_state out. |
| 3011 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3012 | UpdateFirst(tag, SYNC_IMAGE_LAYOUT_TRANSITION, SyncOrdering::kNonAttachment); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3013 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3014 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3015 | |
| 3016 | // Apply the accumulate execution barriers (and thus update chaining information) |
| 3017 | // for layout transition, read count is zeroed by SetWrite, so this will be skipped. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3018 | for (auto &read_access : last_reads) { |
| 3019 | read_access.barriers |= read_access.pending_dep_chain; |
| 3020 | read_execution_barriers |= read_access.barriers; |
| 3021 | read_access.pending_dep_chain = 0; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 3025 | write_dependency_chain |= pending_write_dep_chain; |
| 3026 | write_barriers |= pending_write_barriers; |
| 3027 | pending_write_dep_chain = 0; |
| 3028 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3029 | } |
| 3030 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3031 | // 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] | 3032 | VkPipelineStageFlags2KHR ResourceAccessState::GetReadBarriers(const SyncStageAccessFlags &usage_bit) const { |
| 3033 | VkPipelineStageFlags2KHR barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3034 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3035 | for (const auto &read_access : last_reads) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3036 | if ((read_access.access & usage_bit).any()) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3037 | barriers = read_access.barriers; |
| 3038 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3039 | } |
| 3040 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3041 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3042 | return barriers; |
| 3043 | } |
| 3044 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3045 | inline bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlags2KHR usage_stage, const SyncStageAccessFlags &usage) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3046 | assert(IsRead(usage)); |
| 3047 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 3048 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 3049 | // any reads that happen after. |
| 3050 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 3051 | // 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] | 3052 | return last_write.any() && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3053 | } |
| 3054 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3055 | VkPipelineStageFlags2KHR ResourceAccessState::GetOrderedStages(const OrderingBarrier &ordering) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3056 | // 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] | 3057 | VkPipelineStageFlags2KHR ordered_stages = last_read_stages & ordering.exec_scope; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3058 | // Special input attachment handling as always (not encoded in exec_scop) |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3059 | 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] | 3060 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3061 | // 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] | 3062 | ordered_stages |= VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | return ordered_stages; |
| 3066 | } |
| 3067 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3068 | void ResourceAccessState::UpdateFirst(const ResourceUsageTag &tag, SyncStageAccessIndex usage_index, SyncOrdering ordering_rule) { |
| 3069 | // Only record until we record a write. |
| 3070 | if (first_accesses_.empty() || IsRead(first_accesses_.back().usage_index)) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3071 | const VkPipelineStageFlags2KHR usage_stage = IsRead(usage_index) ? PipelineStageBit(usage_index) : 0U; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3072 | if (0 == (usage_stage & first_read_stages_)) { |
| 3073 | // If this is a read we haven't seen or a write, record. |
| 3074 | first_read_stages_ |= usage_stage; |
| 3075 | first_accesses_.emplace_back(tag, usage_index, ordering_rule); |
| 3076 | } |
| 3077 | } |
| 3078 | } |
| 3079 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3080 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3081 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 3082 | if (access_context) { |
| 3083 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3084 | } |
| 3085 | } |
| 3086 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3087 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 3088 | auto access_found = cb_access_state.find(command_buffer); |
| 3089 | if (access_found != cb_access_state.end()) { |
| 3090 | access_found->second->Reset(); |
| 3091 | cb_access_state.erase(access_found); |
| 3092 | } |
| 3093 | } |
| 3094 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3095 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3096 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 3097 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3098 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3099 | assert(cb_context); |
| 3100 | if (!cb_context) return skip; |
| 3101 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3102 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3103 | // If we have no previous accesses, we have no hazards |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3104 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3105 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3106 | |
| 3107 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3108 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3109 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3110 | 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] | 3111 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3112 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3113 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3114 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3115 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3116 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3117 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3118 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3119 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3120 | 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] | 3121 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3122 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3123 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3124 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3125 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3126 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3127 | } |
| 3128 | } |
| 3129 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3130 | } |
| 3131 | return skip; |
| 3132 | } |
| 3133 | |
| 3134 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3135 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3136 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3137 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3138 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3139 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3140 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3141 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3142 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3143 | |
| 3144 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3145 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3146 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3147 | 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] | 3148 | 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] | 3149 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3150 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3151 | 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] | 3152 | 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] | 3153 | } |
| 3154 | } |
| 3155 | } |
| 3156 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3157 | void SyncValidator::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 3158 | // Clear out events from the command buffer contexts |
| 3159 | for (auto &cb_context : cb_access_state) { |
| 3160 | cb_context.second->RecordDestroyEvent(event); |
| 3161 | } |
| 3162 | } |
| 3163 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3164 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3165 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 3166 | bool skip = false; |
| 3167 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3168 | assert(cb_context); |
| 3169 | if (!cb_context) return skip; |
| 3170 | const auto *context = cb_context->GetCurrentAccessContext(); |
| 3171 | |
| 3172 | // If we have no previous accesses, we have no hazards |
| 3173 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3174 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3175 | |
| 3176 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3177 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3178 | if (src_buffer) { |
| 3179 | 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] | 3180 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3181 | if (hazard.hazard) { |
| 3182 | // TODO -- add tag information to log msg when useful. |
| 3183 | skip |= LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3184 | "vkCmdCopyBuffer2KHR(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3185 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3186 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3187 | } |
| 3188 | } |
| 3189 | if (dst_buffer && !skip) { |
| 3190 | 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] | 3191 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3192 | if (hazard.hazard) { |
| 3193 | skip |= LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3194 | "vkCmdCopyBuffer2KHR(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3195 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3196 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3197 | } |
| 3198 | } |
| 3199 | if (skip) break; |
| 3200 | } |
| 3201 | return skip; |
| 3202 | } |
| 3203 | |
| 3204 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 3205 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3206 | assert(cb_context); |
| 3207 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER2KHR); |
| 3208 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3209 | |
| 3210 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3211 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3212 | |
| 3213 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3214 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3215 | if (src_buffer) { |
| 3216 | 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] | 3217 | 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] | 3218 | } |
| 3219 | if (dst_buffer) { |
| 3220 | 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] | 3221 | 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] | 3222 | } |
| 3223 | } |
| 3224 | } |
| 3225 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3226 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3227 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3228 | const VkImageCopy *pRegions) const { |
| 3229 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3230 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3231 | assert(cb_access_context); |
| 3232 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3233 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3234 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3235 | assert(context); |
| 3236 | if (!context) return skip; |
| 3237 | |
| 3238 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3239 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3240 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3241 | const auto ©_region = pRegions[region]; |
| 3242 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3243 | 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] | 3244 | copy_region.srcOffset, copy_region.extent); |
| 3245 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3246 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3247 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3248 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3249 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3250 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3254 | VkExtent3D dst_copy_extent = |
| 3255 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3256 | 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] | 3257 | copy_region.dstOffset, dst_copy_extent); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3258 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3259 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3260 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3261 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3262 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3263 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 3264 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3265 | } |
| 3266 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3267 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3268 | return skip; |
| 3269 | } |
| 3270 | |
| 3271 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3272 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3273 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3274 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3275 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3276 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3277 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3278 | assert(context); |
| 3279 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3280 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3281 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3282 | |
| 3283 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3284 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3285 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3286 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3287 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3288 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3289 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3290 | VkExtent3D dst_copy_extent = |
| 3291 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3292 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3293 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3294 | } |
| 3295 | } |
| 3296 | } |
| 3297 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3298 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 3299 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 3300 | bool skip = false; |
| 3301 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3302 | assert(cb_access_context); |
| 3303 | if (!cb_access_context) return skip; |
| 3304 | |
| 3305 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3306 | assert(context); |
| 3307 | if (!context) return skip; |
| 3308 | |
| 3309 | const auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3310 | const auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3311 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3312 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3313 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3314 | 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] | 3315 | copy_region.srcOffset, copy_region.extent); |
| 3316 | if (hazard.hazard) { |
| 3317 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 3318 | "vkCmdCopyImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 3319 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3320 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3321 | } |
| 3322 | } |
| 3323 | |
| 3324 | if (dst_image) { |
| 3325 | VkExtent3D dst_copy_extent = |
| 3326 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3327 | 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] | 3328 | copy_region.dstOffset, dst_copy_extent); |
| 3329 | if (hazard.hazard) { |
| 3330 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 3331 | "vkCmdCopyImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 3332 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3333 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3334 | } |
| 3335 | if (skip) break; |
| 3336 | } |
| 3337 | } |
| 3338 | |
| 3339 | return skip; |
| 3340 | } |
| 3341 | |
| 3342 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 3343 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3344 | assert(cb_access_context); |
| 3345 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE2KHR); |
| 3346 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3347 | assert(context); |
| 3348 | |
| 3349 | auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3350 | auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3351 | |
| 3352 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3353 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3354 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3355 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3356 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3357 | } |
| 3358 | if (dst_image) { |
| 3359 | VkExtent3D dst_copy_extent = |
| 3360 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3361 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3362 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3363 | } |
| 3364 | } |
| 3365 | } |
| 3366 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3367 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3368 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3369 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3370 | uint32_t bufferMemoryBarrierCount, |
| 3371 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3372 | uint32_t imageMemoryBarrierCount, |
| 3373 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 3374 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3375 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3376 | assert(cb_access_context); |
| 3377 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3378 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 3379 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 3380 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 3381 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 3382 | pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 3383 | skip = pipeline_barrier.Validate(*cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3384 | return skip; |
| 3385 | } |
| 3386 | |
| 3387 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3388 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3389 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3390 | uint32_t bufferMemoryBarrierCount, |
| 3391 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3392 | uint32_t imageMemoryBarrierCount, |
| 3393 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3394 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3395 | assert(cb_access_context); |
| 3396 | if (!cb_access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3397 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 3398 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 3399 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 3400 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 3401 | pImageMemoryBarriers); |
| 3402 | pipeline_barrier.Record(cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3403 | } |
| 3404 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 3405 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 3406 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 3407 | bool skip = false; |
| 3408 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3409 | assert(cb_access_context); |
| 3410 | if (!cb_access_context) return skip; |
| 3411 | |
| 3412 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3413 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 3414 | return skip; |
| 3415 | } |
| 3416 | |
| 3417 | void SyncValidator::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) { |
| 3418 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3419 | assert(cb_access_context); |
| 3420 | if (!cb_access_context) return; |
| 3421 | |
| 3422 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3423 | pipeline_barrier.Record(cb_access_context); |
| 3424 | } |
| 3425 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3426 | void SyncValidator::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 3427 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result) { |
| 3428 | // The state tracker sets up the device state |
| 3429 | StateTracker::PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, result); |
| 3430 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3431 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 3432 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3433 | // TODO: Find a good way to do this hooklessly. |
| 3434 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 3435 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, LayerObjectTypeSyncValidation); |
| 3436 | SyncValidator *sync_device_state = static_cast<SyncValidator *>(validation_data); |
| 3437 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3438 | sync_device_state->SetCommandBufferResetCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3439 | sync_device_state->ResetCommandBufferCallback(command_buffer); |
| 3440 | }); |
| 3441 | sync_device_state->SetCommandBufferFreeCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3442 | sync_device_state->FreeCommandBufferCallback(command_buffer); |
| 3443 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3444 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3445 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3446 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3447 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd, const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3448 | bool skip = false; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3449 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3450 | if (cb_context) { |
| 3451 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo, cmd_name); |
| 3452 | skip = sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3453 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3454 | return skip; |
| 3455 | } |
| 3456 | |
| 3457 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3458 | VkSubpassContents contents) const { |
| 3459 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3460 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3461 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3462 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3463 | return skip; |
| 3464 | } |
| 3465 | |
| 3466 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3467 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3468 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3469 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3470 | return skip; |
| 3471 | } |
| 3472 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3473 | static const char *kBeginRenderPass2KhrName = "vkCmdBeginRenderPass2KHR"; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3474 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3475 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3476 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3477 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3478 | skip |= |
| 3479 | ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2, kBeginRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3480 | return skip; |
| 3481 | } |
| 3482 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3483 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 3484 | VkResult result) { |
| 3485 | // The state tracker sets up the command buffer state |
| 3486 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 3487 | |
| 3488 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 3489 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 3490 | assert(cb_access_context); |
| 3491 | cb_access_context->Reset(); |
| 3492 | } |
| 3493 | |
| 3494 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3495 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd, const char *cmd_name) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3496 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3497 | if (cb_context) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3498 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo, cmd_name); |
| 3499 | sync_op.Record(cb_context); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3500 | } |
| 3501 | } |
| 3502 | |
| 3503 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3504 | VkSubpassContents contents) { |
| 3505 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3506 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3507 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3508 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3512 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3513 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3514 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3518 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3519 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3520 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3521 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2, kBeginRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3522 | } |
| 3523 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3524 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3525 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3526 | bool skip = false; |
| 3527 | |
| 3528 | auto cb_context = GetAccessContext(commandBuffer); |
| 3529 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3530 | if (!cb_context) return skip; |
| 3531 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo, cmd_name); |
| 3532 | return sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 3536 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3537 | // Convert to a NextSubpass2 |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3538 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3539 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3540 | auto subpass_end_info = LvlInitStruct<VkSubpassEndInfo>(); |
| 3541 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, &subpass_end_info, CMD_NEXTSUBPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3542 | return skip; |
| 3543 | } |
| 3544 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3545 | static const char *kNextSubpass2KhrName = "vkCmdNextSubpass2KHR"; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3546 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3547 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3548 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3549 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2, kNextSubpass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3550 | return skip; |
| 3551 | } |
| 3552 | |
| 3553 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3554 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 3555 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3556 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3557 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3561 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, const char *cmd_name) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3562 | auto cb_context = GetAccessContext(commandBuffer); |
| 3563 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3564 | if (!cb_context) return; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3565 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3566 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo, cmd_name); |
| 3567 | sync_op.Record(cb_context); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3568 | } |
| 3569 | |
| 3570 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 3571 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3572 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3573 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3574 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3578 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3579 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3580 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3584 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3585 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3586 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2, kNextSubpass2KhrName); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3587 | } |
| 3588 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3589 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, |
| 3590 | const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3591 | bool skip = false; |
| 3592 | |
| 3593 | auto cb_context = GetAccessContext(commandBuffer); |
| 3594 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3595 | if (!cb_context) return skip; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3596 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3597 | SyncOpEndRenderPass sync_op(cmd, *this, pSubpassEndInfo, cmd_name); |
| 3598 | skip |= sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3599 | return skip; |
| 3600 | } |
| 3601 | |
| 3602 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 3603 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3604 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3605 | return skip; |
| 3606 | } |
| 3607 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3608 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3609 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3610 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3611 | return skip; |
| 3612 | } |
| 3613 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3614 | const static char *kEndRenderPass2KhrName = "vkEndRenderPass2KHR"; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3615 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3616 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3617 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3618 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2, kEndRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3619 | return skip; |
| 3620 | } |
| 3621 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3622 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, |
| 3623 | const char *cmd_name) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3624 | // Resolve the all subpass contexts to the command buffer contexts |
| 3625 | auto cb_context = GetAccessContext(commandBuffer); |
| 3626 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3627 | if (!cb_context) return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3628 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3629 | SyncOpEndRenderPass sync_op(cmd, *this, pSubpassEndInfo, cmd_name); |
| 3630 | sync_op.Record(cb_context); |
| 3631 | return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3632 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3633 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 3634 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 3635 | // updates to a resource which do not conflict at the byte level. |
| 3636 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 3637 | // TODO: Add programatic control over suppression heuristics |
| 3638 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 3639 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 3640 | } |
| 3641 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3642 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3643 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3644 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3648 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3649 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3653 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2, kEndRenderPass2KhrName); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3654 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3655 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3656 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3657 | template <typename BufferImageCopyRegionType> |
| 3658 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3659 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3660 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3661 | bool skip = false; |
| 3662 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3663 | assert(cb_access_context); |
| 3664 | if (!cb_access_context) return skip; |
| 3665 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3666 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3667 | const char *func_name = is_2khr ? "vkCmdCopyBufferToImage2KHR()" : "vkCmdCopyBufferToImage()"; |
| 3668 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3669 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3670 | assert(context); |
| 3671 | if (!context) return skip; |
| 3672 | |
| 3673 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3674 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3675 | |
| 3676 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3677 | const auto ©_region = pRegions[region]; |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3678 | HazardResult hazard; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3679 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3680 | if (src_buffer) { |
| 3681 | ResourceAccessRange src_range = |
| 3682 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3683 | hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3684 | if (hazard.hazard) { |
| 3685 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 3686 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3687 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3688 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3689 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3693 | hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.imageSubresource, |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3694 | copy_region.imageOffset, copy_region.imageExtent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3695 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3696 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3697 | "%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] | 3698 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3699 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3700 | } |
| 3701 | if (skip) break; |
| 3702 | } |
| 3703 | if (skip) break; |
| 3704 | } |
| 3705 | return skip; |
| 3706 | } |
| 3707 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3708 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3709 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3710 | const VkBufferImageCopy *pRegions) const { |
| 3711 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
| 3712 | COPY_COMMAND_VERSION_1); |
| 3713 | } |
| 3714 | |
| 3715 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3716 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 3717 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3718 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3719 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3720 | } |
| 3721 | |
| 3722 | template <typename BufferImageCopyRegionType> |
| 3723 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3724 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3725 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3726 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3727 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3728 | |
| 3729 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3730 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYBUFFERTOIMAGE2KHR : CMD_COPYBUFFERTOIMAGE; |
| 3731 | |
| 3732 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3733 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3734 | assert(context); |
| 3735 | |
| 3736 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3737 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3738 | |
| 3739 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3740 | const auto ©_region = pRegions[region]; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3741 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3742 | if (src_buffer) { |
| 3743 | ResourceAccessRange src_range = |
| 3744 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3745 | 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] | 3746 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3747 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3748 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3749 | } |
| 3750 | } |
| 3751 | } |
| 3752 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3753 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3754 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3755 | const VkBufferImageCopy *pRegions) { |
| 3756 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
| 3757 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3758 | } |
| 3759 | |
| 3760 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3761 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 3762 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 3763 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3764 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3765 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3766 | } |
| 3767 | |
| 3768 | template <typename BufferImageCopyRegionType> |
| 3769 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3770 | VkBuffer dstBuffer, uint32_t regionCount, |
| 3771 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3772 | bool skip = false; |
| 3773 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3774 | assert(cb_access_context); |
| 3775 | if (!cb_access_context) return skip; |
| 3776 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3777 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3778 | const char *func_name = is_2khr ? "vkCmdCopyImageToBuffer2KHR()" : "vkCmdCopyImageToBuffer()"; |
| 3779 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3780 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3781 | assert(context); |
| 3782 | if (!context) return skip; |
| 3783 | |
| 3784 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3785 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3786 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->binding.mem_state->mem : VK_NULL_HANDLE; |
| 3787 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3788 | const auto ©_region = pRegions[region]; |
| 3789 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3790 | 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] | 3791 | copy_region.imageOffset, copy_region.imageExtent); |
| 3792 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3793 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3794 | "%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] | 3795 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3796 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3797 | } |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3798 | if (dst_mem) { |
| 3799 | ResourceAccessRange dst_range = |
| 3800 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3801 | hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3802 | if (hazard.hazard) { |
| 3803 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3804 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3805 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3806 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3807 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3808 | } |
| 3809 | } |
| 3810 | if (skip) break; |
| 3811 | } |
| 3812 | return skip; |
| 3813 | } |
| 3814 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3815 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 3816 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 3817 | const VkBufferImageCopy *pRegions) const { |
| 3818 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
| 3819 | COPY_COMMAND_VERSION_1); |
| 3820 | } |
| 3821 | |
| 3822 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3823 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 3824 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3825 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3826 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3827 | } |
| 3828 | |
| 3829 | template <typename BufferImageCopyRegionType> |
| 3830 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3831 | VkBuffer dstBuffer, uint32_t regionCount, const BufferImageCopyRegionType *pRegions, |
| 3832 | CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3833 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3834 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3835 | |
| 3836 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3837 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYIMAGETOBUFFER2KHR : CMD_COPYIMAGETOBUFFER; |
| 3838 | |
| 3839 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3840 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3841 | assert(context); |
| 3842 | |
| 3843 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3844 | auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3845 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->binding.mem_state->mem : VK_NULL_HANDLE; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3846 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3847 | |
| 3848 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3849 | const auto ©_region = pRegions[region]; |
| 3850 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3851 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3852 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3853 | if (dst_buffer) { |
| 3854 | ResourceAccessRange dst_range = |
| 3855 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3856 | 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] | 3857 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3858 | } |
| 3859 | } |
| 3860 | } |
| 3861 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3862 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3863 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 3864 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
| 3865 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3866 | } |
| 3867 | |
| 3868 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3869 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 3870 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 3871 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3872 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3873 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3874 | } |
| 3875 | |
| 3876 | template <typename RegionType> |
| 3877 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3878 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3879 | const RegionType *pRegions, VkFilter filter, const char *apiName) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3880 | bool skip = false; |
| 3881 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3882 | assert(cb_access_context); |
| 3883 | if (!cb_access_context) return skip; |
| 3884 | |
| 3885 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3886 | assert(context); |
| 3887 | if (!context) return skip; |
| 3888 | |
| 3889 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3890 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3891 | |
| 3892 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3893 | const auto &blit_region = pRegions[region]; |
| 3894 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3895 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3896 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3897 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3898 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3899 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3900 | 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] | 3901 | 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] | 3902 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3903 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3904 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3905 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3906 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3911 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3912 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3913 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3914 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3915 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3916 | 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] | 3917 | 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] | 3918 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3919 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3920 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3921 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3922 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3923 | } |
| 3924 | if (skip) break; |
| 3925 | } |
| 3926 | } |
| 3927 | |
| 3928 | return skip; |
| 3929 | } |
| 3930 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3931 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3932 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3933 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 3934 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
| 3935 | "vkCmdBlitImage"); |
| 3936 | } |
| 3937 | |
| 3938 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 3939 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 3940 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 3941 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 3942 | pBlitImageInfo->filter, "vkCmdBlitImage2KHR"); |
| 3943 | } |
| 3944 | |
| 3945 | template <typename RegionType> |
| 3946 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3947 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3948 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3949 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3950 | assert(cb_access_context); |
| 3951 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3952 | assert(context); |
| 3953 | |
| 3954 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3955 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3956 | |
| 3957 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3958 | const auto &blit_region = pRegions[region]; |
| 3959 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3960 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3961 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3962 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3963 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3964 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3965 | 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] | 3966 | context->UpdateAccessState(*src_image, SYNC_BLIT_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3967 | blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3968 | } |
| 3969 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3970 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3971 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3972 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3973 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3974 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3975 | 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] | 3976 | context->UpdateAccessState(*dst_image, SYNC_BLIT_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3977 | blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3978 | } |
| 3979 | } |
| 3980 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3981 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3982 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3983 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3984 | const VkImageBlit *pRegions, VkFilter filter) { |
| 3985 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3986 | assert(cb_access_context); |
| 3987 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 3988 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 3989 | pRegions, filter); |
| 3990 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 3991 | } |
| 3992 | |
| 3993 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 3994 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 3995 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3996 | assert(cb_access_context); |
| 3997 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 3998 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 3999 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4000 | pBlitImageInfo->filter, tag); |
| 4001 | } |
| 4002 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4003 | bool SyncValidator::ValidateIndirectBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4004 | VkCommandBuffer commandBuffer, const VkDeviceSize struct_size, const VkBuffer buffer, |
| 4005 | const VkDeviceSize offset, const uint32_t drawCount, const uint32_t stride, |
| 4006 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4007 | bool skip = false; |
| 4008 | if (drawCount == 0) return skip; |
| 4009 | |
| 4010 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 4011 | VkDeviceSize size = struct_size; |
| 4012 | if (drawCount == 1 || stride == size) { |
| 4013 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4014 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4015 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4016 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4017 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4018 | "%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] | 4019 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4020 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4021 | } |
| 4022 | } else { |
| 4023 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4024 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4025 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4026 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4027 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4028 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
| 4029 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4030 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4031 | break; |
| 4032 | } |
| 4033 | } |
| 4034 | } |
| 4035 | return skip; |
| 4036 | } |
| 4037 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4038 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag &tag, const VkDeviceSize struct_size, |
| 4039 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 4040 | uint32_t stride) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4041 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 4042 | VkDeviceSize size = struct_size; |
| 4043 | if (drawCount == 1 || stride == size) { |
| 4044 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4045 | const ResourceAccessRange range = MakeRange(offset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4046 | 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] | 4047 | } else { |
| 4048 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4049 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4050 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, |
| 4051 | tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4052 | } |
| 4053 | } |
| 4054 | } |
| 4055 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4056 | bool SyncValidator::ValidateCountBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4057 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4058 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4059 | bool skip = false; |
| 4060 | |
| 4061 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4062 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4063 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4064 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4065 | skip |= LogError(count_buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4066 | "%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] | 4067 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4068 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4069 | } |
| 4070 | return skip; |
| 4071 | } |
| 4072 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4073 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag &tag, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4074 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4075 | const ResourceAccessRange range = MakeRange(offset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4076 | 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] | 4077 | } |
| 4078 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4079 | 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] | 4080 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4081 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4082 | assert(cb_access_context); |
| 4083 | if (!cb_access_context) return skip; |
| 4084 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4085 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4086 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | 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] | 4090 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4091 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4092 | assert(cb_access_context); |
| 4093 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4094 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4095 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4096 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4097 | |
| 4098 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4099 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4100 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4101 | assert(cb_access_context); |
| 4102 | if (!cb_access_context) return skip; |
| 4103 | |
| 4104 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4105 | assert(context); |
| 4106 | if (!context) return skip; |
| 4107 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4108 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4109 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, |
| 4110 | 1, sizeof(VkDispatchIndirectCommand), "vkCmdDispatchIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4111 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4112 | } |
| 4113 | |
| 4114 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4115 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4116 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4117 | assert(cb_access_context); |
| 4118 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 4119 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4120 | assert(context); |
| 4121 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4122 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 4123 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4127 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4128 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4129 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4130 | assert(cb_access_context); |
| 4131 | if (!cb_access_context) return skip; |
| 4132 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4133 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw"); |
| 4134 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, "vkCmdDraw"); |
| 4135 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDraw"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4136 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4140 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4141 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4142 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4143 | assert(cb_access_context); |
| 4144 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4145 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4146 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4147 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 4148 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4149 | } |
| 4150 | |
| 4151 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4152 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4153 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4154 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4155 | assert(cb_access_context); |
| 4156 | if (!cb_access_context) return skip; |
| 4157 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4158 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed"); |
| 4159 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, "vkCmdDrawIndexed"); |
| 4160 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexed"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4161 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4165 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4166 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4167 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4168 | assert(cb_access_context); |
| 4169 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4170 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4171 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4172 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 4173 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4177 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4178 | bool skip = false; |
| 4179 | if (drawCount == 0) return skip; |
| 4180 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4181 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4182 | assert(cb_access_context); |
| 4183 | if (!cb_access_context) return skip; |
| 4184 | |
| 4185 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4186 | assert(context); |
| 4187 | if (!context) return skip; |
| 4188 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4189 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect"); |
| 4190 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4191 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4192 | drawCount, stride, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4193 | |
| 4194 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4195 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4196 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4197 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4198 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4202 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4203 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4204 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4205 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4206 | assert(cb_access_context); |
| 4207 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 4208 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4209 | assert(context); |
| 4210 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4211 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4212 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4213 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4214 | |
| 4215 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4216 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4217 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4218 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4222 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4223 | bool skip = false; |
| 4224 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4225 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4226 | assert(cb_access_context); |
| 4227 | if (!cb_access_context) return skip; |
| 4228 | |
| 4229 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4230 | assert(context); |
| 4231 | if (!context) return skip; |
| 4232 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4233 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect"); |
| 4234 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexedIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4235 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4236 | offset, drawCount, stride, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4237 | |
| 4238 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4239 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4240 | // 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] | 4241 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4242 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4243 | } |
| 4244 | |
| 4245 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4246 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4247 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4248 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4249 | assert(cb_access_context); |
| 4250 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 4251 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4252 | assert(context); |
| 4253 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4254 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4255 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4256 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4257 | |
| 4258 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4259 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4260 | // 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] | 4261 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4265 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4266 | uint32_t stride, const char *function) const { |
| 4267 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4268 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4269 | assert(cb_access_context); |
| 4270 | if (!cb_access_context) return skip; |
| 4271 | |
| 4272 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4273 | assert(context); |
| 4274 | if (!context) return skip; |
| 4275 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4276 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4277 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4278 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4279 | maxDrawCount, stride, function); |
| 4280 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4281 | |
| 4282 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4283 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4284 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4285 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4286 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4287 | } |
| 4288 | |
| 4289 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4290 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4291 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4292 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4293 | "vkCmdDrawIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4297 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4298 | uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4299 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4300 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4301 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4302 | assert(cb_access_context); |
| 4303 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECTCOUNT); |
| 4304 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4305 | assert(context); |
| 4306 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4307 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4308 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4309 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 4310 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4311 | |
| 4312 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4313 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4314 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4315 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4319 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4320 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4321 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4322 | "vkCmdDrawIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4326 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4327 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4328 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4329 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4330 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4334 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4335 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4336 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4337 | "vkCmdDrawIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4341 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4342 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4343 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4344 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4345 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4346 | } |
| 4347 | |
| 4348 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4349 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4350 | uint32_t stride, const char *function) const { |
| 4351 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4352 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4353 | assert(cb_access_context); |
| 4354 | if (!cb_access_context) return skip; |
| 4355 | |
| 4356 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4357 | assert(context); |
| 4358 | if (!context) return skip; |
| 4359 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4360 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4361 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4362 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4363 | offset, maxDrawCount, stride, function); |
| 4364 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4365 | |
| 4366 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4367 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4368 | // 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] | 4369 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4370 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4374 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4375 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4376 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4377 | "vkCmdDrawIndexedIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4381 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4382 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4383 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4384 | maxDrawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4385 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4386 | assert(cb_access_context); |
| 4387 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 4388 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4389 | assert(context); |
| 4390 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4391 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4392 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4393 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 4394 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4395 | |
| 4396 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4397 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4398 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 4399 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4400 | } |
| 4401 | |
| 4402 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4403 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4404 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4405 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4406 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4407 | "vkCmdDrawIndexedIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4411 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4412 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4413 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4414 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4415 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4416 | } |
| 4417 | |
| 4418 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4419 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4420 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4421 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4422 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4423 | "vkCmdDrawIndexedIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4424 | } |
| 4425 | |
| 4426 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4427 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4428 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4429 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4430 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4431 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4432 | } |
| 4433 | |
| 4434 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4435 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4436 | const VkImageSubresourceRange *pRanges) const { |
| 4437 | bool skip = false; |
| 4438 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4439 | assert(cb_access_context); |
| 4440 | if (!cb_access_context) return skip; |
| 4441 | |
| 4442 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4443 | assert(context); |
| 4444 | if (!context) return skip; |
| 4445 | |
| 4446 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4447 | |
| 4448 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4449 | const auto &range = pRanges[index]; |
| 4450 | if (image_state) { |
| 4451 | auto hazard = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4452 | context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4453 | if (hazard.hazard) { |
| 4454 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4455 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4456 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4457 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4458 | } |
| 4459 | } |
| 4460 | } |
| 4461 | return skip; |
| 4462 | } |
| 4463 | |
| 4464 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4465 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4466 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4467 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4468 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4469 | assert(cb_access_context); |
| 4470 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 4471 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4472 | assert(context); |
| 4473 | |
| 4474 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4475 | |
| 4476 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4477 | const auto &range = pRanges[index]; |
| 4478 | if (image_state) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4479 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, {0, 0, 0}, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4480 | image_state->createInfo.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4481 | } |
| 4482 | } |
| 4483 | } |
| 4484 | |
| 4485 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 4486 | VkImageLayout imageLayout, |
| 4487 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4488 | const VkImageSubresourceRange *pRanges) const { |
| 4489 | bool skip = false; |
| 4490 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4491 | assert(cb_access_context); |
| 4492 | if (!cb_access_context) return skip; |
| 4493 | |
| 4494 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4495 | assert(context); |
| 4496 | if (!context) return skip; |
| 4497 | |
| 4498 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4499 | |
| 4500 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4501 | const auto &range = pRanges[index]; |
| 4502 | if (image_state) { |
| 4503 | auto hazard = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4504 | context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4505 | if (hazard.hazard) { |
| 4506 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4507 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4508 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4509 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4510 | } |
| 4511 | } |
| 4512 | } |
| 4513 | return skip; |
| 4514 | } |
| 4515 | |
| 4516 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4517 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4518 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4519 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4520 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4521 | assert(cb_access_context); |
| 4522 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 4523 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4524 | assert(context); |
| 4525 | |
| 4526 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4527 | |
| 4528 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4529 | const auto &range = pRanges[index]; |
| 4530 | if (image_state) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4531 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, {0, 0, 0}, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4532 | image_state->createInfo.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4533 | } |
| 4534 | } |
| 4535 | } |
| 4536 | |
| 4537 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4538 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 4539 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 4540 | VkQueryResultFlags flags) const { |
| 4541 | bool skip = false; |
| 4542 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4543 | assert(cb_access_context); |
| 4544 | if (!cb_access_context) return skip; |
| 4545 | |
| 4546 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4547 | assert(context); |
| 4548 | if (!context) return skip; |
| 4549 | |
| 4550 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4551 | |
| 4552 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4553 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4554 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4555 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4556 | skip |= |
| 4557 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4558 | "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] | 4559 | 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] | 4560 | } |
| 4561 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4562 | |
| 4563 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4564 | return skip; |
| 4565 | } |
| 4566 | |
| 4567 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 4568 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4569 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4570 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 4571 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4572 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4573 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4574 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4575 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4576 | assert(context); |
| 4577 | |
| 4578 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4579 | |
| 4580 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4581 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4582 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4583 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4584 | |
| 4585 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4589 | VkDeviceSize size, uint32_t data) const { |
| 4590 | bool skip = false; |
| 4591 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4592 | assert(cb_access_context); |
| 4593 | if (!cb_access_context) return skip; |
| 4594 | |
| 4595 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4596 | assert(context); |
| 4597 | if (!context) return skip; |
| 4598 | |
| 4599 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4600 | |
| 4601 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4602 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4603 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4604 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4605 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4606 | "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] | 4607 | 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] | 4608 | } |
| 4609 | } |
| 4610 | return skip; |
| 4611 | } |
| 4612 | |
| 4613 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4614 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4615 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4616 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4617 | assert(cb_access_context); |
| 4618 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 4619 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4620 | assert(context); |
| 4621 | |
| 4622 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4623 | |
| 4624 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4625 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4626 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4631 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4632 | const VkImageResolve *pRegions) const { |
| 4633 | bool skip = false; |
| 4634 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4635 | assert(cb_access_context); |
| 4636 | if (!cb_access_context) return skip; |
| 4637 | |
| 4638 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4639 | assert(context); |
| 4640 | if (!context) return skip; |
| 4641 | |
| 4642 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4643 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4644 | |
| 4645 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4646 | const auto &resolve_region = pRegions[region]; |
| 4647 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4648 | 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] | 4649 | resolve_region.srcOffset, resolve_region.extent); |
| 4650 | if (hazard.hazard) { |
| 4651 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4652 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4653 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4654 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4655 | } |
| 4656 | } |
| 4657 | |
| 4658 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4659 | 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] | 4660 | resolve_region.dstOffset, resolve_region.extent); |
| 4661 | if (hazard.hazard) { |
| 4662 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4663 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4664 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4665 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4666 | } |
| 4667 | if (skip) break; |
| 4668 | } |
| 4669 | } |
| 4670 | |
| 4671 | return skip; |
| 4672 | } |
| 4673 | |
| 4674 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4675 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4676 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4677 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4678 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4679 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4680 | assert(cb_access_context); |
| 4681 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 4682 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4683 | assert(context); |
| 4684 | |
| 4685 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4686 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4687 | |
| 4688 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4689 | const auto &resolve_region = pRegions[region]; |
| 4690 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4691 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4692 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4693 | } |
| 4694 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4695 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4696 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4697 | } |
| 4698 | } |
| 4699 | } |
| 4700 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4701 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4702 | const VkResolveImageInfo2KHR *pResolveImageInfo) 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 *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4713 | const auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4714 | |
| 4715 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4716 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4717 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4718 | 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] | 4719 | resolve_region.srcOffset, resolve_region.extent); |
| 4720 | if (hazard.hazard) { |
| 4721 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 4722 | "vkCmdResolveImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 4723 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4724 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4725 | } |
| 4726 | } |
| 4727 | |
| 4728 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4729 | 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] | 4730 | resolve_region.dstOffset, resolve_region.extent); |
| 4731 | if (hazard.hazard) { |
| 4732 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 4733 | "vkCmdResolveImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 4734 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4735 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4736 | } |
| 4737 | if (skip) break; |
| 4738 | } |
| 4739 | } |
| 4740 | |
| 4741 | return skip; |
| 4742 | } |
| 4743 | |
| 4744 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4745 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 4746 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 4747 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4748 | assert(cb_access_context); |
| 4749 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE2KHR); |
| 4750 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4751 | assert(context); |
| 4752 | |
| 4753 | auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4754 | auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4755 | |
| 4756 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4757 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4758 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4759 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4760 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4761 | } |
| 4762 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4763 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4764 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4765 | } |
| 4766 | } |
| 4767 | } |
| 4768 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4769 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4770 | VkDeviceSize dataSize, const void *pData) const { |
| 4771 | bool skip = false; |
| 4772 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4773 | assert(cb_access_context); |
| 4774 | if (!cb_access_context) return skip; |
| 4775 | |
| 4776 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4777 | assert(context); |
| 4778 | if (!context) return skip; |
| 4779 | |
| 4780 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4781 | |
| 4782 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4783 | // VK_WHOLE_SIZE not allowed |
| 4784 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4785 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4786 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4787 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4788 | "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] | 4789 | 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] | 4790 | } |
| 4791 | } |
| 4792 | return skip; |
| 4793 | } |
| 4794 | |
| 4795 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4796 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4797 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4798 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4799 | assert(cb_access_context); |
| 4800 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 4801 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4802 | assert(context); |
| 4803 | |
| 4804 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4805 | |
| 4806 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4807 | // VK_WHOLE_SIZE not allowed |
| 4808 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4809 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4810 | } |
| 4811 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4812 | |
| 4813 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4814 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 4815 | bool skip = false; |
| 4816 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4817 | assert(cb_access_context); |
| 4818 | if (!cb_access_context) return skip; |
| 4819 | |
| 4820 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4821 | assert(context); |
| 4822 | if (!context) return skip; |
| 4823 | |
| 4824 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4825 | |
| 4826 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4827 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4828 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4829 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4830 | skip |= |
| 4831 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4832 | "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] | 4833 | 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] | 4834 | } |
| 4835 | } |
| 4836 | return skip; |
| 4837 | } |
| 4838 | |
| 4839 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4840 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4841 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4842 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4843 | assert(cb_access_context); |
| 4844 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 4845 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4846 | assert(context); |
| 4847 | |
| 4848 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4849 | |
| 4850 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4851 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4852 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4853 | } |
| 4854 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4855 | |
| 4856 | bool SyncValidator::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
| 4857 | bool skip = false; |
| 4858 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4859 | assert(cb_context); |
| 4860 | if (!cb_context) return skip; |
| 4861 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4862 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 4863 | return set_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | void SyncValidator::PostCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 4867 | StateTracker::PostCallRecordCmdSetEvent(commandBuffer, event, stageMask); |
| 4868 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4869 | assert(cb_context); |
| 4870 | if (!cb_context) return; |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4871 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4872 | set_event_op.Record(cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4873 | } |
| 4874 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4875 | bool SyncValidator::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4876 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 4877 | bool skip = false; |
| 4878 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4879 | assert(cb_context); |
| 4880 | if (!cb_context || !pDependencyInfo) return skip; |
| 4881 | |
| 4882 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 4883 | return set_event_op.Validate(*cb_context); |
| 4884 | } |
| 4885 | |
| 4886 | void SyncValidator::PostCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4887 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 4888 | StateTracker::PostCallRecordCmdSetEvent2KHR(commandBuffer, event, pDependencyInfo); |
| 4889 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4890 | assert(cb_context); |
| 4891 | if (!cb_context || !pDependencyInfo) return; |
| 4892 | |
| 4893 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 4894 | set_event_op.Record(cb_context); |
| 4895 | } |
| 4896 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4897 | bool SyncValidator::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4898 | VkPipelineStageFlags stageMask) const { |
| 4899 | bool skip = false; |
| 4900 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4901 | assert(cb_context); |
| 4902 | if (!cb_context) return skip; |
| 4903 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4904 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 4905 | return reset_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | void SyncValidator::PostCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 4909 | StateTracker::PostCallRecordCmdResetEvent(commandBuffer, event, stageMask); |
| 4910 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4911 | assert(cb_context); |
| 4912 | if (!cb_context) return; |
| 4913 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4914 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4915 | reset_event_op.Record(cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4916 | } |
| 4917 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4918 | bool SyncValidator::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4919 | VkPipelineStageFlags2KHR stageMask) const { |
| 4920 | bool skip = false; |
| 4921 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4922 | assert(cb_context); |
| 4923 | if (!cb_context) return skip; |
| 4924 | |
| 4925 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4926 | return reset_event_op.Validate(*cb_context); |
| 4927 | } |
| 4928 | |
| 4929 | void SyncValidator::PostCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4930 | VkPipelineStageFlags2KHR stageMask) { |
| 4931 | StateTracker::PostCallRecordCmdResetEvent2KHR(commandBuffer, event, stageMask); |
| 4932 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4933 | assert(cb_context); |
| 4934 | if (!cb_context) return; |
| 4935 | |
| 4936 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4937 | reset_event_op.Record(cb_context); |
| 4938 | } |
| 4939 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4940 | bool SyncValidator::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4941 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4942 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4943 | uint32_t bufferMemoryBarrierCount, |
| 4944 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4945 | uint32_t imageMemoryBarrierCount, |
| 4946 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 4947 | bool skip = false; |
| 4948 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4949 | assert(cb_context); |
| 4950 | if (!cb_context) return skip; |
| 4951 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4952 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 4953 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 4954 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 4955 | return wait_events_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4956 | } |
| 4957 | |
| 4958 | void SyncValidator::PostCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4959 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4960 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4961 | uint32_t bufferMemoryBarrierCount, |
| 4962 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4963 | uint32_t imageMemoryBarrierCount, |
| 4964 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 4965 | StateTracker::PostCallRecordCmdWaitEvents(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
| 4966 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 4967 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 4968 | |
| 4969 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4970 | assert(cb_context); |
| 4971 | if (!cb_context) return; |
| 4972 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4973 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 4974 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 4975 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
| 4976 | return wait_events_op.Record(cb_context); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4977 | } |
| 4978 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4979 | bool SyncValidator::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4980 | const VkDependencyInfoKHR *pDependencyInfos) const { |
| 4981 | bool skip = false; |
| 4982 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4983 | assert(cb_context); |
| 4984 | if (!cb_context) return skip; |
| 4985 | |
| 4986 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 4987 | skip |= wait_events_op.Validate(*cb_context); |
| 4988 | return skip; |
| 4989 | } |
| 4990 | |
| 4991 | void SyncValidator::PostCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4992 | const VkDependencyInfoKHR *pDependencyInfos) { |
| 4993 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 4994 | |
| 4995 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4996 | assert(cb_context); |
| 4997 | if (!cb_context) return; |
| 4998 | |
| 4999 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 5000 | wait_events_op.Record(cb_context); |
| 5001 | } |
| 5002 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5003 | void SyncEventState::ResetFirstScope() { |
| 5004 | for (const auto address_type : kAddressTypes) { |
| 5005 | first_scope[static_cast<size_t>(address_type)].clear(); |
| 5006 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 5007 | scope = SyncExecScope(); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5008 | } |
| 5009 | |
| 5010 | // 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] | 5011 | SyncEventState::IgnoreReason SyncEventState::IsIgnoredByWait(CMD_TYPE cmd, VkPipelineStageFlags2KHR srcStageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5012 | IgnoreReason reason = NotIgnored; |
| 5013 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5014 | if ((CMD_WAITEVENTS2KHR == cmd) && (CMD_SETEVENT == last_command)) { |
| 5015 | reason = SetVsWait2; |
| 5016 | } else if ((last_command == CMD_RESETEVENT || last_command == CMD_RESETEVENT2KHR) && !HasBarrier(0U, 0U)) { |
| 5017 | reason = (last_command == CMD_RESETEVENT) ? ResetWaitRace : Reset2WaitRace; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5018 | } else if (unsynchronized_set) { |
| 5019 | reason = SetRace; |
| 5020 | } else { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5021 | const VkPipelineStageFlags2KHR missing_bits = scope.mask_param & ~srcStageMask; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5022 | if (missing_bits) reason = MissingStageBits; |
| 5023 | } |
| 5024 | |
| 5025 | return reason; |
| 5026 | } |
| 5027 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5028 | bool SyncEventState::HasBarrier(VkPipelineStageFlags2KHR stageMask, VkPipelineStageFlags2KHR exec_scope_arg) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5029 | bool has_barrier = (last_command == CMD_NONE) || (stageMask & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) || |
| 5030 | (barriers & exec_scope_arg) || (barriers & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 5031 | return has_barrier; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5032 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5033 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5034 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5035 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5036 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5037 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5038 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5039 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5040 | : SyncOpBase(cmd), barriers_(1) { |
| 5041 | auto &barrier_set = barriers_[0]; |
| 5042 | barrier_set.dependency_flags = dependencyFlags; |
| 5043 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, srcStageMask); |
| 5044 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, dstStageMask); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5045 | // 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] | 5046 | barrier_set.MakeMemoryBarriers(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, memoryBarrierCount, |
| 5047 | pMemoryBarriers); |
| 5048 | barrier_set.MakeBufferMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 5049 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
| 5050 | barrier_set.MakeImageMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 5051 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5054 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t event_count, |
| 5055 | const VkDependencyInfoKHR *dep_infos) |
| 5056 | : SyncOpBase(cmd), barriers_(event_count) { |
| 5057 | for (uint32_t i = 0; i < event_count; i++) { |
| 5058 | const auto &dep_info = dep_infos[i]; |
| 5059 | auto &barrier_set = barriers_[i]; |
| 5060 | barrier_set.dependency_flags = dep_info.dependencyFlags; |
| 5061 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 5062 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, stage_masks.src); |
| 5063 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, stage_masks.dst); |
| 5064 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
| 5065 | barrier_set.MakeMemoryBarriers(queue_flags, dep_info.dependencyFlags, dep_info.memoryBarrierCount, |
| 5066 | dep_info.pMemoryBarriers); |
| 5067 | barrier_set.MakeBufferMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.bufferMemoryBarrierCount, |
| 5068 | dep_info.pBufferMemoryBarriers); |
| 5069 | barrier_set.MakeImageMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.imageMemoryBarrierCount, |
| 5070 | dep_info.pImageMemoryBarriers); |
| 5071 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5072 | } |
| 5073 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5074 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5075 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5076 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 5077 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5078 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5079 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5080 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5081 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers) {} |
| 5082 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5083 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5084 | const VkDependencyInfoKHR &dep_info) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5085 | : SyncOpBarriers(cmd, sync_state, queue_flags, 1, &dep_info) {} |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5086 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5087 | bool SyncOpPipelineBarrier::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5088 | bool skip = false; |
| 5089 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5090 | assert(context); |
| 5091 | if (!context) return skip; |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5092 | assert(barriers_.size() == 1); // PipelineBarriers only support a single barrier set. |
| 5093 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5094 | // Validate Image Layout transitions |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5095 | const auto &barrier_set = barriers_[0]; |
| 5096 | for (const auto &image_barrier : barrier_set.image_memory_barriers) { |
| 5097 | if (image_barrier.new_layout == image_barrier.old_layout) continue; // Only interested in layout transitions at this point. |
| 5098 | const auto *image_state = image_barrier.image.get(); |
| 5099 | if (!image_state) continue; |
| 5100 | const auto hazard = context->DetectImageBarrierHazard(image_barrier); |
| 5101 | if (hazard.hazard) { |
| 5102 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 5103 | const auto &sync_state = cb_context.GetSyncState(); |
| 5104 | const auto image_handle = image_state->image; |
| 5105 | skip |= sync_state.LogError(image_handle, string_SyncHazardVUID(hazard.hazard), |
| 5106 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5107 | string_SyncHazard(hazard.hazard), image_barrier.index, |
| 5108 | sync_state.report_data->FormatHandle(image_handle).c_str(), |
| 5109 | cb_context.FormatUsage(hazard).c_str()); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5110 | } |
| 5111 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5112 | return skip; |
| 5113 | } |
| 5114 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5115 | struct SyncOpPipelineBarrierFunctorFactory { |
| 5116 | using BarrierOpFunctor = PipelineBarrierOp; |
| 5117 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5118 | using GlobalBarrierOpFunctor = PipelineBarrierOp; |
| 5119 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5120 | using BufferRange = ResourceAccessRange; |
| 5121 | using ImageRange = subresource_adapter::ImageRangeGenerator; |
| 5122 | using GlobalRange = ResourceAccessRange; |
| 5123 | |
| 5124 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier, bool layout_transition) const { |
| 5125 | return ApplyFunctor(BarrierOpFunctor(barrier, layout_transition)); |
| 5126 | } |
| 5127 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, const ResourceUsageTag &tag) const { |
| 5128 | return GlobalApplyFunctor(true /* resolve */, size_hint, tag); |
| 5129 | } |
| 5130 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier) const { |
| 5131 | return GlobalBarrierOpFunctor(barrier, false); |
| 5132 | } |
| 5133 | |
| 5134 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range) const { |
| 5135 | if (!SimpleBinding(buffer)) return ResourceAccessRange(); |
| 5136 | const auto base_address = ResourceBaseAddress(buffer); |
| 5137 | return (range + base_address); |
| 5138 | } |
| 5139 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const SyncImageMemoryBarrier::SubImageRange &range) const { |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 5140 | if (!SimpleBinding(image)) return subresource_adapter::ImageRangeGenerator(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5141 | |
| 5142 | const auto base_address = ResourceBaseAddress(image); |
| 5143 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), range.subresource_range, range.offset, |
| 5144 | range.extent, base_address); |
| 5145 | return range_gen; |
| 5146 | } |
| 5147 | GlobalRange MakeGlobalRangeGen(AccessAddressType) const { return kFullRange; } |
| 5148 | }; |
| 5149 | |
| 5150 | template <typename Barriers, typename FunctorFactory> |
| 5151 | void SyncOpBarriers::ApplyBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag &tag, |
| 5152 | AccessContext *context) { |
| 5153 | for (const auto &barrier : barriers) { |
| 5154 | const auto *state = barrier.GetState(); |
| 5155 | if (state) { |
| 5156 | auto *const accesses = &context->GetAccessStateMap(GetAccessAddressType(*state)); |
| 5157 | auto update_action = factory.MakeApplyFunctor(barrier.barrier, barrier.IsLayoutTransition()); |
| 5158 | auto range_gen = factory.MakeRangeGen(*state, barrier.Range()); |
| 5159 | UpdateMemoryAccessState(accesses, update_action, &range_gen); |
| 5160 | } |
| 5161 | } |
| 5162 | } |
| 5163 | |
| 5164 | template <typename Barriers, typename FunctorFactory> |
| 5165 | void SyncOpBarriers::ApplyGlobalBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag &tag, |
| 5166 | AccessContext *access_context) { |
| 5167 | auto barriers_functor = factory.MakeGlobalApplyFunctor(barriers.size(), tag); |
| 5168 | for (const auto &barrier : barriers) { |
| 5169 | barriers_functor.EmplaceBack(factory.MakeGlobalBarrierOpFunctor(barrier)); |
| 5170 | } |
| 5171 | for (const auto address_type : kAddressTypes) { |
| 5172 | auto range_gen = factory.MakeGlobalRangeGen(address_type); |
| 5173 | UpdateMemoryAccessState(&(access_context->GetAccessStateMap(address_type)), barriers_functor, &range_gen); |
| 5174 | } |
| 5175 | } |
| 5176 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5177 | void SyncOpPipelineBarrier::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5178 | SyncOpPipelineBarrierFunctorFactory factory; |
| 5179 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5180 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5181 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5182 | // Pipeline barriers only have a single barrier set, unlike WaitEvents2 |
| 5183 | assert(barriers_.size() == 1); |
| 5184 | const auto &barrier_set = barriers_[0]; |
| 5185 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5186 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5187 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
| 5188 | |
| 5189 | if (barrier_set.single_exec_scope) { |
| 5190 | cb_context->ApplyGlobalBarriersToEvents(barrier_set.src_exec_scope, barrier_set.dst_exec_scope); |
| 5191 | } else { |
| 5192 | for (const auto &barrier : barrier_set.memory_barriers) { |
| 5193 | cb_context->ApplyGlobalBarriersToEvents(barrier.src_exec_scope, barrier.dst_exec_scope); |
| 5194 | } |
| 5195 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5196 | } |
| 5197 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5198 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(const SyncExecScope &src, const SyncExecScope &dst, |
| 5199 | VkDependencyFlags dependency_flags, uint32_t memory_barrier_count, |
| 5200 | const VkMemoryBarrier *barriers) { |
| 5201 | memory_barriers.reserve(std::max<uint32_t>(1, memory_barrier_count)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5202 | 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] | 5203 | const auto &barrier = barriers[barrier_index]; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5204 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5205 | memory_barriers.emplace_back(sync_barrier); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5206 | } |
| 5207 | if (0 == memory_barrier_count) { |
| 5208 | // If there are no global memory barriers, force an exec barrier |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5209 | memory_barriers.emplace_back(SyncBarrier(src, dst)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5210 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5211 | single_exec_scope = true; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5212 | } |
| 5213 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5214 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5215 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5216 | uint32_t barrier_count, const VkBufferMemoryBarrier *barriers) { |
| 5217 | buffer_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5218 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5219 | const auto &barrier = barriers[index]; |
| 5220 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5221 | if (buffer) { |
| 5222 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5223 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5224 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5225 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5226 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5227 | buffer_memory_barriers.emplace_back(); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5228 | } |
| 5229 | } |
| 5230 | } |
| 5231 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5232 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(VkQueueFlags queue_flags, VkDependencyFlags dependency_flags, |
| 5233 | uint32_t memory_barrier_count, const VkMemoryBarrier2KHR *barriers) { |
| 5234 | memory_barriers.reserve(memory_barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5235 | 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] | 5236 | const auto &barrier = barriers[barrier_index]; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5237 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5238 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5239 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5240 | memory_barriers.emplace_back(sync_barrier); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5241 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5242 | single_exec_scope = false; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5243 | } |
| 5244 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5245 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5246 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5247 | const VkBufferMemoryBarrier2KHR *barriers) { |
| 5248 | buffer_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5249 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5250 | const auto &barrier = barriers[index]; |
| 5251 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5252 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5253 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5254 | if (buffer) { |
| 5255 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5256 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5257 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5258 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5259 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5260 | buffer_memory_barriers.emplace_back(); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5261 | } |
| 5262 | } |
| 5263 | } |
| 5264 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5265 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5266 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5267 | uint32_t barrier_count, const VkImageMemoryBarrier *barriers) { |
| 5268 | image_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5269 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5270 | const auto &barrier = barriers[index]; |
| 5271 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5272 | if (image) { |
| 5273 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5274 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5275 | 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] | 5276 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5277 | image_memory_barriers.emplace_back(); |
| 5278 | 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] | 5279 | } |
| 5280 | } |
| 5281 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5282 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5283 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5284 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5285 | const VkImageMemoryBarrier2KHR *barriers) { |
| 5286 | image_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5287 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5288 | const auto &barrier = barriers[index]; |
| 5289 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5290 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5291 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5292 | if (image) { |
| 5293 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5294 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5295 | 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] | 5296 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5297 | image_memory_barriers.emplace_back(); |
| 5298 | 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] | 5299 | } |
| 5300 | } |
| 5301 | } |
| 5302 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5303 | 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] | 5304 | const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5305 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5306 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5307 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5308 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, VkDependencyFlags(0U), memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5309 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 5310 | pImageMemoryBarriers) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5311 | MakeEventsList(sync_state, eventCount, pEvents); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5314 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t eventCount, |
| 5315 | const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfo) |
| 5316 | : SyncOpBarriers(cmd, sync_state, queue_flags, eventCount, pDependencyInfo) { |
| 5317 | MakeEventsList(sync_state, eventCount, pEvents); |
| 5318 | assert(events_.size() == barriers_.size()); // Just so nobody gets clever and decides to cull the event or barrier arrays |
| 5319 | } |
| 5320 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5321 | bool SyncOpWaitEvents::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5322 | const char *const ignored = "Wait operation is ignored for this event."; |
| 5323 | bool skip = false; |
| 5324 | const auto &sync_state = cb_context.GetSyncState(); |
| 5325 | const auto command_buffer_handle = cb_context.GetCBState().commandBuffer; |
| 5326 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5327 | for (size_t barrier_set_index = 0; barrier_set_index < barriers_.size(); barrier_set_index++) { |
| 5328 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5329 | if (barrier_set.single_exec_scope) { |
| 5330 | if (barrier_set.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5331 | const std::string vuid = std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 5332 | skip = sync_state.LogInfo(command_buffer_handle, vuid, |
| 5333 | "%s, srcStageMask includes %s, unsupported by synchronization validation.", CmdName(), |
| 5334 | string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT)); |
| 5335 | } else { |
| 5336 | const auto &barriers = barrier_set.memory_barriers; |
| 5337 | for (size_t barrier_index = 0; barrier_index < barriers.size(); barrier_index++) { |
| 5338 | const auto &barrier = barriers[barrier_index]; |
| 5339 | if (barrier.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5340 | const std::string vuid = |
| 5341 | std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 5342 | skip = |
| 5343 | sync_state.LogInfo(command_buffer_handle, vuid, |
| 5344 | "%s, srcStageMask %s of %s %zu, %s %zu, unsupported by synchronization validation.", |
| 5345 | CmdName(), string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT), |
| 5346 | "pDependencyInfo", barrier_set_index, "pMemoryBarriers", barrier_index); |
| 5347 | } |
| 5348 | } |
| 5349 | } |
| 5350 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5351 | } |
| 5352 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5353 | VkPipelineStageFlags2KHR event_stage_masks = 0U; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5354 | VkPipelineStageFlags2KHR barrier_mask_params = 0U; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5355 | bool events_not_found = false; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5356 | const auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5357 | assert(events_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5358 | size_t barrier_set_index = 0; |
| 5359 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 5360 | for (size_t event_index = 0; event_index < events_.size(); event_index++) |
| 5361 | for (const auto &event : events_) { |
| 5362 | const auto *sync_event = events_context->Get(event.get()); |
| 5363 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5364 | if (!sync_event) { |
| 5365 | // NOTE PHASE2: This is where we'll need queue submit time validation to come back and check the srcStageMask bits |
| 5366 | // or solve this with replay creating the SyncEventState in the queue context... also this will be a |
| 5367 | // new validation error... wait without previously submitted set event... |
| 5368 | events_not_found = true; // Demote "extra_stage_bits" error to warning, to avoid false positives at *record time* |
| 5369 | barrier_set_index += barrier_set_incr; |
| 5370 | continue; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5371 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5372 | const auto event_handle = sync_event->event->event; |
| 5373 | // TODO add "destroyed" checks |
| 5374 | |
| 5375 | barrier_mask_params |= barrier_set.src_exec_scope.mask_param; |
| 5376 | const auto &src_exec_scope = barrier_set.src_exec_scope; |
| 5377 | event_stage_masks |= sync_event->scope.mask_param; |
| 5378 | const auto ignore_reason = sync_event->IsIgnoredByWait(cmd_, src_exec_scope.mask_param); |
| 5379 | if (ignore_reason) { |
| 5380 | switch (ignore_reason) { |
| 5381 | case SyncEventState::ResetWaitRace: |
| 5382 | case SyncEventState::Reset2WaitRace: { |
| 5383 | // Four permuations of Reset and Wait calls... |
| 5384 | const char *vuid = |
| 5385 | (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent-event-03834" : "VUID-vkCmdResetEvent-event-03835"; |
| 5386 | if (ignore_reason == SyncEventState::Reset2WaitRace) { |
| 5387 | vuid = |
Jeremy Gebben | 476f5e2 | 2021-03-01 15:27:20 -0700 | [diff] [blame] | 5388 | (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent2KHR-event-03831" : "VUID-vkCmdResetEvent2KHR-event-03832"; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5389 | } |
| 5390 | const char *const message = |
| 5391 | "%s: %s %s operation following %s without intervening execution barrier, may cause race condition. %s"; |
| 5392 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5393 | sync_state.report_data->FormatHandle(event_handle).c_str(), CmdName(), |
| 5394 | CommandTypeString(sync_event->last_command), ignored); |
| 5395 | break; |
| 5396 | } |
| 5397 | case SyncEventState::SetRace: { |
| 5398 | // Issue error message that Wait is waiting on an signal subject to race condition, and is thus ignored for |
| 5399 | // this event |
| 5400 | const char *const vuid = "SYNC-vkCmdWaitEvents-unsynchronized-setops"; |
| 5401 | const char *const message = |
| 5402 | "%s: %s Unsychronized %s calls result in race conditions w.r.t. event signalling, %s %s"; |
| 5403 | const char *const reason = "First synchronization scope is undefined."; |
| 5404 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5405 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5406 | CommandTypeString(sync_event->last_command), reason, ignored); |
| 5407 | break; |
| 5408 | } |
| 5409 | case SyncEventState::MissingStageBits: { |
| 5410 | const auto missing_bits = sync_event->scope.mask_param & ~src_exec_scope.mask_param; |
| 5411 | // Issue error message that event waited for is not in wait events scope |
| 5412 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 5413 | const char *const message = |
| 5414 | "%s: %s stageMask %" PRIx64 " includes bits not present in srcStageMask 0x%" PRIx64 |
| 5415 | ". Bits missing from srcStageMask %s. %s"; |
| 5416 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5417 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5418 | sync_event->scope.mask_param, src_exec_scope.mask_param, |
| 5419 | sync_utils::StringPipelineStageFlags(missing_bits).c_str(), ignored); |
| 5420 | break; |
| 5421 | } |
| 5422 | case SyncEventState::SetVsWait2: { |
| 5423 | skip |= sync_state.LogError(event_handle, "VUID-vkCmdWaitEvents2KHR-pEvents-03837", |
| 5424 | "%s: Follows set of %s by %s. Disallowed.", CmdName(), |
| 5425 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5426 | CommandTypeString(sync_event->last_command)); |
| 5427 | break; |
| 5428 | } |
| 5429 | default: |
| 5430 | assert(ignore_reason == SyncEventState::NotIgnored); |
| 5431 | } |
| 5432 | } else if (barrier_set.image_memory_barriers.size()) { |
| 5433 | const auto &image_memory_barriers = barrier_set.image_memory_barriers; |
| 5434 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5435 | assert(context); |
| 5436 | for (const auto &image_memory_barrier : image_memory_barriers) { |
| 5437 | if (image_memory_barrier.old_layout == image_memory_barrier.new_layout) continue; |
| 5438 | const auto *image_state = image_memory_barrier.image.get(); |
| 5439 | if (!image_state) continue; |
| 5440 | const auto &subresource_range = image_memory_barrier.range.subresource_range; |
| 5441 | const auto &src_access_scope = image_memory_barrier.barrier.src_access_scope; |
| 5442 | const auto hazard = |
| 5443 | context->DetectImageBarrierHazard(*image_state, sync_event->scope.exec_scope, src_access_scope, |
| 5444 | subresource_range, *sync_event, AccessContext::DetectOptions::kDetectAll); |
| 5445 | if (hazard.hazard) { |
| 5446 | skip |= sync_state.LogError(image_state->image, string_SyncHazardVUID(hazard.hazard), |
| 5447 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5448 | string_SyncHazard(hazard.hazard), image_memory_barrier.index, |
| 5449 | sync_state.report_data->FormatHandle(image_state->image).c_str(), |
| 5450 | cb_context.FormatUsage(hazard).c_str()); |
| 5451 | break; |
| 5452 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5453 | } |
| 5454 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5455 | // TODO: Add infrastructure for checking pDependencyInfo's vs. CmdSetEvent2 VUID - vkCmdWaitEvents2KHR - pEvents - |
| 5456 | // 03839 |
| 5457 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5458 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5459 | |
| 5460 | // 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] | 5461 | 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] | 5462 | if (extra_stage_bits) { |
| 5463 | // 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] | 5464 | // NOTE: This isn't exactly the right VUID for WaitEvents2, but it's as close as we currently have support for |
| 5465 | const char *const vuid = |
| 5466 | (CMD_WAITEVENTS == cmd_) ? "VUID-vkCmdWaitEvents-srcStageMask-01158" : "VUID-vkCmdWaitEvents2KHR-pEvents-03838"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5467 | const char *const message = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5468 | "%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] | 5469 | if (events_not_found) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5470 | 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] | 5471 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5472 | " vkCmdSetEvent may be in previously submitted command buffer."); |
| 5473 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5474 | 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] | 5475 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), ""); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5476 | } |
| 5477 | } |
| 5478 | return skip; |
| 5479 | } |
| 5480 | |
| 5481 | struct SyncOpWaitEventsFunctorFactory { |
| 5482 | using BarrierOpFunctor = WaitEventBarrierOp; |
| 5483 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5484 | using GlobalBarrierOpFunctor = WaitEventBarrierOp; |
| 5485 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5486 | using BufferRange = EventSimpleRangeGenerator; |
| 5487 | using ImageRange = EventImageRangeGenerator; |
| 5488 | using GlobalRange = EventSimpleRangeGenerator; |
| 5489 | |
| 5490 | // Need to restrict to only valid exec and access scope for this event |
| 5491 | // Pass by value is intentional to get a copy we can change without modifying the passed barrier |
| 5492 | SyncBarrier RestrictToEvent(SyncBarrier barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 5493 | 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] | 5494 | barrier.src_access_scope = sync_event->scope.valid_accesses & barrier.src_access_scope; |
| 5495 | return barrier; |
| 5496 | } |
| 5497 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier_arg, bool layout_transition) const { |
| 5498 | auto barrier = RestrictToEvent(barrier_arg); |
| 5499 | return ApplyFunctor(BarrierOpFunctor(sync_event->first_scope_tag, barrier, layout_transition)); |
| 5500 | } |
| 5501 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, const ResourceUsageTag &tag) const { |
| 5502 | return GlobalApplyFunctor(false /* don't resolve */, size_hint, tag); |
| 5503 | } |
| 5504 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier_arg) const { |
| 5505 | auto barrier = RestrictToEvent(barrier_arg); |
| 5506 | return GlobalBarrierOpFunctor(sync_event->first_scope_tag, barrier, false); |
| 5507 | } |
| 5508 | |
| 5509 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range_arg) const { |
| 5510 | const AccessAddressType address_type = GetAccessAddressType(buffer); |
| 5511 | const auto base_address = ResourceBaseAddress(buffer); |
| 5512 | ResourceAccessRange range = SimpleBinding(buffer) ? (range_arg + base_address) : ResourceAccessRange(); |
| 5513 | EventSimpleRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), range); |
| 5514 | return filtered_range_gen; |
| 5515 | } |
| 5516 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const SyncImageMemoryBarrier::SubImageRange &range) const { |
| 5517 | if (!SimpleBinding(image)) return ImageRange(); |
| 5518 | const auto address_type = GetAccessAddressType(image); |
| 5519 | const auto base_address = ResourceBaseAddress(image); |
| 5520 | subresource_adapter::ImageRangeGenerator image_range_gen(*image.fragment_encoder.get(), range.subresource_range, |
| 5521 | range.offset, range.extent, base_address); |
| 5522 | EventImageRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), image_range_gen); |
| 5523 | |
| 5524 | return filtered_range_gen; |
| 5525 | } |
| 5526 | GlobalRange MakeGlobalRangeGen(AccessAddressType address_type) const { |
| 5527 | return EventSimpleRangeGenerator(sync_event->FirstScope(address_type), kFullRange); |
| 5528 | } |
| 5529 | SyncOpWaitEventsFunctorFactory(SyncEventState *sync_event_) : sync_event(sync_event_) { assert(sync_event); } |
| 5530 | SyncEventState *sync_event; |
| 5531 | }; |
| 5532 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5533 | void SyncOpWaitEvents::Record(CommandBufferAccessContext *cb_context) const { |
| 5534 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5535 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5536 | assert(access_context); |
| 5537 | if (!access_context) return; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5538 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5539 | assert(events_context); |
| 5540 | if (!events_context) return; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5541 | |
| 5542 | // Unlike PipelineBarrier, WaitEvent is *not* limited to accesses within the current subpass (if any) and thus needs to import |
| 5543 | // all accesses. Can instead import for all first_scopes, or a union of them, if this becomes a performance/memory issue, |
| 5544 | // but with no idea of the performance of the union, nor of whether it even matters... take the simplest approach here, |
| 5545 | access_context->ResolvePreviousAccesses(); |
| 5546 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5547 | // TODO... this needs change the SyncEventContext it's using depending on whether this is replay... the recorded |
| 5548 | // 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] | 5549 | size_t barrier_set_index = 0; |
| 5550 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 5551 | assert(barriers_.size() == 1 || (barriers_.size() == events_.size())); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5552 | for (auto &event_shared : events_) { |
| 5553 | if (!event_shared.get()) continue; |
| 5554 | auto *sync_event = events_context->GetFromShared(event_shared); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5555 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5556 | sync_event->last_command = cmd_; |
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 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5559 | const auto &dst = barrier_set.dst_exec_scope; |
| 5560 | if (!sync_event->IsIgnoredByWait(cmd_, barrier_set.src_exec_scope.mask_param)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5561 | // These apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 5562 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 5563 | // of the barriers is maintained. |
| 5564 | SyncOpWaitEventsFunctorFactory factory(sync_event); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5565 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5566 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5567 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5568 | |
| 5569 | // Apply the global barrier to the event itself (for race condition tracking) |
| 5570 | // Events don't happen at a stage, so we need to store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 5571 | sync_event->barriers = dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 5572 | sync_event->barriers |= dst.exec_scope; |
| 5573 | } else { |
| 5574 | // We ignored this wait, so we don't have any effective synchronization barriers for it. |
| 5575 | sync_event->barriers = 0U; |
| 5576 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5577 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | // Apply the pending barriers |
| 5581 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
| 5582 | access_context->ApplyToContext(apply_pending_action); |
| 5583 | } |
| 5584 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5585 | bool SyncValidator::PreCallValidateCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 5586 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 5587 | bool skip = false; |
| 5588 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5589 | assert(cb_access_context); |
| 5590 | if (!cb_access_context) return skip; |
| 5591 | |
| 5592 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5593 | assert(context); |
| 5594 | if (!context) return skip; |
| 5595 | |
| 5596 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5597 | |
| 5598 | if (dst_buffer) { |
| 5599 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 5600 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
| 5601 | if (hazard.hazard) { |
| 5602 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5603 | "vkCmdWriteBufferMarkerAMD2: Hazard %s for dstBuffer %s. Access info %s.", |
| 5604 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), |
| 5605 | string_UsageTag(hazard.tag).c_str()); |
| 5606 | } |
| 5607 | } |
| 5608 | return skip; |
| 5609 | } |
| 5610 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5611 | 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] | 5612 | events_.reserve(event_count); |
| 5613 | for (uint32_t event_index = 0; event_index < event_count; event_index++) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5614 | events_.emplace_back(sync_state.GetShared<EVENT_STATE>(events[event_index])); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5615 | } |
| 5616 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5617 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5618 | 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] | 5619 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5620 | : SyncOpBase(cmd), |
| 5621 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
| 5622 | exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5623 | |
| 5624 | bool SyncOpResetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5625 | auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5626 | assert(events_context); |
| 5627 | bool skip = false; |
| 5628 | if (!events_context) return skip; |
| 5629 | |
| 5630 | const auto &sync_state = cb_context.GetSyncState(); |
| 5631 | const auto *sync_event = events_context->Get(event_); |
| 5632 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5633 | |
| 5634 | const char *const set_wait = |
| 5635 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 5636 | "hazards."; |
| 5637 | const char *message = set_wait; // Only one message this call. |
| 5638 | if (!sync_event->HasBarrier(exec_scope_.mask_param, exec_scope_.exec_scope)) { |
| 5639 | const char *vuid = nullptr; |
| 5640 | switch (sync_event->last_command) { |
| 5641 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5642 | case CMD_SETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5643 | // Needs a barrier between set and reset |
| 5644 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-set"; |
| 5645 | break; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5646 | case CMD_WAITEVENTS: |
| 5647 | case CMD_WAITEVENTS2KHR: { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5648 | // Needs to be in the barriers chain (either because of a barrier, or because of dstStageMask |
| 5649 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-wait"; |
| 5650 | break; |
| 5651 | } |
| 5652 | default: |
| 5653 | // The only other valid last command that wasn't one. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5654 | assert((sync_event->last_command == CMD_NONE) || (sync_event->last_command == CMD_RESETEVENT) || |
| 5655 | (sync_event->last_command == CMD_RESETEVENT2KHR)); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5656 | break; |
| 5657 | } |
| 5658 | if (vuid) { |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5659 | skip |= sync_state.LogError(event_->event, vuid, message, CmdName(), |
| 5660 | sync_state.report_data->FormatHandle(event_->event).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5661 | CommandTypeString(sync_event->last_command)); |
| 5662 | } |
| 5663 | } |
| 5664 | return skip; |
| 5665 | } |
| 5666 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5667 | void SyncOpResetEvent::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5668 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5669 | assert(events_context); |
| 5670 | if (!events_context) return; |
| 5671 | |
| 5672 | auto *sync_event = events_context->GetFromShared(event_); |
| 5673 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5674 | |
| 5675 | // Update the event state |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5676 | sync_event->last_command = cmd_; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5677 | sync_event->unsynchronized_set = CMD_NONE; |
| 5678 | sync_event->ResetFirstScope(); |
| 5679 | sync_event->barriers = 0U; |
| 5680 | } |
| 5681 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5682 | 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] | 5683 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5684 | : SyncOpBase(cmd), |
| 5685 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5686 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)), |
| 5687 | dep_info_() {} |
| 5688 | |
| 5689 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
| 5690 | const VkDependencyInfoKHR &dep_info) |
| 5691 | : SyncOpBase(cmd), |
| 5692 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
| 5693 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, sync_utils::GetGlobalStageMasks(dep_info).src)), |
| 5694 | dep_info_(new safe_VkDependencyInfoKHR(&dep_info)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5695 | |
| 5696 | bool SyncOpSetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5697 | // 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] | 5698 | bool skip = false; |
| 5699 | |
| 5700 | const auto &sync_state = cb_context.GetSyncState(); |
| 5701 | auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5702 | assert(events_context); |
| 5703 | if (!events_context) return skip; |
| 5704 | |
| 5705 | const auto *sync_event = events_context->Get(event_); |
| 5706 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5707 | |
| 5708 | const char *const reset_set = |
| 5709 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 5710 | "hazards."; |
| 5711 | const char *const wait = |
| 5712 | "%s: %s %s operation following %s without intervening vkCmdResetEvent, may result in data hazard and is ignored."; |
| 5713 | |
| 5714 | 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] | 5715 | const char *vuid_stem = nullptr; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5716 | const char *message = nullptr; |
| 5717 | switch (sync_event->last_command) { |
| 5718 | case CMD_RESETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5719 | case CMD_RESETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5720 | // Needs a barrier between reset and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5721 | vuid_stem = "-missingbarrier-reset"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5722 | message = reset_set; |
| 5723 | break; |
| 5724 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5725 | case CMD_SETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5726 | // Needs a barrier between set and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5727 | vuid_stem = "-missingbarrier-set"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5728 | message = reset_set; |
| 5729 | break; |
| 5730 | case CMD_WAITEVENTS: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5731 | case CMD_WAITEVENTS2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5732 | // Needs a barrier or is in second execution scope |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5733 | vuid_stem = "-missingbarrier-wait"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5734 | message = wait; |
| 5735 | break; |
| 5736 | default: |
| 5737 | // The only other valid last command that wasn't one. |
| 5738 | assert(sync_event->last_command == CMD_NONE); |
| 5739 | break; |
| 5740 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5741 | if (vuid_stem) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5742 | assert(nullptr != message); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5743 | std::string vuid("SYNC-"); |
| 5744 | vuid.append(CmdName()).append(vuid_stem); |
| 5745 | skip |= sync_state.LogError(event_->event, vuid.c_str(), message, CmdName(), |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5746 | sync_state.report_data->FormatHandle(event_->event).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5747 | CommandTypeString(sync_event->last_command)); |
| 5748 | } |
| 5749 | } |
| 5750 | |
| 5751 | return skip; |
| 5752 | } |
| 5753 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5754 | void SyncOpSetEvent::Record(CommandBufferAccessContext *cb_context) const { |
| 5755 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5756 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5757 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5758 | assert(events_context); |
| 5759 | if (!events_context) return; |
| 5760 | |
| 5761 | auto *sync_event = events_context->GetFromShared(event_); |
| 5762 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5763 | |
| 5764 | // NOTE: We're going to simply record the sync scope here, as anything else would be implementation defined/undefined |
| 5765 | // and we're issuing errors re: missing barriers between event commands, which if the user fixes would fix |
| 5766 | // any issues caused by naive scope setting here. |
| 5767 | |
| 5768 | // What happens with two SetEvent is that one cannot know what group of operations will be waited for. |
| 5769 | // Given: |
| 5770 | // Stuff1; SetEvent; Stuff2; SetEvent; WaitEvents; |
| 5771 | // WaitEvents cannot know which of Stuff1, Stuff2, or both has completed execution. |
| 5772 | |
| 5773 | if (!sync_event->HasBarrier(src_exec_scope_.mask_param, src_exec_scope_.exec_scope)) { |
| 5774 | sync_event->unsynchronized_set = sync_event->last_command; |
| 5775 | sync_event->ResetFirstScope(); |
| 5776 | } else if (sync_event->scope.exec_scope == 0) { |
| 5777 | // We only set the scope if there isn't one |
| 5778 | sync_event->scope = src_exec_scope_; |
| 5779 | |
| 5780 | auto set_scope = [&sync_event](AccessAddressType address_type, const ResourceAccessRangeMap::value_type &access) { |
| 5781 | auto &scope_map = sync_event->first_scope[static_cast<size_t>(address_type)]; |
| 5782 | if (access.second.InSourceScopeOrChain(sync_event->scope.exec_scope, sync_event->scope.valid_accesses)) { |
| 5783 | scope_map.insert(scope_map.end(), std::make_pair(access.first, true)); |
| 5784 | } |
| 5785 | }; |
| 5786 | access_context->ForAll(set_scope); |
| 5787 | sync_event->unsynchronized_set = CMD_NONE; |
| 5788 | sync_event->first_scope_tag = tag; |
| 5789 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5790 | // TODO: Store dep_info_ shared ptr in sync_state for WaitEvents2 validation |
| 5791 | sync_event->last_command = cmd_; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5792 | sync_event->barriers = 0U; |
| 5793 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 5794 | |
| 5795 | SyncOpBeginRenderPass::SyncOpBeginRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, |
| 5796 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 5797 | const VkSubpassBeginInfo *pSubpassBeginInfo, const char *cmd_name) |
| 5798 | : SyncOpBase(cmd, cmd_name) { |
| 5799 | if (pRenderPassBegin) { |
| 5800 | rp_state_ = sync_state.GetShared<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
| 5801 | renderpass_begin_info_ = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
| 5802 | const auto *fb_state = sync_state.Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
| 5803 | if (fb_state) { |
| 5804 | shared_attachments_ = sync_state.GetSharedAttachmentViews(*renderpass_begin_info_.ptr(), *fb_state); |
| 5805 | // TODO: Revisit this when all attachment validation is through SyncOps to see if we can discard the plain pointer copy |
| 5806 | // Note that this a safe to presist as long as shared_attachments is not cleared |
| 5807 | attachments_.reserve(shared_attachments_.size()); |
sfricke-samsung | 01c9ae9 | 2021-02-09 22:30:52 -0800 | [diff] [blame] | 5808 | for (const auto &attachment : shared_attachments_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 5809 | attachments_.emplace_back(attachment.get()); |
| 5810 | } |
| 5811 | } |
| 5812 | if (pSubpassBeginInfo) { |
| 5813 | subpass_begin_info_ = safe_VkSubpassBeginInfo(pSubpassBeginInfo); |
| 5814 | } |
| 5815 | } |
| 5816 | } |
| 5817 | |
| 5818 | bool SyncOpBeginRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5819 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 5820 | bool skip = false; |
| 5821 | |
| 5822 | assert(rp_state_.get()); |
| 5823 | if (nullptr == rp_state_.get()) return skip; |
| 5824 | auto &rp_state = *rp_state_.get(); |
| 5825 | |
| 5826 | const uint32_t subpass = 0; |
| 5827 | |
| 5828 | // Construct the state we can use to validate against... (since validation is const and RecordCmdBeginRenderPass |
| 5829 | // hasn't happened yet) |
| 5830 | const std::vector<AccessContext> empty_context_vector; |
| 5831 | AccessContext temp_context(subpass, cb_context.GetQueueFlags(), rp_state.subpass_dependencies, empty_context_vector, |
| 5832 | cb_context.GetCurrentAccessContext()); |
| 5833 | |
| 5834 | // Validate attachment operations |
| 5835 | if (attachments_.size() == 0) return skip; |
| 5836 | const auto &render_area = renderpass_begin_info_.renderArea; |
| 5837 | skip |= temp_context.ValidateLayoutTransitions(cb_context, rp_state, render_area, subpass, attachments_, CmdName()); |
| 5838 | |
| 5839 | // Validate load operations if there were no layout transition hazards |
| 5840 | if (!skip) { |
| 5841 | temp_context.RecordLayoutTransitions(rp_state, subpass, attachments_, kCurrentCommandTag); |
| 5842 | skip |= temp_context.ValidateLoadOperation(cb_context, rp_state, render_area, subpass, attachments_, CmdName()); |
| 5843 | } |
| 5844 | |
| 5845 | return skip; |
| 5846 | } |
| 5847 | |
| 5848 | void SyncOpBeginRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
| 5849 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5850 | assert(rp_state_.get()); |
| 5851 | if (nullptr == rp_state_.get()) return; |
| 5852 | const auto tag = cb_context->NextCommandTag(cmd_); |
| 5853 | cb_context->RecordBeginRenderPass(*rp_state_.get(), renderpass_begin_info_.renderArea, attachments_, tag); |
| 5854 | } |
| 5855 | |
| 5856 | SyncOpNextSubpass::SyncOpNextSubpass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 5857 | const VkSubpassEndInfo *pSubpassEndInfo, const char *name_override) |
| 5858 | : SyncOpBase(cmd, name_override) { |
| 5859 | if (pSubpassBeginInfo) { |
| 5860 | subpass_begin_info_.initialize(pSubpassBeginInfo); |
| 5861 | } |
| 5862 | if (pSubpassEndInfo) { |
| 5863 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 5864 | } |
| 5865 | } |
| 5866 | |
| 5867 | bool SyncOpNextSubpass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5868 | bool skip = false; |
| 5869 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 5870 | if (!renderpass_context) return skip; |
| 5871 | |
| 5872 | skip |= renderpass_context->ValidateNextSubpass(cb_context.GetExecutionContext(), CmdName()); |
| 5873 | return skip; |
| 5874 | } |
| 5875 | |
| 5876 | void SyncOpNextSubpass::Record(CommandBufferAccessContext *cb_context) const { |
| 5877 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5878 | cb_context->RecordNextSubpass(cmd_); |
| 5879 | } |
| 5880 | |
| 5881 | SyncOpEndRenderPass::SyncOpEndRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassEndInfo *pSubpassEndInfo, |
| 5882 | const char *name_override) |
| 5883 | : SyncOpBase(cmd, name_override) { |
| 5884 | if (pSubpassEndInfo) { |
| 5885 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 5886 | } |
| 5887 | } |
| 5888 | |
| 5889 | bool SyncOpEndRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5890 | bool skip = false; |
| 5891 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 5892 | |
| 5893 | if (!renderpass_context) return skip; |
| 5894 | skip |= renderpass_context->ValidateEndRenderPass(cb_context.GetExecutionContext(), CmdName()); |
| 5895 | return skip; |
| 5896 | } |
| 5897 | |
| 5898 | void SyncOpEndRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
| 5899 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5900 | cb_context->RecordEndRenderPass(cmd_); |
| 5901 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5902 | |
| 5903 | void SyncValidator::PreCallRecordCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 5904 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
| 5905 | StateTracker::PreCallRecordCmdWriteBufferMarker2AMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
| 5906 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5907 | assert(cb_access_context); |
| 5908 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 5909 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5910 | assert(context); |
| 5911 | |
| 5912 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5913 | |
| 5914 | if (dst_buffer) { |
| 5915 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 5916 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
| 5917 | } |
| 5918 | } |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 5919 | |
| 5920 | #ifdef SYNCVAL_DIAGNOSTICS |
| 5921 | bool SyncValidator::PreCallValidateDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) const { |
| 5922 | sync_diagnostics.InstanceDump(instance); |
| 5923 | ImageRangeGen::diag_.Report(); |
| 5924 | return StateTracker::PreCallValidateDestroyInstance(instance, pAllocator); |
| 5925 | } |
| 5926 | #endif |