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> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 552 | void ResolveOperation(Action &action, const RENDER_PASS_STATE &rp_state, const AttachmentViewGenVector &attachment_views, |
| 553 | uint32_t subpass) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 554 | const auto &rp_ci = rp_state.createInfo; |
| 555 | const auto *attachment_ci = rp_ci.pAttachments; |
| 556 | const auto &subpass_ci = rp_ci.pSubpasses[subpass]; |
| 557 | |
| 558 | // Color resolves -- require an inuse color attachment and a matching inuse resolve attachment |
| 559 | const auto *color_attachments = subpass_ci.pColorAttachments; |
| 560 | const auto *color_resolve = subpass_ci.pResolveAttachments; |
| 561 | if (color_resolve && color_attachments) { |
| 562 | for (uint32_t i = 0; i < subpass_ci.colorAttachmentCount; i++) { |
| 563 | const auto &color_attach = color_attachments[i].attachment; |
| 564 | const auto &resolve_attach = subpass_ci.pResolveAttachments[i].attachment; |
| 565 | if ((color_attach != VK_ATTACHMENT_UNUSED) && (resolve_attach != VK_ATTACHMENT_UNUSED)) { |
| 566 | action("color", "resolve read", color_attach, resolve_attach, attachment_views[color_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 567 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, |
| 568 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 569 | action("color", "resolve write", color_attach, resolve_attach, attachment_views[resolve_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 570 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 571 | SyncOrdering::kColorAttachment); |
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; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 587 | |
| 588 | // Figure out which aspects are actually touched during resolve operations |
| 589 | const char *aspect_string = nullptr; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 590 | AttachmentViewGen::Gen gen_type = AttachmentViewGen::Gen::kRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 591 | if (resolve_depth && resolve_stencil) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 592 | aspect_string = "depth/stencil"; |
| 593 | } else if (resolve_depth) { |
| 594 | // Validate depth only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 595 | gen_type = AttachmentViewGen::Gen::kDepthOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 596 | aspect_string = "depth"; |
| 597 | } else if (resolve_stencil) { |
| 598 | // Validate all stencil only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 599 | gen_type = AttachmentViewGen::Gen::kStencilOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 600 | aspect_string = "stencil"; |
| 601 | } |
| 602 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 603 | if (aspect_string) { |
| 604 | action(aspect_string, "resolve read", src_at, dst_at, attachment_views[src_at], gen_type, |
| 605 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, SyncOrdering::kRaster); |
| 606 | action(aspect_string, "resolve write", src_at, dst_at, attachment_views[dst_at], gen_type, |
| 607 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | // Action for validating resolve operations |
| 613 | class ValidateResolveAction { |
| 614 | public: |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 615 | ValidateResolveAction(VkRenderPass render_pass, uint32_t subpass, const AccessContext &context, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 616 | const CommandExecutionContext &ex_context, const char *func_name) |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 617 | : render_pass_(render_pass), |
| 618 | subpass_(subpass), |
| 619 | context_(context), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 620 | ex_context_(ex_context), |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 621 | func_name_(func_name), |
| 622 | skip_(false) {} |
| 623 | void operator()(const char *aspect_name, const char *attachment_name, uint32_t src_at, uint32_t dst_at, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 624 | const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, |
| 625 | SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 626 | HazardResult hazard; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 627 | hazard = context_.DetectHazard(view_gen, gen_type, current_usage, ordering_rule); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 628 | if (hazard.hazard) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 629 | skip_ |= |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 630 | ex_context_.GetSyncState().LogError(render_pass_, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 631 | "%s: Hazard %s in subpass %" PRIu32 "during %s %s, from attachment %" PRIu32 |
| 632 | " to resolve attachment %" PRIu32 ". Access info %s.", |
| 633 | func_name_, string_SyncHazard(hazard.hazard), subpass_, aspect_name, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 634 | attachment_name, src_at, dst_at, ex_context_.FormatUsage(hazard).c_str()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | // Providing a mechanism for the constructing caller to get the result of the validation |
| 638 | bool GetSkip() const { return skip_; } |
| 639 | |
| 640 | private: |
| 641 | VkRenderPass render_pass_; |
| 642 | const uint32_t subpass_; |
| 643 | const AccessContext &context_; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 644 | const CommandExecutionContext &ex_context_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 645 | const char *func_name_; |
| 646 | bool skip_; |
| 647 | }; |
| 648 | |
| 649 | // Update action for resolve operations |
| 650 | class UpdateStateResolveAction { |
| 651 | public: |
| 652 | UpdateStateResolveAction(AccessContext &context, const ResourceUsageTag &tag) : context_(context), tag_(tag) {} |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 653 | void operator()(const char *, const char *, uint32_t, uint32_t, const AttachmentViewGen &view_gen, |
| 654 | AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 655 | // Ignores validation only arguments... |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 656 | context_.UpdateAccessState(view_gen, gen_type, current_usage, ordering_rule, tag_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | private: |
| 660 | AccessContext &context_; |
| 661 | const ResourceUsageTag &tag_; |
| 662 | }; |
| 663 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 664 | void HazardResult::Set(const ResourceAccessState *access_state_, SyncStageAccessIndex usage_index_, SyncHazard hazard_, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 665 | const SyncStageAccessFlags &prior_, const ResourceUsageTag &tag_) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 666 | access_state = std::unique_ptr<const ResourceAccessState>(new ResourceAccessState(*access_state_)); |
| 667 | usage_index = usage_index_; |
| 668 | hazard = hazard_; |
| 669 | prior_access = prior_; |
| 670 | tag = tag_; |
| 671 | } |
| 672 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 673 | AccessContext::AccessContext(uint32_t subpass, VkQueueFlags queue_flags, |
| 674 | const std::vector<SubpassDependencyGraphNode> &dependencies, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 675 | const std::vector<AccessContext> &contexts, const AccessContext *external_context) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 676 | Reset(); |
| 677 | const auto &subpass_dep = dependencies[subpass]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 678 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 679 | prev_.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 680 | 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] | 681 | for (const auto &prev_dep : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 682 | const auto prev_pass = prev_dep.first->pass; |
| 683 | const auto &prev_barriers = prev_dep.second; |
| 684 | assert(prev_dep.second.size()); |
| 685 | prev_.emplace_back(&contexts[prev_pass], queue_flags, prev_barriers); |
| 686 | prev_by_subpass_[prev_pass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 687 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 688 | |
| 689 | async_.reserve(subpass_dep.async.size()); |
| 690 | for (const auto async_subpass : subpass_dep.async) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 691 | async_.emplace_back(&contexts[async_subpass]); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 692 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 693 | if (has_barrier_from_external) { |
| 694 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 695 | prev_.emplace_back(external_context, queue_flags, subpass_dep.barrier_from_external); |
| 696 | src_external_ = &prev_.back(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 697 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 698 | if (subpass_dep.barrier_to_external.size()) { |
| 699 | dst_external_ = TrackBack(this, queue_flags, subpass_dep.barrier_to_external); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 700 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 701 | } |
| 702 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 703 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 704 | HazardResult AccessContext::DetectPreviousHazard(AccessAddressType type, const Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 705 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 706 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 707 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 708 | |
| 709 | HazardResult hazard; |
| 710 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 711 | hazard = detector.Detect(prev); |
| 712 | } |
| 713 | return hazard; |
| 714 | } |
| 715 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 716 | template <typename Action> |
| 717 | void AccessContext::ForAll(Action &&action) { |
| 718 | for (const auto address_type : kAddressTypes) { |
| 719 | auto &accesses = GetAccessStateMap(address_type); |
| 720 | for (const auto &access : accesses) { |
| 721 | action(address_type, access); |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 726 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 727 | // the DAG of the contexts (for example subpasses) |
| 728 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 729 | HazardResult AccessContext::DetectHazard(AccessAddressType type, const Detector &detector, const ResourceAccessRange &range, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 730 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 731 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 732 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 733 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 734 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 735 | // so we'll check these first |
| 736 | for (const auto &async_context : async_) { |
| 737 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 738 | if (hazard.hazard) return hazard; |
| 739 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 740 | } |
| 741 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 742 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 743 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 744 | const auto &accesses = GetAccessStateMap(type); |
| 745 | const auto from = accesses.lower_bound(range); |
| 746 | const auto to = accesses.upper_bound(range); |
| 747 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 748 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 749 | for (auto pos = from; pos != to; ++pos) { |
| 750 | // Cover any leading gap, or gap between entries |
| 751 | if (detect_prev) { |
| 752 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 753 | // Cover any leading gap, or gap between entries |
| 754 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 755 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 756 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 757 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 758 | if (hazard.hazard) return hazard; |
| 759 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 760 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 761 | gap.begin = pos->first.end; |
| 762 | } |
| 763 | |
| 764 | hazard = detector.Detect(pos); |
| 765 | if (hazard.hazard) return hazard; |
| 766 | } |
| 767 | |
| 768 | if (detect_prev) { |
| 769 | // Detect in the trailing empty as needed |
| 770 | gap.end = range.end; |
| 771 | if (gap.non_empty()) { |
| 772 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 773 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | return hazard; |
| 777 | } |
| 778 | |
| 779 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 780 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 781 | HazardResult AccessContext::DetectAsyncHazard(AccessAddressType type, const Detector &detector, |
| 782 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 783 | auto &accesses = GetAccessStateMap(type); |
| 784 | const auto from = accesses.lower_bound(range); |
| 785 | const auto to = accesses.upper_bound(range); |
| 786 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 787 | HazardResult hazard; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 788 | for (auto pos = from; pos != to && !hazard.hazard; ++pos) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 789 | hazard = detector.DetectAsync(pos, start_tag_); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 790 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 791 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 792 | return hazard; |
| 793 | } |
| 794 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 795 | struct ApplySubpassTransitionBarriersAction { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 796 | explicit ApplySubpassTransitionBarriersAction(const std::vector<SyncBarrier> &barriers_) : barriers(barriers_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 797 | void operator()(ResourceAccessState *access) const { |
| 798 | assert(access); |
| 799 | access->ApplyBarriers(barriers, true); |
| 800 | } |
| 801 | const std::vector<SyncBarrier> &barriers; |
| 802 | }; |
| 803 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 804 | struct ApplyTrackbackStackAction { |
| 805 | explicit ApplyTrackbackStackAction(const std::vector<SyncBarrier> &barriers_, |
| 806 | const ResourceAccessStateFunction *previous_barrier_ = nullptr) |
| 807 | : barriers(barriers_), previous_barrier(previous_barrier_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 808 | void operator()(ResourceAccessState *access) const { |
| 809 | assert(access); |
| 810 | assert(!access->HasPendingState()); |
| 811 | access->ApplyBarriers(barriers, false); |
| 812 | access->ApplyPendingBarriers(kCurrentCommandTag); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 813 | if (previous_barrier) { |
| 814 | assert(bool(*previous_barrier)); |
| 815 | (*previous_barrier)(access); |
| 816 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 817 | } |
| 818 | const std::vector<SyncBarrier> &barriers; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 819 | const ResourceAccessStateFunction *previous_barrier; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 820 | }; |
| 821 | |
| 822 | // Splits a single map entry into piece matching the entries in [first, last) the total range over [first, last) must be |
| 823 | // contained with entry. Entry must be an iterator pointing to dest, first and last must be iterators pointing to a |
| 824 | // *different* map from dest. |
| 825 | // Returns the position past the last resolved range -- the entry covering the remainder of entry->first not included in the |
| 826 | // range [first, last) |
| 827 | template <typename BarrierAction> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 828 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 829 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 830 | BarrierAction &barrier_action) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 831 | auto at = entry; |
| 832 | for (auto pos = first; pos != last; ++pos) { |
| 833 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 834 | assert(at->first.includes(pos->first)); |
| 835 | assert(at != dest->end()); |
| 836 | // Trim up at to the same size as the entry to resolve |
| 837 | at = sparse_container::split(at, *dest, pos->first); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 838 | auto access = pos->second; // intentional copy |
| 839 | barrier_action(&access); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 840 | at->second.Resolve(access); |
| 841 | ++at; // Go to the remaining unused section of entry |
| 842 | } |
| 843 | } |
| 844 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 845 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 846 | SyncBarrier merged = {}; |
| 847 | for (const auto &barrier : barriers) { |
| 848 | merged.Merge(barrier); |
| 849 | } |
| 850 | return merged; |
| 851 | } |
| 852 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 853 | template <typename BarrierAction> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 854 | void AccessContext::ResolveAccessRange(AccessAddressType type, const ResourceAccessRange &range, BarrierAction &barrier_action, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 855 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 856 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 857 | if (!range.non_empty()) return; |
| 858 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 859 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 860 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 861 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 862 | if (current->pos_B->valid) { |
| 863 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 864 | auto access = src_pos->second; // intentional copy |
| 865 | barrier_action(&access); |
| 866 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 867 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 868 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 869 | trimmed->second.Resolve(access); |
| 870 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 871 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 872 | 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] | 873 | 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] | 874 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 875 | } else { |
| 876 | // we have to descend to fill this gap |
| 877 | if (recur_to_infill) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 878 | ResourceAccessRange recurrence_range = current_range; |
| 879 | // The current context is empty for the current range, so recur to fill the gap. |
| 880 | // Since we will be recurring back up the DAG, expand the gap descent to cover the full range for which B |
| 881 | // is not valid, to minimize that recurrence |
| 882 | if (current->pos_B.at_end()) { |
| 883 | // Do the remainder here.... |
| 884 | recurrence_range.end = range.end; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 885 | } else { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 886 | // Recur only over the range until B becomes valid (within the limits of range). |
| 887 | 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] | 888 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 889 | ResolvePreviousAccessStack(type, recurrence_range, resolve_map, infill_state, barrier_action); |
| 890 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 891 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 892 | // iterator of the outer while. |
| 893 | |
| 894 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 895 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 896 | // we stepped on the dest map |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 897 | 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] | 898 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 899 | current.seek(seek_to); |
| 900 | } else if (!current->pos_A->valid && infill_state) { |
| 901 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 902 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 903 | 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] | 904 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 905 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 906 | ++current; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 907 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 908 | |
| 909 | // Infill if range goes passed both the current and resolve map prior contents |
| 910 | if (recur_to_infill && (current->range.end < range.end)) { |
| 911 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 912 | ResolvePreviousAccessStack<BarrierAction>(type, trailing_fill_range, resolve_map, infill_state, barrier_action); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 913 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 914 | } |
| 915 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 916 | template <typename BarrierAction> |
| 917 | void AccessContext::ResolvePreviousAccessStack(AccessAddressType type, const ResourceAccessRange &range, |
| 918 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 919 | const BarrierAction &previous_barrier) const { |
| 920 | ResourceAccessStateFunction stacked_barrier(std::ref(previous_barrier)); |
| 921 | ResolvePreviousAccess(type, range, descent_map, infill_state, &stacked_barrier); |
| 922 | } |
| 923 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 924 | void AccessContext::ResolvePreviousAccess(AccessAddressType type, const ResourceAccessRange &range, |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 925 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 926 | const ResourceAccessStateFunction *previous_barrier) const { |
| 927 | if (prev_.size() == 0) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 928 | if (range.non_empty() && infill_state) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 929 | // Fill the empty poritions of descent_map with the default_state with the barrier function applied (iff present) |
| 930 | ResourceAccessState state_copy; |
| 931 | if (previous_barrier) { |
| 932 | assert(bool(*previous_barrier)); |
| 933 | state_copy = *infill_state; |
| 934 | (*previous_barrier)(&state_copy); |
| 935 | infill_state = &state_copy; |
| 936 | } |
| 937 | sparse_container::update_range_value(*descent_map, range, *infill_state, |
| 938 | sparse_container::value_precedence::prefer_dest); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 939 | } |
| 940 | } else { |
| 941 | // Look for something to fill the gap further along. |
| 942 | for (const auto &prev_dep : prev_) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 943 | const ApplyTrackbackStackAction barrier_action(prev_dep.barriers, previous_barrier); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 944 | prev_dep.context->ResolveAccessRange(type, range, barrier_action, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 945 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 946 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 947 | } |
| 948 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 949 | // Non-lazy import of all accesses, WaitEvents needs this. |
| 950 | void AccessContext::ResolvePreviousAccesses() { |
| 951 | ResourceAccessState default_state; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 952 | if (!prev_.size()) return; // If no previous contexts, nothing to do |
| 953 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 954 | for (const auto address_type : kAddressTypes) { |
| 955 | ResolvePreviousAccess(address_type, kFullRange, &GetAccessStateMap(address_type), &default_state); |
| 956 | } |
| 957 | } |
| 958 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 959 | AccessAddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
| 960 | return (image.fragment_encoder->IsLinearImage()) ? AccessAddressType::kLinear : AccessAddressType::kIdealized; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 961 | } |
| 962 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 963 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
| 964 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 965 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE; |
| 966 | return stage_access; |
| 967 | } |
| 968 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
| 969 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 970 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE; |
| 971 | return stage_access; |
| 972 | } |
| 973 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 974 | // Caller must manage returned pointer |
| 975 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 976 | uint32_t subpass, const AttachmentViewGenVector &attachment_views) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 977 | auto *proxy = new AccessContext(context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 978 | proxy->UpdateAttachmentResolveAccess(rp_state, attachment_views, subpass, kCurrentCommandTag); |
| 979 | proxy->UpdateAttachmentStoreAccess(rp_state, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 980 | return proxy; |
| 981 | } |
| 982 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 983 | template <typename BarrierAction> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 984 | void AccessContext::ResolveAccessRange(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 985 | BarrierAction &barrier_action, ResourceAccessRangeMap *descent_map, |
| 986 | const ResourceAccessState *infill_state) const { |
| 987 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 988 | if (!attachment_gen) return; |
| 989 | |
| 990 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 991 | const AccessAddressType address_type = view_gen.GetAddressType(); |
| 992 | for (; range_gen->non_empty(); ++range_gen) { |
| 993 | ResolveAccessRange(address_type, *range_gen, barrier_action, descent_map, infill_state); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 994 | } |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 995 | } |
| 996 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 997 | // 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] | 998 | 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] | 999 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1000 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1001 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1002 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 1003 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 1004 | // those affects have not been recorded yet. |
| 1005 | // |
| 1006 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 1007 | // to apply and only copy then, if this proves a hot spot. |
| 1008 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 1009 | TrackBack proxy_track_back; |
| 1010 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1011 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 1012 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1013 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 1014 | |
| 1015 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1016 | assert(track_back); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1017 | if (prev_needs_proxy) { |
| 1018 | if (!proxy_for_prev) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1019 | proxy_for_prev.reset( |
| 1020 | CreateStoreResolveProxyContext(*track_back->context, rp_state, transition.prev_pass, attachment_views)); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1021 | proxy_track_back = *track_back; |
| 1022 | proxy_track_back.context = proxy_for_prev.get(); |
| 1023 | } |
| 1024 | track_back = &proxy_track_back; |
| 1025 | } |
| 1026 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1027 | if (hazard.hazard) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1028 | skip |= ex_context.GetSyncState().LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1029 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1030 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 1031 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1032 | string_VkImageLayout(transition.old_layout), |
| 1033 | string_VkImageLayout(transition.new_layout), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1034 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1035 | } |
| 1036 | } |
| 1037 | return skip; |
| 1038 | } |
| 1039 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1040 | 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] | 1041 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1042 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1043 | bool skip = false; |
| 1044 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1045 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1046 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1047 | if (subpass == rp_state.attachment_first_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1048 | const auto &view_gen = attachment_views[i]; |
| 1049 | if (!view_gen.IsValid()) continue; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1050 | const auto &ci = attachment_ci[i]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1051 | |
| 1052 | // Need check in the following way |
| 1053 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 1054 | // vs. transition |
| 1055 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 1056 | // for each aspect loaded. |
| 1057 | |
| 1058 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1059 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1060 | const bool is_color = !(has_depth || has_stencil); |
| 1061 | |
| 1062 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1063 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1064 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1065 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1066 | const char *aspect = nullptr; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1067 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1068 | bool checked_stencil = false; |
| 1069 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1070 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, load_index, SyncOrdering::kColorAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1071 | aspect = "color"; |
| 1072 | } else { |
| 1073 | if (has_depth) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1074 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_index, |
| 1075 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1076 | aspect = "depth"; |
| 1077 | } |
| 1078 | if (!hazard.hazard && has_stencil) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1079 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, stencil_load_index, |
| 1080 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1081 | aspect = "stencil"; |
| 1082 | checked_stencil = true; |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | if (hazard.hazard) { |
| 1087 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1088 | const auto &sync_state = ex_context.GetSyncState(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1089 | if (hazard.tag == kCurrentCommandTag) { |
| 1090 | // Hazard vs. ILT |
| 1091 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 1092 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1093 | " aspect %s during load with loadOp %s.", |
| 1094 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string); |
| 1095 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1096 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 1097 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1098 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1099 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1100 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | return skip; |
| 1106 | } |
| 1107 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1108 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 1109 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 1110 | // store is part of the same Next/End operation. |
| 1111 | // The latter is handled in layout transistion validation directly |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1112 | 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] | 1113 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1114 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1115 | bool skip = false; |
| 1116 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1117 | |
| 1118 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1119 | if (subpass == rp_state.attachment_last_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1120 | const AttachmentViewGen &view_gen = attachment_views[i]; |
| 1121 | if (!view_gen.IsValid()) continue; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1122 | const auto &ci = attachment_ci[i]; |
| 1123 | |
| 1124 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1125 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 1126 | // sake, we treat DONT_CARE as writing. |
| 1127 | const bool has_depth = FormatHasDepth(ci.format); |
| 1128 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1129 | const bool is_color = !(has_depth || has_stencil); |
| 1130 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1131 | if (!has_stencil && !store_op_stores) continue; |
| 1132 | |
| 1133 | HazardResult hazard; |
| 1134 | const char *aspect = nullptr; |
| 1135 | bool checked_stencil = false; |
| 1136 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1137 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1138 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1139 | aspect = "color"; |
| 1140 | } else { |
| 1141 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1142 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1143 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1144 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1145 | aspect = "depth"; |
| 1146 | } |
| 1147 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1148 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1149 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1150 | aspect = "stencil"; |
| 1151 | checked_stencil = true; |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | if (hazard.hazard) { |
| 1156 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 1157 | 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] | 1158 | skip |= ex_context.GetSyncState().LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1159 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1160 | " %s aspect during store with %s %s. Access info %s", |
| 1161 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1162 | op_type_string, store_op_string, ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | return skip; |
| 1167 | } |
| 1168 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1169 | bool AccessContext::ValidateResolveOperations(const CommandExecutionContext &ex_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1170 | const VkRect2D &render_area, const AttachmentViewGenVector &attachment_views, |
| 1171 | const char *func_name, uint32_t subpass) const { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1172 | ValidateResolveAction validate_action(rp_state.renderPass, subpass, *this, ex_context, func_name); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1173 | ResolveOperation(validate_action, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1174 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1175 | } |
| 1176 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1177 | class HazardDetector { |
| 1178 | SyncStageAccessIndex usage_index_; |
| 1179 | |
| 1180 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1181 | 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] | 1182 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1183 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1184 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1185 | explicit HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1186 | }; |
| 1187 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1188 | class HazardDetectorWithOrdering { |
| 1189 | const SyncStageAccessIndex usage_index_; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1190 | const SyncOrdering ordering_rule_; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1191 | |
| 1192 | public: |
| 1193 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1194 | return pos->second.DetectHazard(usage_index_, ordering_rule_); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1195 | } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1196 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1197 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1198 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1199 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, SyncOrdering ordering) : usage_index_(usage), ordering_rule_(ordering) {} |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1200 | }; |
| 1201 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1202 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1203 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1204 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1205 | const auto base_address = ResourceBaseAddress(buffer); |
| 1206 | HazardDetector detector(usage_index); |
| 1207 | return DetectHazard(AccessAddressType::kLinear, detector, (range + base_address), DetectOptions::kDetectAll); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 1208 | } |
| 1209 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1210 | template <typename Detector> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1211 | HazardResult AccessContext::DetectHazard(Detector &detector, const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1212 | DetectOptions options) const { |
| 1213 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1214 | if (!attachment_gen) return HazardResult(); |
| 1215 | |
| 1216 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1217 | const auto address_type = view_gen.GetAddressType(); |
| 1218 | for (; range_gen->non_empty(); ++range_gen) { |
| 1219 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1220 | if (hazard.hazard) return hazard; |
| 1221 | } |
| 1222 | |
| 1223 | return HazardResult(); |
| 1224 | } |
| 1225 | |
| 1226 | template <typename Detector> |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1227 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1228 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1229 | const VkExtent3D &extent, DetectOptions options) const { |
| 1230 | if (!SimpleBinding(image)) return HazardResult(); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1231 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1232 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1233 | base_address); |
| 1234 | const auto address_type = ImageAddressType(image); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1235 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 1236 | #ifdef SYNCVAL_DIAGNOSTICS |
| 1237 | sync_diagnostics.Detect(*range_gen); |
| 1238 | #endif |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1239 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1240 | if (hazard.hazard) return hazard; |
| 1241 | } |
| 1242 | return HazardResult(); |
| 1243 | } |
| 1244 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1245 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1246 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1247 | const VkExtent3D &extent) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1248 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1249 | subresource.layerCount}; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1250 | return DetectHazard(image, current_usage, subresource_range, offset, extent); |
| 1251 | } |
| 1252 | |
| 1253 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1254 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1255 | const VkExtent3D &extent) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1256 | HazardDetector detector(current_usage); |
| 1257 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
| 1258 | } |
| 1259 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1260 | HazardResult AccessContext::DetectHazard(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1261 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) const { |
| 1262 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
| 1263 | return DetectHazard(detector, view_gen, gen_type, DetectOptions::kDetectAll); |
| 1264 | } |
| 1265 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1266 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1267 | const VkImageSubresourceRange &subresource_range, SyncOrdering ordering_rule, |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1268 | const VkOffset3D &offset, const VkExtent3D &extent) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1269 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1270 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1271 | } |
| 1272 | |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1273 | // Some common code for looking at attachments, if there's anything wrong, we return no hazard, core validation |
| 1274 | // should have reported the issue regarding an invalid attachment entry |
| 1275 | HazardResult AccessContext::DetectHazard(const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1276 | SyncOrdering ordering_rule, const VkOffset3D &offset, const VkExtent3D &extent, |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1277 | VkImageAspectFlags aspect_mask) const { |
| 1278 | if (view != nullptr) { |
| 1279 | const IMAGE_STATE *image = view->image_state.get(); |
| 1280 | if (image != nullptr) { |
| 1281 | auto *detect_range = &view->normalized_subresource_range; |
| 1282 | VkImageSubresourceRange masked_range; |
| 1283 | if (aspect_mask) { // If present and non-zero, restrict the normalized range to aspects present in aspect_mask |
| 1284 | masked_range = view->normalized_subresource_range; |
| 1285 | masked_range.aspectMask = aspect_mask & masked_range.aspectMask; |
| 1286 | detect_range = &masked_range; |
| 1287 | } |
| 1288 | |
| 1289 | // NOTE: The range encoding code is not robust to invalid ranges, so we protect it from our change |
| 1290 | if (detect_range->aspectMask) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1291 | return DetectHazard(*image, current_usage, *detect_range, ordering_rule, offset, extent); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | } |
| 1295 | return HazardResult(); |
| 1296 | } |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1297 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1298 | class BarrierHazardDetector { |
| 1299 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1300 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1301 | SyncStageAccessFlags src_access_scope) |
| 1302 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1303 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1304 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1305 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1306 | } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1307 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1308 | // 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] | 1309 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | private: |
| 1313 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1314 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1315 | SyncStageAccessFlags src_access_scope_; |
| 1316 | }; |
| 1317 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1318 | class EventBarrierHazardDetector { |
| 1319 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1320 | EventBarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1321 | SyncStageAccessFlags src_access_scope, const SyncEventState::ScopeMap &event_scope, |
| 1322 | const ResourceUsageTag &scope_tag) |
| 1323 | : usage_index_(usage_index), |
| 1324 | src_exec_scope_(src_exec_scope), |
| 1325 | src_access_scope_(src_access_scope), |
| 1326 | event_scope_(event_scope), |
| 1327 | scope_pos_(event_scope.cbegin()), |
| 1328 | scope_end_(event_scope.cend()), |
| 1329 | scope_tag_(scope_tag) {} |
| 1330 | |
| 1331 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1332 | // TODO NOTE: This is almost the slowest way to do this... need to intelligently walk this... |
| 1333 | // Need to find a more efficient sync, since we know pos->first is strictly increasing call to call |
| 1334 | // NOTE: "cached_lower_bound_impl" with upgrades could do this. |
| 1335 | if (scope_pos_ == scope_end_) return HazardResult(); |
| 1336 | if (!scope_pos_->first.intersects(pos->first)) { |
| 1337 | event_scope_.lower_bound(pos->first); |
| 1338 | if ((scope_pos_ == scope_end_) || !scope_pos_->first.intersects(pos->first)) return HazardResult(); |
| 1339 | } |
| 1340 | |
| 1341 | // Some portion of this pos is in the event_scope, so check for a barrier hazard |
| 1342 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_, scope_tag_); |
| 1343 | } |
| 1344 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1345 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1346 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
| 1347 | } |
| 1348 | |
| 1349 | private: |
| 1350 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1351 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1352 | SyncStageAccessFlags src_access_scope_; |
| 1353 | const SyncEventState::ScopeMap &event_scope_; |
| 1354 | SyncEventState::ScopeMap::const_iterator scope_pos_; |
| 1355 | SyncEventState::ScopeMap::const_iterator scope_end_; |
| 1356 | const ResourceUsageTag &scope_tag_; |
| 1357 | }; |
| 1358 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1359 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1360 | const SyncStageAccessFlags &src_access_scope, |
| 1361 | const VkImageSubresourceRange &subresource_range, |
| 1362 | const SyncEventState &sync_event, DetectOptions options) const { |
| 1363 | // It's not particularly DRY to get the address type in this function as well as lower down, but we have to select the |
| 1364 | // first access scope map to use, and there's no easy way to plumb it in below. |
| 1365 | const auto address_type = ImageAddressType(image); |
| 1366 | const auto &event_scope = sync_event.FirstScope(address_type); |
| 1367 | |
| 1368 | EventBarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope, |
| 1369 | event_scope, sync_event.first_scope_tag); |
| 1370 | VkOffset3D zero_offset = {0, 0, 0}; |
| 1371 | return DetectHazard(detector, image, subresource_range, zero_offset, image.createInfo.extent, options); |
| 1372 | } |
| 1373 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1374 | HazardResult AccessContext::DetectImageBarrierHazard(const AttachmentViewGen &view_gen, const SyncBarrier &barrier, |
| 1375 | DetectOptions options) const { |
| 1376 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, barrier.src_exec_scope.exec_scope, |
| 1377 | barrier.src_access_scope); |
| 1378 | return DetectHazard(detector, view_gen, AttachmentViewGen::Gen::kViewSubresource, options); |
| 1379 | } |
| 1380 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1381 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1382 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1383 | const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1384 | const DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1385 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope); |
| 1386 | VkOffset3D zero_offset = {0, 0, 0}; |
| 1387 | return DetectHazard(detector, image, subresource_range, zero_offset, image.createInfo.extent, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1390 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1391 | const SyncStageAccessFlags &src_stage_accesses, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1392 | const VkImageMemoryBarrier &barrier) const { |
| 1393 | auto subresource_range = NormalizeSubresourceRange(image.createInfo, barrier.subresourceRange); |
| 1394 | const auto src_access_scope = SyncStageAccess::AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 1395 | return DetectImageBarrierHazard(image, src_exec_scope, src_access_scope, subresource_range, kDetectAll); |
| 1396 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1397 | HazardResult AccessContext::DetectImageBarrierHazard(const SyncImageMemoryBarrier &image_barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1398 | 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] | 1399 | image_barrier.barrier.src_access_scope, image_barrier.range.subresource_range, kDetectAll); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1400 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1401 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1402 | template <typename Flags, typename Map> |
| 1403 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1404 | SyncStageAccessFlags scope = 0; |
| 1405 | for (const auto &bit_scope : map) { |
| 1406 | if (flag_mask < bit_scope.first) break; |
| 1407 | |
| 1408 | if (flag_mask & bit_scope.first) { |
| 1409 | scope |= bit_scope.second; |
| 1410 | } |
| 1411 | } |
| 1412 | return scope; |
| 1413 | } |
| 1414 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1415 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags2KHR stages) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1416 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1417 | } |
| 1418 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1419 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags2KHR accesses) { |
| 1420 | return AccessScopeImpl(sync_utils::ExpandAccessFlags(accesses), syncStageAccessMaskByAccessBit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1421 | } |
| 1422 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1423 | // Getting from stage mask and access mask to stage/access masks is something we need to be good at... |
| 1424 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags2KHR stages, VkAccessFlags2KHR accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1425 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1426 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1427 | // 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] | 1428 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1429 | } |
| 1430 | |
| 1431 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1432 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1433 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1434 | // that do incrementalupdates |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1435 | assert(accesses); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1436 | auto pos = accesses->lower_bound(range); |
| 1437 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1438 | // The range is empty, fill it with a default value. |
| 1439 | pos = action.Infill(accesses, pos, range); |
| 1440 | } else if (range.begin < pos->first.begin) { |
| 1441 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1442 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1443 | } else if (pos->first.begin < range.begin) { |
| 1444 | // Trim the beginning if needed |
| 1445 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1446 | ++pos; |
| 1447 | } |
| 1448 | |
| 1449 | const auto the_end = accesses->end(); |
| 1450 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1451 | if (pos->first.end > range.end) { |
| 1452 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1453 | } |
| 1454 | |
| 1455 | pos = action(accesses, pos); |
| 1456 | if (pos == the_end) break; |
| 1457 | |
| 1458 | auto next = pos; |
| 1459 | ++next; |
| 1460 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1461 | // Need to infill if next is disjoint |
| 1462 | 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] | 1463 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1464 | next = action.Infill(accesses, next, new_range); |
| 1465 | } |
| 1466 | pos = next; |
| 1467 | } |
| 1468 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1469 | |
| 1470 | // Give a comparable interface for range generators and ranges |
| 1471 | template <typename Action> |
| 1472 | inline void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, ResourceAccessRange *range) { |
| 1473 | assert(range); |
| 1474 | UpdateMemoryAccessState(accesses, *range, action); |
| 1475 | } |
| 1476 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1477 | template <typename Action, typename RangeGen> |
| 1478 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, RangeGen *range_gen_arg) { |
| 1479 | assert(range_gen_arg); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1480 | 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] | 1481 | for (; range_gen->non_empty(); ++range_gen) { |
| 1482 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1483 | } |
| 1484 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1485 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1486 | template <typename Action, typename RangeGen> |
| 1487 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, const RangeGen &range_gen_prebuilt) { |
| 1488 | RangeGen range_gen(range_gen_prebuilt); // RangeGenerators can be expensive to create from scratch... initialize from built |
| 1489 | for (; range_gen->non_empty(); ++range_gen) { |
| 1490 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1491 | } |
| 1492 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1493 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1494 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1495 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1496 | // this is only called on gaps, and never returns a gap. |
| 1497 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1498 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1499 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1500 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1501 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1502 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1503 | auto &access_state = pos->second; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1504 | access_state.Update(usage, ordering_rule, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1505 | return pos; |
| 1506 | } |
| 1507 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1508 | UpdateMemoryAccessStateFunctor(AccessAddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1509 | SyncOrdering ordering_rule_, const ResourceUsageTag &tag_) |
| 1510 | : type(type_), context(context_), usage(usage_), ordering_rule(ordering_rule_), tag(tag_) {} |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1511 | const AccessAddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1512 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1513 | const SyncStageAccessIndex usage; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1514 | const SyncOrdering ordering_rule; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1515 | const ResourceUsageTag &tag; |
| 1516 | }; |
| 1517 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1518 | // The barrier operation for pipeline and subpass dependencies` |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1519 | struct PipelineBarrierOp { |
| 1520 | SyncBarrier barrier; |
| 1521 | bool layout_transition; |
| 1522 | PipelineBarrierOp(const SyncBarrier &barrier_, bool layout_transition_) |
| 1523 | : barrier(barrier_), layout_transition(layout_transition_) {} |
| 1524 | PipelineBarrierOp() = default; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1525 | PipelineBarrierOp(const PipelineBarrierOp &) = default; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1526 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(barrier, layout_transition); } |
| 1527 | }; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1528 | // The barrier operation for wait events |
| 1529 | struct WaitEventBarrierOp { |
| 1530 | const ResourceUsageTag *scope_tag; |
| 1531 | SyncBarrier barrier; |
| 1532 | bool layout_transition; |
| 1533 | WaitEventBarrierOp(const ResourceUsageTag &scope_tag_, const SyncBarrier &barrier_, bool layout_transition_) |
| 1534 | : scope_tag(&scope_tag_), barrier(barrier_), layout_transition(layout_transition_) {} |
| 1535 | WaitEventBarrierOp() = default; |
| 1536 | void operator()(ResourceAccessState *access_state) const { |
| 1537 | assert(scope_tag); // Not valid to have a non-scope op executed, default construct included for std::vector support |
| 1538 | access_state->ApplyBarrier(*scope_tag, barrier, layout_transition); |
| 1539 | } |
| 1540 | }; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1541 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1542 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1543 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1544 | // of a collection is known/present. |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1545 | template <typename BarrierOp> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1546 | class ApplyBarrierOpsFunctor { |
| 1547 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1548 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1549 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1550 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1551 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1552 | auto &access_state = pos->second; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1553 | for (const auto &op : barrier_ops_) { |
| 1554 | op(&access_state); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1555 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1556 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1557 | if (resolve_) { |
| 1558 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1559 | // another walk |
| 1560 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1561 | } |
| 1562 | return pos; |
| 1563 | } |
| 1564 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1565 | // 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] | 1566 | ApplyBarrierOpsFunctor(bool resolve, size_t size_hint, const ResourceUsageTag &tag) |
| 1567 | : resolve_(resolve), barrier_ops_(), tag_(tag) { |
| 1568 | barrier_ops_.reserve(size_hint); |
| 1569 | } |
| 1570 | void EmplaceBack(const BarrierOp &op) { barrier_ops_.emplace_back(op); } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1571 | |
| 1572 | private: |
| 1573 | bool resolve_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1574 | std::vector<BarrierOp> barrier_ops_; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1575 | const ResourceUsageTag &tag_; |
| 1576 | }; |
| 1577 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1578 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1579 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1580 | template <typename BarrierOp> |
| 1581 | class ApplyBarrierFunctor { |
| 1582 | public: |
| 1583 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1584 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
| 1585 | |
| 1586 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
| 1587 | auto &access_state = pos->second; |
| 1588 | barrier_op_(&access_state); |
| 1589 | return pos; |
| 1590 | } |
| 1591 | |
| 1592 | ApplyBarrierFunctor(const BarrierOp &barrier_op) : barrier_op_(barrier_op) {} |
| 1593 | |
| 1594 | private: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1595 | BarrierOp barrier_op_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1596 | }; |
| 1597 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1598 | // This functor resolves the pendinging state. |
| 1599 | class ResolvePendingBarrierFunctor { |
| 1600 | public: |
| 1601 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1602 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
| 1603 | |
| 1604 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
| 1605 | auto &access_state = pos->second; |
| 1606 | access_state.ApplyPendingBarriers(tag_); |
| 1607 | return pos; |
| 1608 | } |
| 1609 | |
| 1610 | ResolvePendingBarrierFunctor(const ResourceUsageTag &tag) : tag_(tag) {} |
| 1611 | |
| 1612 | private: |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1613 | const ResourceUsageTag &tag_; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1614 | }; |
| 1615 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1616 | void AccessContext::UpdateAccessState(AccessAddressType type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
| 1617 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
| 1618 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1619 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1620 | } |
| 1621 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1622 | 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] | 1623 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1624 | if (!SimpleBinding(buffer)) return; |
| 1625 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1626 | UpdateAccessState(AccessAddressType::kLinear, current_usage, ordering_rule, range + base_address, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1627 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1628 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1629 | 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] | 1630 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1631 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1632 | if (!SimpleBinding(image)) return; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1633 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1634 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1635 | base_address); |
| 1636 | const auto address_type = ImageAddressType(image); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1637 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1638 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1639 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), *range_gen, action); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1640 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1641 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1642 | |
| 1643 | void AccessContext::UpdateAccessState(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1644 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, const ResourceUsageTag &tag) { |
| 1645 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1646 | if (!gen) return; |
| 1647 | subresource_adapter::ImageRangeGenerator range_gen(*gen); |
| 1648 | const auto address_type = view_gen.GetAddressType(); |
| 1649 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1650 | ApplyUpdateAction(address_type, action, &range_gen); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1651 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1652 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1653 | 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] | 1654 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1655 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1656 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1657 | subresource.layerCount}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1658 | UpdateAccessState(image, current_usage, ordering_rule, subresource_range, offset, extent, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1659 | } |
| 1660 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1661 | template <typename Action, typename RangeGen> |
| 1662 | void AccessContext::ApplyUpdateAction(AccessAddressType address_type, const Action &action, RangeGen *range_gen_arg) { |
| 1663 | assert(range_gen_arg); // Old Google C++ styleguide require non-const object pass by * not &, but this isn't an optional arg. |
| 1664 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, range_gen_arg); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1668 | void AccessContext::ApplyUpdateAction(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, const Action &action) { |
| 1669 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1670 | if (!gen) return; |
| 1671 | UpdateMemoryAccessState(&GetAccessStateMap(view_gen.GetAddressType()), action, *gen); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1672 | } |
| 1673 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1674 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, |
| 1675 | const AttachmentViewGenVector &attachment_views, uint32_t subpass, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1676 | const ResourceUsageTag &tag) { |
| 1677 | UpdateStateResolveAction update(*this, tag); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1678 | ResolveOperation(update, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1679 | } |
| 1680 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1681 | void AccessContext::UpdateAttachmentStoreAccess(const RENDER_PASS_STATE &rp_state, const AttachmentViewGenVector &attachment_views, |
| 1682 | uint32_t subpass, const ResourceUsageTag &tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1683 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1684 | |
| 1685 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1686 | if (rp_state.attachment_last_subpass[i] == subpass) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1687 | const auto &view_gen = attachment_views[i]; |
| 1688 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1689 | |
| 1690 | const auto &ci = attachment_ci[i]; |
| 1691 | const bool has_depth = FormatHasDepth(ci.format); |
| 1692 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1693 | const bool is_color = !(has_depth || has_stencil); |
| 1694 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1695 | |
| 1696 | if (is_color && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1697 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1698 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1699 | } else { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1700 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1701 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1702 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1703 | } |
| 1704 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1705 | if (has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1706 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1707 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | } |
| 1713 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1714 | template <typename Action> |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1715 | void AccessContext::ApplyToContext(const Action &barrier_action) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1716 | // 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] | 1717 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1718 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), kFullRange, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1723 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1724 | auto &context = contexts[subpass_index]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1725 | ApplyTrackbackStackAction barrier_action(context.GetDstExternalTrackBack().barriers); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1726 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1727 | context.ResolveAccessRange(address_type, kFullRange, barrier_action, &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1728 | } |
| 1729 | } |
| 1730 | } |
| 1731 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1732 | // Suitable only for *subpass* access contexts |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1733 | HazardResult AccessContext::DetectSubpassTransitionHazard(const TrackBack &track_back, const AttachmentViewGen &attach_view) const { |
| 1734 | if (!attach_view.IsValid()) return HazardResult(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1735 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1736 | // 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] | 1737 | assert(track_back.context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1738 | |
| 1739 | // 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] | 1740 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1741 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1742 | HazardResult hazard = track_back.context->DetectImageBarrierHazard(attach_view, merged_barrier, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1743 | if (!hazard.hazard) { |
| 1744 | // The Async hazard check is against the current context's async set. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1745 | hazard = DetectImageBarrierHazard(attach_view, merged_barrier, kDetectAsync); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1746 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1747 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1748 | return hazard; |
| 1749 | } |
| 1750 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1751 | void AccessContext::RecordLayoutTransitions(const RENDER_PASS_STATE &rp_state, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1752 | const AttachmentViewGenVector &attachment_views, const ResourceUsageTag &tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1753 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1754 | const ResourceAccessState empty_infill; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1755 | for (const auto &transition : transitions) { |
| 1756 | const auto prev_pass = transition.prev_pass; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1757 | const auto &view_gen = attachment_views[transition.attachment]; |
| 1758 | if (!view_gen.IsValid()) continue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1759 | |
| 1760 | const auto *trackback = GetTrackBackFromSubpass(prev_pass); |
| 1761 | assert(trackback); |
| 1762 | |
| 1763 | // Import the attachments into the current context |
| 1764 | const auto *prev_context = trackback->context; |
| 1765 | assert(prev_context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1766 | const auto address_type = view_gen.GetAddressType(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1767 | auto &target_map = GetAccessStateMap(address_type); |
| 1768 | ApplySubpassTransitionBarriersAction barrier_action(trackback->barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 1769 | prev_context->ResolveAccessRange(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action, &target_map, |
| 1770 | &empty_infill); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1771 | } |
| 1772 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1773 | // If there were no transitions skip this global map walk |
| 1774 | if (transitions.size()) { |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1775 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1776 | ApplyToContext(apply_pending_action); |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1777 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1778 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1779 | |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1780 | void CommandBufferAccessContext::ApplyGlobalBarriersToEvents(const SyncExecScope &src, const SyncExecScope &dst) { |
| 1781 | 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] | 1782 | |
| 1783 | auto *events_context = GetCurrentEventsContext(); |
| 1784 | assert(events_context); |
| 1785 | for (auto &event_pair : *events_context) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1786 | assert(event_pair.second); // Shouldn't be storing empty |
| 1787 | auto &sync_event = *event_pair.second; |
| 1788 | // 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] | 1789 | if ((sync_event.barriers & src.exec_scope) || all_commands_bit) { |
| 1790 | sync_event.barriers |= dst.exec_scope; |
| 1791 | sync_event.barriers |= dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | } |
| 1795 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1796 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1797 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1798 | const char *func_name) const { |
| 1799 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1800 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1801 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1802 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pipe, &per_sets); |
| 1803 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1804 | return skip; |
| 1805 | } |
| 1806 | |
| 1807 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1808 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1809 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1810 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1811 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1812 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1813 | for (const auto &stage_state : pipe->stage_state) { |
| 1814 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->graphicsPipelineCI.pRasterizationState && |
| 1815 | pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1816 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1817 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1818 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1819 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1820 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1821 | set_binding.first.second); |
| 1822 | const auto descriptor_type = binding_it.GetType(); |
| 1823 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1824 | auto array_idx = 0; |
| 1825 | |
| 1826 | if (binding_it.IsVariableDescriptorCount()) { |
| 1827 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1828 | } |
| 1829 | SyncStageAccessIndex sync_index = |
| 1830 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1831 | |
| 1832 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1833 | uint32_t index = i - index_range.start; |
| 1834 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1835 | switch (descriptor->GetClass()) { |
| 1836 | case DescriptorClass::ImageSampler: |
| 1837 | case DescriptorClass::Image: { |
| 1838 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1839 | VkImageLayout image_layout; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1840 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1841 | const auto image_sampler_descriptor = static_cast<const ImageSamplerDescriptor *>(descriptor); |
| 1842 | img_view_state = image_sampler_descriptor->GetImageViewState(); |
| 1843 | image_layout = image_sampler_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1844 | } else { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1845 | const auto image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 1846 | img_view_state = image_descriptor->GetImageViewState(); |
| 1847 | image_layout = image_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1848 | } |
| 1849 | if (!img_view_state) continue; |
| 1850 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
| 1851 | VkExtent3D extent = {}; |
| 1852 | VkOffset3D offset = {}; |
| 1853 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1854 | extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1855 | offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1856 | } else { |
| 1857 | extent = img_state->createInfo.extent; |
| 1858 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1859 | HazardResult hazard; |
| 1860 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
| 1861 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 1862 | // Input attachments are subject to raster ordering rules |
| 1863 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1864 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1865 | } else { |
| 1866 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, offset, extent); |
| 1867 | } |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1868 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1869 | skip |= sync_state_->LogError( |
| 1870 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1871 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 1872 | ", index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1873 | func_name, string_SyncHazard(hazard.hazard), |
| 1874 | sync_state_->report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1875 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1876 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1877 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1878 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1879 | set_binding.first.second, index, FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1880 | } |
| 1881 | break; |
| 1882 | } |
| 1883 | case DescriptorClass::TexelBuffer: { |
| 1884 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1885 | if (!buf_view_state) continue; |
| 1886 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1887 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1888 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1889 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1890 | skip |= sync_state_->LogError( |
| 1891 | buf_view_state->buffer_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1892 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1893 | func_name, string_SyncHazard(hazard.hazard), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1894 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view).c_str(), |
| 1895 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1896 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1897 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1898 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1899 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1900 | } |
| 1901 | break; |
| 1902 | } |
| 1903 | case DescriptorClass::GeneralBuffer: { |
| 1904 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1905 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1906 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1907 | const ResourceAccessRange range = |
| 1908 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1909 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 1910 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1911 | skip |= sync_state_->LogError( |
| 1912 | buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1913 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1914 | func_name, string_SyncHazard(hazard.hazard), |
| 1915 | sync_state_->report_data->FormatHandle(buf_state->buffer).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1916 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1917 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1918 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1919 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1920 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1921 | } |
| 1922 | break; |
| 1923 | } |
| 1924 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1925 | default: |
| 1926 | break; |
| 1927 | } |
| 1928 | } |
| 1929 | } |
| 1930 | } |
| 1931 | return skip; |
| 1932 | } |
| 1933 | |
| 1934 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1935 | const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1936 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1937 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1938 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pipe, &per_sets); |
| 1939 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1940 | return; |
| 1941 | } |
| 1942 | |
| 1943 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1944 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1945 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1946 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1947 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1948 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1949 | for (const auto &stage_state : pipe->stage_state) { |
| 1950 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->graphicsPipelineCI.pRasterizationState && |
| 1951 | pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1952 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1953 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1954 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1955 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1956 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1957 | set_binding.first.second); |
| 1958 | const auto descriptor_type = binding_it.GetType(); |
| 1959 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1960 | auto array_idx = 0; |
| 1961 | |
| 1962 | if (binding_it.IsVariableDescriptorCount()) { |
| 1963 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1964 | } |
| 1965 | SyncStageAccessIndex sync_index = |
| 1966 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1967 | |
| 1968 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1969 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1970 | switch (descriptor->GetClass()) { |
| 1971 | case DescriptorClass::ImageSampler: |
| 1972 | case DescriptorClass::Image: { |
| 1973 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
| 1974 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
| 1975 | img_view_state = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetImageViewState(); |
| 1976 | } else { |
| 1977 | img_view_state = static_cast<const ImageDescriptor *>(descriptor)->GetImageViewState(); |
| 1978 | } |
| 1979 | if (!img_view_state) continue; |
| 1980 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
| 1981 | VkExtent3D extent = {}; |
| 1982 | VkOffset3D offset = {}; |
| 1983 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1984 | extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1985 | offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1986 | } else { |
| 1987 | extent = img_state->createInfo.extent; |
| 1988 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1989 | SyncOrdering ordering_rule = (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) |
| 1990 | ? SyncOrdering::kRaster |
| 1991 | : SyncOrdering::kNonAttachment; |
| 1992 | current_context_->UpdateAccessState(*img_state, sync_index, ordering_rule, |
| 1993 | img_view_state->normalized_subresource_range, offset, extent, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1994 | break; |
| 1995 | } |
| 1996 | case DescriptorClass::TexelBuffer: { |
| 1997 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1998 | if (!buf_view_state) continue; |
| 1999 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2000 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2001 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2002 | break; |
| 2003 | } |
| 2004 | case DescriptorClass::GeneralBuffer: { |
| 2005 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 2006 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 2007 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2008 | const ResourceAccessRange range = |
| 2009 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2010 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2011 | break; |
| 2012 | } |
| 2013 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2014 | default: |
| 2015 | break; |
| 2016 | } |
| 2017 | } |
| 2018 | } |
| 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const char *func_name) const { |
| 2023 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2024 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2025 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2026 | return skip; |
| 2027 | } |
| 2028 | |
| 2029 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2030 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2031 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2032 | |
| 2033 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2034 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2035 | if (binding_description.binding < binding_buffers_size) { |
| 2036 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2037 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->destroyed) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2038 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2039 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2040 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2041 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2042 | 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] | 2043 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2044 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2045 | 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] | 2046 | 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] | 2047 | 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] | 2048 | } |
| 2049 | } |
| 2050 | } |
| 2051 | return skip; |
| 2052 | } |
| 2053 | |
| 2054 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2055 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2056 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2057 | return; |
| 2058 | } |
| 2059 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2060 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2061 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2062 | |
| 2063 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2064 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2065 | if (binding_description.binding < binding_buffers_size) { |
| 2066 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2067 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->destroyed) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2068 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2069 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2070 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2071 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2072 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ, |
| 2073 | SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2074 | } |
| 2075 | } |
| 2076 | } |
| 2077 | |
| 2078 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const char *func_name) const { |
| 2079 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2080 | 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] | 2081 | return skip; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2082 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2083 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2084 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2085 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2086 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2087 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2088 | 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] | 2089 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2090 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2091 | 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] | 2092 | 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] | 2093 | 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] | 2094 | } |
| 2095 | |
| 2096 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2097 | // We will detect more accurate range in the future. |
| 2098 | skip |= ValidateDrawVertex(UINT32_MAX, 0, func_name); |
| 2099 | return skip; |
| 2100 | } |
| 2101 | |
| 2102 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag &tag) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2103 | 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] | 2104 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2105 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2106 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2107 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2108 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2109 | 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] | 2110 | |
| 2111 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2112 | // We will detect more accurate range in the future. |
| 2113 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 2114 | } |
| 2115 | |
| 2116 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(const char *func_name) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2117 | bool skip = false; |
| 2118 | if (!current_renderpass_context_) return skip; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2119 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(GetExecutionContext(), *cb_state_.get(), func_name); |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2120 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2124 | if (current_renderpass_context_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2125 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), tag); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2126 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2127 | } |
| 2128 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2129 | void CommandBufferAccessContext::RecordBeginRenderPass(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2130 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2131 | const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2132 | // Create an access context the current renderpass. |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2133 | 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] | 2134 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2135 | current_renderpass_context_->RecordBeginRenderPass(tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2136 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2137 | } |
| 2138 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2139 | void CommandBufferAccessContext::RecordNextSubpass(CMD_TYPE command) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2140 | assert(current_renderpass_context_); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2141 | auto prev_tag = NextCommandTag(command); |
| 2142 | auto next_tag = NextSubcommandTag(command); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2143 | current_renderpass_context_->RecordNextSubpass(prev_tag, next_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2144 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
| 2145 | } |
| 2146 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2147 | void CommandBufferAccessContext::RecordEndRenderPass(CMD_TYPE command) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2148 | assert(current_renderpass_context_); |
| 2149 | if (!current_renderpass_context_) return; |
| 2150 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2151 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, NextCommandTag(command)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2152 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2153 | current_renderpass_context_ = nullptr; |
| 2154 | } |
| 2155 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2156 | void CommandBufferAccessContext::RecordDestroyEvent(VkEvent event) { |
| 2157 | // Erase is okay with the key not being |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2158 | const auto *event_state = sync_state_->Get<EVENT_STATE>(event); |
| 2159 | if (event_state) { |
| 2160 | GetCurrentEventsContext()->Destroy(event_state); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2161 | } |
| 2162 | } |
| 2163 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2164 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const CommandExecutionContext &ex_context, const CMD_BUFFER_STATE &cmd, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2165 | const char *func_name) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2166 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2167 | const auto &sync_state = ex_context.GetSyncState(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2168 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2169 | if (!pipe || |
| 2170 | (pipe->graphicsPipelineCI.pRasterizationState && pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2171 | return skip; |
| 2172 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2173 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2174 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2175 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2176 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2177 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2178 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2179 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2180 | if (location >= subpass.colorAttachmentCount || |
| 2181 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2182 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2183 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2184 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2185 | if (!view_gen.IsValid()) continue; |
| 2186 | HazardResult hazard = |
| 2187 | current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2188 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2189 | if (hazard.hazard) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2190 | const VkImageView view_handle = view_gen.GetViewState()->image_view; |
| 2191 | skip |= sync_state.LogError(view_handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2192 | "%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] | 2193 | func_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2194 | sync_state.report_data->FormatHandle(view_handle).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2195 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2196 | location, ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2197 | } |
| 2198 | } |
| 2199 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2200 | |
| 2201 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2202 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2203 | const uint32_t depth_stencil_attachment = |
| 2204 | GetSubpassDepthStencilAttachmentIndex(pipe->graphicsPipelineCI.pDepthStencilState, subpass.pDepthStencilAttachment); |
| 2205 | |
| 2206 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2207 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2208 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2209 | bool depth_write = false, stencil_write = false; |
| 2210 | |
| 2211 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2212 | if (!FormatIsStencilOnly(view_state.create_info.format) && pipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2213 | pipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2214 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2215 | depth_write = true; |
| 2216 | } |
| 2217 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2218 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2219 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2220 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2221 | if (!FormatIsDepthOnly(view_state.create_info.format) && pipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2222 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2223 | stencil_write = true; |
| 2224 | } |
| 2225 | |
| 2226 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2227 | if (depth_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2228 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2229 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2230 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2231 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2232 | skip |= sync_state.LogError( |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2233 | view_state.image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2234 | "%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] | 2235 | func_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2236 | sync_state.report_data->FormatHandle(view_state.image_view).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2237 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2238 | ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2239 | } |
| 2240 | } |
| 2241 | if (stencil_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2242 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2243 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2244 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2245 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2246 | skip |= sync_state.LogError( |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2247 | view_state.image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2248 | "%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] | 2249 | func_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2250 | sync_state.report_data->FormatHandle(view_state.image_view).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2251 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2252 | ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2253 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2254 | } |
| 2255 | } |
| 2256 | return skip; |
| 2257 | } |
| 2258 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2259 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd, const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2260 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2261 | if (!pipe || |
| 2262 | (pipe->graphicsPipelineCI.pRasterizationState && pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2263 | return; |
| 2264 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2265 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2266 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2267 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2268 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2269 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2270 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2271 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2272 | if (location >= subpass.colorAttachmentCount || |
| 2273 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2274 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2275 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2276 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2277 | current_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2278 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment, |
| 2279 | tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2280 | } |
| 2281 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2282 | |
| 2283 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2284 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2285 | const uint32_t depth_stencil_attachment = |
| 2286 | GetSubpassDepthStencilAttachmentIndex(pipe->graphicsPipelineCI.pDepthStencilState, subpass.pDepthStencilAttachment); |
| 2287 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2288 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2289 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2290 | bool depth_write = false, stencil_write = false; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2291 | const bool has_depth = 0 != (view_state.normalized_subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 2292 | const bool has_stencil = 0 != (view_state.normalized_subresource_range.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2293 | |
| 2294 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2295 | if (has_depth && !FormatIsStencilOnly(view_state.create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2296 | pipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 2297 | pipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2298 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2299 | depth_write = true; |
| 2300 | } |
| 2301 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2302 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2303 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2304 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2305 | if (has_stencil && !FormatIsDepthOnly(view_state.create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2306 | pipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2307 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2308 | stencil_write = true; |
| 2309 | } |
| 2310 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2311 | if (depth_write || stencil_write) { |
| 2312 | const auto ds_gentype = view_gen.GetDepthStencilRenderAreaGenType(depth_write, stencil_write); |
| 2313 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2314 | current_context.UpdateAccessState(view_gen, ds_gentype, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2315 | SyncOrdering::kDepthStencilAttachment, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2316 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2317 | } |
| 2318 | } |
| 2319 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2320 | bool RenderPassAccessContext::ValidateNextSubpass(const CommandExecutionContext &ex_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2321 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2322 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2323 | 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] | 2324 | current_subpass_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2325 | 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] | 2326 | func_name); |
| 2327 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2328 | const auto next_subpass = current_subpass_ + 1; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2329 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2330 | skip |= |
| 2331 | 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] | 2332 | if (!skip) { |
| 2333 | // To avoid complex (and buggy) duplication of the affect of layout transitions on load operations, we'll record them |
| 2334 | // on a copy of the (empty) next context. |
| 2335 | // Note: The resource access map should be empty so hopefully this copy isn't too horrible from a perf POV. |
| 2336 | AccessContext temp_context(next_context); |
| 2337 | temp_context.RecordLayoutTransitions(*rp_state_, next_subpass, attachment_views_, kCurrentCommandTag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2338 | skip |= |
| 2339 | 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] | 2340 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2341 | return skip; |
| 2342 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2343 | bool RenderPassAccessContext::ValidateEndRenderPass(const CommandExecutionContext &ex_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2344 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2345 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2346 | 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] | 2347 | current_subpass_); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2348 | skip |= CurrentContext().ValidateStoreOperation(ex_context, *rp_state_, render_area_, current_subpass_, |
| 2349 | |
| 2350 | attachment_views_, func_name); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2351 | skip |= ValidateFinalSubpassLayoutTransitions(ex_context, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2352 | return skip; |
| 2353 | } |
| 2354 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2355 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy() const { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2356 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, attachment_views_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2357 | } |
| 2358 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2359 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const CommandExecutionContext &ex_context, |
| 2360 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2361 | bool skip = false; |
| 2362 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2363 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2364 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2365 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2366 | // to apply and only copy then, if this proves a hot spot. |
| 2367 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2368 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2369 | // Validate the "finalLayout" transitions to external |
| 2370 | // Get them from where there we're hidding in the extra entry. |
| 2371 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2372 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2373 | const auto &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2374 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
| 2375 | 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] | 2376 | auto *context = trackback.context; |
| 2377 | |
| 2378 | if (transition.prev_pass == current_subpass_) { |
| 2379 | if (!proxy_for_current) { |
| 2380 | // 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] | 2381 | proxy_for_current.reset(CreateStoreResolveProxy()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2382 | } |
| 2383 | context = proxy_for_current.get(); |
| 2384 | } |
| 2385 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2386 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2387 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2388 | auto hazard = context->DetectImageBarrierHazard(view_gen, merged_barrier, AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2389 | if (hazard.hazard) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2390 | skip |= ex_context.GetSyncState().LogError( |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2391 | rp_state_->renderPass, string_SyncHazardVUID(hazard.hazard), |
| 2392 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
| 2393 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 2394 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2395 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2396 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | return skip; |
| 2400 | } |
| 2401 | |
| 2402 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag &tag) { |
| 2403 | // Add layout transitions... |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2404 | subpass_contexts_[current_subpass_].RecordLayoutTransitions(*rp_state_, current_subpass_, attachment_views_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2405 | } |
| 2406 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2407 | void RenderPassAccessContext::RecordLoadOperations(const ResourceUsageTag &tag) { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2408 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2409 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2410 | |
| 2411 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2412 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2413 | const AttachmentViewGen &view_gen = attachment_views_[i]; |
| 2414 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2415 | |
| 2416 | const auto &ci = attachment_ci[i]; |
| 2417 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2418 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2419 | const bool is_color = !(has_depth || has_stencil); |
| 2420 | |
| 2421 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2422 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, ColorLoadUsage(ci.loadOp), |
| 2423 | SyncOrdering::kColorAttachment, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2424 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2425 | if (has_depth) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2426 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2427 | DepthStencilLoadUsage(ci.loadOp), SyncOrdering::kDepthStencilAttachment, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2428 | } |
| 2429 | if (has_stencil) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2430 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2431 | DepthStencilLoadUsage(ci.stencilLoadOp), |
| 2432 | SyncOrdering::kDepthStencilAttachment, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | } |
| 2437 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2438 | AttachmentViewGenVector RenderPassAccessContext::CreateAttachmentViewGen( |
| 2439 | const VkRect2D &render_area, const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
| 2440 | AttachmentViewGenVector view_gens; |
| 2441 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2442 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2443 | view_gens.reserve(attachment_views.size()); |
| 2444 | for (const auto *view : attachment_views) { |
| 2445 | view_gens.emplace_back(view, offset, extent); |
| 2446 | } |
| 2447 | return view_gens; |
| 2448 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2449 | RenderPassAccessContext::RenderPassAccessContext(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2450 | VkQueueFlags queue_flags, |
| 2451 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2452 | const AccessContext *external_context) |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2453 | : rp_state_(&rp_state), render_area_(render_area), current_subpass_(0U), attachment_views_() { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2454 | // 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] | 2455 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2456 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2457 | 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] | 2458 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2459 | attachment_views_ = CreateAttachmentViewGen(render_area, attachment_views); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2460 | } |
| 2461 | void RenderPassAccessContext::RecordBeginRenderPass(const ResourceUsageTag &tag) { |
| 2462 | assert(0 == current_subpass_); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2463 | subpass_contexts_[current_subpass_].SetStartTag(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2464 | RecordLayoutTransitions(tag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2465 | RecordLoadOperations(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2466 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2467 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2468 | void RenderPassAccessContext::RecordNextSubpass(const ResourceUsageTag &prev_subpass_tag, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2469 | const ResourceUsageTag &next_subpass_tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2470 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2471 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, prev_subpass_tag); |
| 2472 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, prev_subpass_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2473 | |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 2474 | // Move to the next sub-command for the new subpass. The resolve and store are logically part of the previous |
| 2475 | // 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] | 2476 | current_subpass_++; |
| 2477 | assert(current_subpass_ < subpass_contexts_.size()); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2478 | subpass_contexts_[current_subpass_].SetStartTag(next_subpass_tag); |
| 2479 | RecordLayoutTransitions(next_subpass_tag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2480 | RecordLoadOperations(next_subpass_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2481 | } |
| 2482 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2483 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const ResourceUsageTag &tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2484 | // Add the resolve and store accesses |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2485 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, tag); |
| 2486 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2487 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2488 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2489 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2490 | |
| 2491 | // Add the "finalLayout" transitions to external |
| 2492 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2493 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2494 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2495 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2496 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2497 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2498 | const AttachmentViewGen &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2499 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | aa97d8b | 2020-07-14 10:58:13 -0600 | [diff] [blame] | 2500 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2501 | ApplyBarrierOpsFunctor<PipelineBarrierOp> barrier_action(true /* resolve */, last_trackback.barriers.size(), tag); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2502 | for (const auto &barrier : last_trackback.barriers) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2503 | barrier_action.EmplaceBack(PipelineBarrierOp(barrier, true)); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2504 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 2505 | external_context->ApplyUpdateAction(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2506 | } |
| 2507 | } |
| 2508 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2509 | SyncExecScope SyncExecScope::MakeSrc(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2510 | SyncExecScope result; |
| 2511 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2512 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2513 | result.exec_scope = sync_utils::WithEarlierPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2514 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2515 | return result; |
| 2516 | } |
| 2517 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2518 | SyncExecScope SyncExecScope::MakeDst(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2519 | SyncExecScope result; |
| 2520 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2521 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2522 | result.exec_scope = sync_utils::WithLaterPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2523 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2524 | return result; |
| 2525 | } |
| 2526 | |
| 2527 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2528 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2529 | src_access_scope = 0; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2530 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2531 | dst_access_scope = 0; |
| 2532 | } |
| 2533 | |
| 2534 | template <typename Barrier> |
| 2535 | SyncBarrier::SyncBarrier(const Barrier &barrier, const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2536 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2537 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2538 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2539 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
| 2540 | } |
| 2541 | |
| 2542 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &subpass) { |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2543 | const auto barrier = lvl_find_in_chain<VkMemoryBarrier2KHR>(subpass.pNext); |
| 2544 | if (barrier) { |
| 2545 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier->srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2546 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2547 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier->srcAccessMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2548 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2549 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier->dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2550 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2551 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier->dstAccessMask); |
| 2552 | |
| 2553 | } else { |
| 2554 | auto src = SyncExecScope::MakeSrc(queue_flags, subpass.srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2555 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2556 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, subpass.srcAccessMask); |
| 2557 | |
| 2558 | auto dst = SyncExecScope::MakeDst(queue_flags, subpass.dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2559 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2560 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, subpass.dstAccessMask); |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | template <typename Barrier> |
| 2565 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const Barrier &barrier) { |
| 2566 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 2567 | src_exec_scope = src.exec_scope; |
| 2568 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
| 2569 | |
| 2570 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2571 | dst_exec_scope = dst.exec_scope; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2572 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2573 | } |
| 2574 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2575 | // Apply a list of barriers, without resolving pending state, useful for subpass layout transitions |
| 2576 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
| 2577 | for (const auto &barrier : barriers) { |
| 2578 | ApplyBarrier(barrier, layout_transition); |
| 2579 | } |
| 2580 | } |
| 2581 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2582 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2583 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2584 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2585 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, const ResourceUsageTag &tag) { |
| 2586 | 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] | 2587 | assert(pending_write_barriers.none()); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2588 | assert(!pending_write_dep_chain); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2589 | for (const auto &barrier : barriers) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2590 | ApplyBarrier(barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2591 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2592 | ApplyPendingBarriers(tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2593 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2594 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2595 | HazardResult hazard; |
| 2596 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2597 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2598 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2599 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2600 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2601 | } |
| 2602 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2603 | // Write operation: |
| 2604 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2605 | // If reads exists -- test only against them because either: |
| 2606 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2607 | // * 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 |
| 2608 | // the current write happens after the reads, so just test the write against the reades |
| 2609 | // Otherwise test against last_write |
| 2610 | // |
| 2611 | // Look for casus belli for WAR |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2612 | if (last_reads.size()) { |
| 2613 | for (const auto &read_access : last_reads) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2614 | if (IsReadHazard(usage_stage, read_access)) { |
| 2615 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2616 | break; |
| 2617 | } |
| 2618 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2619 | } else if (last_write.any() && IsWriteHazard(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2620 | // Write-After-Write check -- if we have a previous write to test against |
| 2621 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2622 | } |
| 2623 | } |
| 2624 | return hazard; |
| 2625 | } |
| 2626 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2627 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrdering &ordering_rule) const { |
| 2628 | const auto &ordering = GetOrderingRules(ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2629 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 2630 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2631 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2632 | const auto usage_stage = PipelineStageBit(usage_index); |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2633 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
| 2634 | const bool last_write_is_ordered = (last_write & ordering.access_scope).any(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2635 | if (IsRead(usage_bit)) { |
| 2636 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 2637 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 2638 | if (is_raw_hazard) { |
| 2639 | // NOTE: we know last_write is non-zero |
| 2640 | // See if the ordering rules save us from the simple RAW check above |
| 2641 | // First check to see if the current usage is covered by the ordering rules |
| 2642 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 2643 | const bool usage_is_ordered = |
| 2644 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 2645 | if (usage_is_ordered) { |
| 2646 | // Now see of the most recent write (or a subsequent read) are ordered |
| 2647 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(ordering)); |
| 2648 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2649 | } |
| 2650 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2651 | if (is_raw_hazard) { |
| 2652 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 2653 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2654 | } else { |
| 2655 | // Only check for WAW if there are no reads since last_write |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2656 | bool usage_write_is_ordered = (usage_bit & ordering.access_scope).any(); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2657 | if (last_reads.size()) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2658 | // Look for any WAR hazards outside the ordered set of stages |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2659 | VkPipelineStageFlags2KHR ordered_stages = 0; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2660 | if (usage_write_is_ordered) { |
| 2661 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
| 2662 | ordered_stages = GetOrderedStages(ordering); |
| 2663 | } |
| 2664 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 2665 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2666 | for (const auto &read_access : last_reads) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2667 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 2668 | if (IsReadHazard(usage_stage, read_access)) { |
| 2669 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2670 | break; |
| 2671 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2672 | } |
| 2673 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2674 | } else if (!(last_write_is_ordered && usage_write_is_ordered)) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2675 | if (last_write.any() && IsWriteHazard(usage_bit)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2676 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2677 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2678 | } |
| 2679 | } |
| 2680 | return hazard; |
| 2681 | } |
| 2682 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2683 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2684 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index, const ResourceUsageTag &start_tag) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2685 | HazardResult hazard; |
| 2686 | auto usage = FlagBit(usage_index); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2687 | // Async checks need to not go back further than the start of the subpass, as we only want to find hazards between the async |
| 2688 | // subpasses. Anything older than that should have been checked at the start of each subpass, taking into account all of |
| 2689 | // the raster ordering rules. |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2690 | if (IsRead(usage)) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2691 | if (last_write.any() && (write_tag.index >= start_tag.index)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2692 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2693 | } |
| 2694 | } else { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2695 | if (last_write.any() && (write_tag.index >= start_tag.index)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2696 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2697 | } else if (last_reads.size() > 0) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2698 | // 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] | 2699 | for (const auto &read_access : last_reads) { |
| 2700 | if (read_access.tag.index >= start_tag.index) { |
| 2701 | 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] | 2702 | break; |
| 2703 | } |
| 2704 | } |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2705 | } |
| 2706 | } |
| 2707 | return hazard; |
| 2708 | } |
| 2709 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2710 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2711 | const SyncStageAccessFlags &src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2712 | // Only supporting image layout transitions for now |
| 2713 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2714 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2715 | // only test for WAW if there no intervening read operations. |
| 2716 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2717 | if (last_reads.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2718 | // Look at the reads if any |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2719 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2720 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2721 | 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] | 2722 | break; |
| 2723 | } |
| 2724 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2725 | } else if (last_write.any() && IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2726 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2727 | } |
| 2728 | |
| 2729 | return hazard; |
| 2730 | } |
| 2731 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2732 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2733 | const SyncStageAccessFlags &src_access_scope, |
| 2734 | const ResourceUsageTag &event_tag) const { |
| 2735 | // Only supporting image layout transitions for now |
| 2736 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2737 | HazardResult hazard; |
| 2738 | // only test for WAW if there no intervening read operations. |
| 2739 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 2740 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2741 | if (last_reads.size()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2742 | // Look at the reads if any... if reads exist, they are either the resaon the access is in the event |
| 2743 | // first scope, or they are a hazard. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2744 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2745 | if (read_access.tag.IsBefore(event_tag)) { |
| 2746 | // The read is in the events first synchronization scope, so we use a barrier hazard check |
| 2747 | // If the read stage is not in the src sync scope |
| 2748 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 2749 | // then the barrier access is unsafe (R/W after R) |
| 2750 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
| 2751 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2752 | break; |
| 2753 | } |
| 2754 | } else { |
| 2755 | // The read not in the event first sync scope and so is a hazard vs. the layout transition |
| 2756 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2757 | } |
| 2758 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2759 | } else if (last_write.any()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2760 | // if there are no reads, the write is either the reason the access is in the event scope... they are a hazard |
| 2761 | if (write_tag.IsBefore(event_tag)) { |
| 2762 | // The write is in the first sync scope of the event (sync their aren't any reads to be the reason) |
| 2763 | // So do a normal barrier hazard check |
| 2764 | if (IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2765 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2766 | } |
| 2767 | } else { |
| 2768 | // 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] | 2769 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2770 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2771 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2772 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2773 | return hazard; |
| 2774 | } |
| 2775 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2776 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 2777 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 2778 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 2779 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
| 2780 | if (write_tag.IsBefore(other.write_tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2781 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 2782 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2783 | *this = other; |
| 2784 | } else if (!other.write_tag.IsBefore(write_tag)) { |
| 2785 | // This is the *equals* case for write operations, we merged the write barriers and the read state (but without the |
| 2786 | // dependency chaining logic or any stage expansion) |
| 2787 | write_barriers |= other.write_barriers; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2788 | pending_write_barriers |= other.pending_write_barriers; |
| 2789 | pending_layout_transition |= other.pending_layout_transition; |
| 2790 | pending_write_dep_chain |= other.pending_write_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2791 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2792 | // Merge the read states |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2793 | const auto pre_merge_count = last_reads.size(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2794 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2795 | 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] | 2796 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2797 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2798 | // 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] | 2799 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 2800 | // but we should wait on profiling data for that. |
| 2801 | 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] | 2802 | auto &my_read = last_reads[my_read_index]; |
| 2803 | if (other_read.stage == my_read.stage) { |
| 2804 | if (my_read.tag.IsBefore(other_read.tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2805 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2806 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2807 | my_read.tag = other_read.tag; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2808 | my_read.pending_dep_chain = other_read.pending_dep_chain; |
| 2809 | // TODO: Phase 2 -- review the state merge logic to avoid false positive from overwriting the barriers |
| 2810 | // May require tracking more than one access per stage. |
| 2811 | my_read.barriers = other_read.barriers; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2812 | if (my_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2813 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 2814 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2815 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2816 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2817 | } else if (other_read.tag.IsBefore(my_read.tag)) { |
| 2818 | // The read tags match so merge the barriers |
| 2819 | my_read.barriers |= other_read.barriers; |
| 2820 | my_read.pending_dep_chain |= other_read.pending_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2821 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2822 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2823 | break; |
| 2824 | } |
| 2825 | } |
| 2826 | } else { |
| 2827 | // The other read stage doesn't exist in this, so add it. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2828 | last_reads.emplace_back(other_read); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2829 | last_read_stages |= other_read.stage; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2830 | if (other_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2831 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2832 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2833 | } |
| 2834 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2835 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2836 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 2837 | // ignore it. |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2838 | |
| 2839 | // Merge first access information by making a copy of this first_access and reconstructing with a shuffle |
| 2840 | // of the copy and other into this using the update first logic. |
| 2841 | // NOTE: All sorts of additional cleverness could be put into short circuts. (for example back is write and is before front |
| 2842 | // of the other first_accesses... ) |
| 2843 | if (!(first_accesses_ == other.first_accesses_) && !other.first_accesses_.empty()) { |
| 2844 | FirstAccesses firsts(std::move(first_accesses_)); |
| 2845 | first_accesses_.clear(); |
| 2846 | first_read_stages_ = 0U; |
| 2847 | auto a = firsts.begin(); |
| 2848 | auto a_end = firsts.end(); |
| 2849 | for (auto &b : other.first_accesses_) { |
| 2850 | // TODO: Determine whether "IsBefore" or "IsGloballyBefore" is needed... |
| 2851 | while (a != a_end && a->tag.IsBefore(b.tag)) { |
| 2852 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 2853 | ++a; |
| 2854 | } |
| 2855 | UpdateFirst(b.tag, b.usage_index, b.ordering_rule); |
| 2856 | } |
| 2857 | for (; a != a_end; ++a) { |
| 2858 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 2859 | } |
| 2860 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2861 | } |
| 2862 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2863 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, SyncOrdering ordering_rule, const ResourceUsageTag &tag) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2864 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 2865 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2866 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2867 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 2868 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 2869 | const auto usage_stage = PipelineStageBit(usage_index); |
| 2870 | if (usage_stage & last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2871 | for (auto &read_access : last_reads) { |
| 2872 | if (read_access.stage == usage_stage) { |
| 2873 | read_access.Set(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2874 | break; |
| 2875 | } |
| 2876 | } |
| 2877 | } else { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2878 | last_reads.emplace_back(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2879 | last_read_stages |= usage_stage; |
| 2880 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2881 | |
| 2882 | // 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] | 2883 | if (usage_stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2884 | // TODO Revisit re: multiple reads for a given stage |
| 2885 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2886 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2887 | } else { |
| 2888 | // Assume write |
| 2889 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2890 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2891 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2892 | UpdateFirst(tag, usage_index, ordering_rule); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2893 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2894 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2895 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 2896 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 2897 | // We can overwrite them as *this* write is now after them. |
| 2898 | // |
| 2899 | // 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] | 2900 | void ResourceAccessState::SetWrite(const SyncStageAccessFlags &usage_bit, const ResourceUsageTag &tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2901 | last_reads.clear(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2902 | last_read_stages = 0; |
| 2903 | read_execution_barriers = 0; |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2904 | 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] | 2905 | |
| 2906 | write_barriers = 0; |
| 2907 | write_dependency_chain = 0; |
| 2908 | write_tag = tag; |
| 2909 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2910 | } |
| 2911 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2912 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 2913 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 2914 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 2915 | // replace the current write barriers or add to them, so accumulate to pending as well. |
| 2916 | void ResourceAccessState::ApplyBarrier(const SyncBarrier &barrier, bool layout_transition) { |
| 2917 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 2918 | // applying the memory barriers |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 2919 | // NOTE: We update the write barrier if the write is in the first access scope or if there is a layout |
| 2920 | // transistion, under the theory of "most recent access". If the read/write *isn't* safe |
| 2921 | // vs. this layout transition DetectBarrierHazard should report it. We treat the layout |
| 2922 | // 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] | 2923 | 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] | 2924 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2925 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2926 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2927 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 2928 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2929 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2930 | if (!pending_layout_transition) { |
| 2931 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 2932 | // 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] | 2933 | for (auto &read_access : last_reads) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2934 | // 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] | 2935 | if (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers)) { |
| 2936 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2937 | } |
| 2938 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2939 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2940 | } |
| 2941 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2942 | // Apply the tag scoped memory barrier without updating the existing barriers. The execution barrier |
| 2943 | // changes the "chaining" state, but to keep barriers independent. See discussion above. |
| 2944 | void ResourceAccessState::ApplyBarrier(const ResourceUsageTag &scope_tag, const SyncBarrier &barrier, bool layout_transition) { |
| 2945 | // The scope logic for events is, if we're here, the resource usage was flagged as "in the first execution scope" at |
| 2946 | // the time of the SetEvent, thus all we need check is whether the access is the same one (i.e. before the scope tag |
| 2947 | // in order to know if it's in the excecution scope |
| 2948 | // Notice that the layout transition sets the pending barriers *regardless*, as any lack of src_access_scope to |
| 2949 | // guard against the layout transition should be reported in the detect barrier hazard phase, and we only report |
| 2950 | // errors w.r.t. "most recent" accesses. |
| 2951 | if (layout_transition || ((write_tag.IsBefore(scope_tag)) && (barrier.src_access_scope & last_write).any())) { |
| 2952 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2953 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2954 | } |
| 2955 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 2956 | pending_layout_transition |= layout_transition; |
| 2957 | |
| 2958 | if (!pending_layout_transition) { |
| 2959 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 2960 | // 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] | 2961 | for (auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2962 | // If this read is the same one we included in the set event and in scope, then apply the execution barrier... |
| 2963 | // NOTE: That's not really correct... this read stage might *not* have been included in the setevent, and the barriers |
| 2964 | // representing the chain might have changed since then (that would be an odd usage), so as a first approximation |
| 2965 | // we'll assume the barriers *haven't* been changed since (if the tag hasn't), and while this could be a false |
| 2966 | // positive in the case of Set; SomeBarrier; Wait; we'll live with it until we can add more state to the first scope |
| 2967 | // capture (the specific write and read stages that *were* in scope at the moment of SetEvents. |
| 2968 | // 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] | 2969 | if (read_access.tag.IsBefore(scope_tag) && |
| 2970 | (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers))) { |
| 2971 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2972 | } |
| 2973 | } |
| 2974 | } |
| 2975 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2976 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag &tag) { |
| 2977 | if (pending_layout_transition) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2978 | // SetWrite clobbers the read count, and thus we don't have to clear the read_state out. |
| 2979 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2980 | UpdateFirst(tag, SYNC_IMAGE_LAYOUT_TRANSITION, SyncOrdering::kNonAttachment); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2981 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2982 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2983 | |
| 2984 | // Apply the accumulate execution barriers (and thus update chaining information) |
| 2985 | // 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] | 2986 | for (auto &read_access : last_reads) { |
| 2987 | read_access.barriers |= read_access.pending_dep_chain; |
| 2988 | read_execution_barriers |= read_access.barriers; |
| 2989 | read_access.pending_dep_chain = 0; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 2993 | write_dependency_chain |= pending_write_dep_chain; |
| 2994 | write_barriers |= pending_write_barriers; |
| 2995 | pending_write_dep_chain = 0; |
| 2996 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2997 | } |
| 2998 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2999 | // 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] | 3000 | VkPipelineStageFlags2KHR ResourceAccessState::GetReadBarriers(const SyncStageAccessFlags &usage_bit) const { |
| 3001 | VkPipelineStageFlags2KHR barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3002 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3003 | for (const auto &read_access : last_reads) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3004 | if ((read_access.access & usage_bit).any()) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3005 | barriers = read_access.barriers; |
| 3006 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3007 | } |
| 3008 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3009 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3010 | return barriers; |
| 3011 | } |
| 3012 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3013 | inline bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlags2KHR usage_stage, const SyncStageAccessFlags &usage) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3014 | assert(IsRead(usage)); |
| 3015 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 3016 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 3017 | // any reads that happen after. |
| 3018 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 3019 | // 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] | 3020 | return last_write.any() && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3021 | } |
| 3022 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3023 | VkPipelineStageFlags2KHR ResourceAccessState::GetOrderedStages(const OrderingBarrier &ordering) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3024 | // 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] | 3025 | VkPipelineStageFlags2KHR ordered_stages = last_read_stages & ordering.exec_scope; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3026 | // Special input attachment handling as always (not encoded in exec_scop) |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3027 | 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] | 3028 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3029 | // 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] | 3030 | ordered_stages |= VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | return ordered_stages; |
| 3034 | } |
| 3035 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3036 | void ResourceAccessState::UpdateFirst(const ResourceUsageTag &tag, SyncStageAccessIndex usage_index, SyncOrdering ordering_rule) { |
| 3037 | // Only record until we record a write. |
| 3038 | if (first_accesses_.empty() || IsRead(first_accesses_.back().usage_index)) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3039 | const VkPipelineStageFlags2KHR usage_stage = IsRead(usage_index) ? PipelineStageBit(usage_index) : 0U; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3040 | if (0 == (usage_stage & first_read_stages_)) { |
| 3041 | // If this is a read we haven't seen or a write, record. |
| 3042 | first_read_stages_ |= usage_stage; |
| 3043 | first_accesses_.emplace_back(tag, usage_index, ordering_rule); |
| 3044 | } |
| 3045 | } |
| 3046 | } |
| 3047 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3048 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3049 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 3050 | if (access_context) { |
| 3051 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3052 | } |
| 3053 | } |
| 3054 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3055 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 3056 | auto access_found = cb_access_state.find(command_buffer); |
| 3057 | if (access_found != cb_access_state.end()) { |
| 3058 | access_found->second->Reset(); |
| 3059 | cb_access_state.erase(access_found); |
| 3060 | } |
| 3061 | } |
| 3062 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3063 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3064 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 3065 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3066 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3067 | assert(cb_context); |
| 3068 | if (!cb_context) return skip; |
| 3069 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3070 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3071 | // If we have no previous accesses, we have no hazards |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3072 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3073 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3074 | |
| 3075 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3076 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3077 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3078 | 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] | 3079 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3080 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3081 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3082 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3083 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3084 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3085 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3086 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3087 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3088 | 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] | 3089 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3090 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3091 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3092 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3093 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3094 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3098 | } |
| 3099 | return skip; |
| 3100 | } |
| 3101 | |
| 3102 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3103 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3104 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3105 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3106 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3107 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3108 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3109 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3110 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3111 | |
| 3112 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3113 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3114 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3115 | 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] | 3116 | 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] | 3117 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3118 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3119 | 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] | 3120 | 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] | 3121 | } |
| 3122 | } |
| 3123 | } |
| 3124 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3125 | void SyncValidator::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 3126 | // Clear out events from the command buffer contexts |
| 3127 | for (auto &cb_context : cb_access_state) { |
| 3128 | cb_context.second->RecordDestroyEvent(event); |
| 3129 | } |
| 3130 | } |
| 3131 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3132 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3133 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 3134 | bool skip = false; |
| 3135 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3136 | assert(cb_context); |
| 3137 | if (!cb_context) return skip; |
| 3138 | const auto *context = cb_context->GetCurrentAccessContext(); |
| 3139 | |
| 3140 | // If we have no previous accesses, we have no hazards |
| 3141 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3142 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3143 | |
| 3144 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3145 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3146 | if (src_buffer) { |
| 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 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3149 | if (hazard.hazard) { |
| 3150 | // TODO -- add tag information to log msg when useful. |
| 3151 | skip |= LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3152 | "vkCmdCopyBuffer2KHR(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3153 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3154 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3155 | } |
| 3156 | } |
| 3157 | if (dst_buffer && !skip) { |
| 3158 | 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] | 3159 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3160 | if (hazard.hazard) { |
| 3161 | skip |= LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3162 | "vkCmdCopyBuffer2KHR(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3163 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3164 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3165 | } |
| 3166 | } |
| 3167 | if (skip) break; |
| 3168 | } |
| 3169 | return skip; |
| 3170 | } |
| 3171 | |
| 3172 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 3173 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3174 | assert(cb_context); |
| 3175 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER2KHR); |
| 3176 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3177 | |
| 3178 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3179 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3180 | |
| 3181 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3182 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3183 | if (src_buffer) { |
| 3184 | 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] | 3185 | 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] | 3186 | } |
| 3187 | if (dst_buffer) { |
| 3188 | 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] | 3189 | 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] | 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3194 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3195 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3196 | const VkImageCopy *pRegions) const { |
| 3197 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3198 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3199 | assert(cb_access_context); |
| 3200 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3201 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3202 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3203 | assert(context); |
| 3204 | if (!context) return skip; |
| 3205 | |
| 3206 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3207 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3208 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3209 | const auto ©_region = pRegions[region]; |
| 3210 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3211 | 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] | 3212 | copy_region.srcOffset, copy_region.extent); |
| 3213 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3214 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3215 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3216 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3217 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3218 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3222 | VkExtent3D dst_copy_extent = |
| 3223 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3224 | 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] | 3225 | copy_region.dstOffset, dst_copy_extent); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3226 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3227 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3228 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3229 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3230 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3231 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 3232 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3233 | } |
| 3234 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3235 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3236 | return skip; |
| 3237 | } |
| 3238 | |
| 3239 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3240 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3241 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3242 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3243 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3244 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3245 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3246 | assert(context); |
| 3247 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3248 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3249 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3250 | |
| 3251 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3252 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3253 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3254 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3255 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3256 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3257 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3258 | VkExtent3D dst_copy_extent = |
| 3259 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3260 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3261 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3262 | } |
| 3263 | } |
| 3264 | } |
| 3265 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3266 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 3267 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 3268 | bool skip = false; |
| 3269 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3270 | assert(cb_access_context); |
| 3271 | if (!cb_access_context) return skip; |
| 3272 | |
| 3273 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3274 | assert(context); |
| 3275 | if (!context) return skip; |
| 3276 | |
| 3277 | const auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3278 | const auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3279 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3280 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3281 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3282 | 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] | 3283 | copy_region.srcOffset, copy_region.extent); |
| 3284 | if (hazard.hazard) { |
| 3285 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 3286 | "vkCmdCopyImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 3287 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3288 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | if (dst_image) { |
| 3293 | VkExtent3D dst_copy_extent = |
| 3294 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3295 | 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] | 3296 | copy_region.dstOffset, dst_copy_extent); |
| 3297 | if (hazard.hazard) { |
| 3298 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 3299 | "vkCmdCopyImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 3300 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3301 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3302 | } |
| 3303 | if (skip) break; |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | return skip; |
| 3308 | } |
| 3309 | |
| 3310 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 3311 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3312 | assert(cb_access_context); |
| 3313 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE2KHR); |
| 3314 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3315 | assert(context); |
| 3316 | |
| 3317 | auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3318 | auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3319 | |
| 3320 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3321 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3322 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3323 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3324 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3325 | } |
| 3326 | if (dst_image) { |
| 3327 | VkExtent3D dst_copy_extent = |
| 3328 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3329 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3330 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3331 | } |
| 3332 | } |
| 3333 | } |
| 3334 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3335 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3336 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3337 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3338 | uint32_t bufferMemoryBarrierCount, |
| 3339 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3340 | uint32_t imageMemoryBarrierCount, |
| 3341 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 3342 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3343 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3344 | assert(cb_access_context); |
| 3345 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3346 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 3347 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 3348 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 3349 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 3350 | pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 3351 | skip = pipeline_barrier.Validate(*cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3352 | return skip; |
| 3353 | } |
| 3354 | |
| 3355 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3356 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3357 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3358 | uint32_t bufferMemoryBarrierCount, |
| 3359 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3360 | uint32_t imageMemoryBarrierCount, |
| 3361 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3362 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3363 | assert(cb_access_context); |
| 3364 | if (!cb_access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3365 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 3366 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 3367 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 3368 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 3369 | pImageMemoryBarriers); |
| 3370 | pipeline_barrier.Record(cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3371 | } |
| 3372 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 3373 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 3374 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 3375 | bool skip = false; |
| 3376 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3377 | assert(cb_access_context); |
| 3378 | if (!cb_access_context) return skip; |
| 3379 | |
| 3380 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3381 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 3382 | return skip; |
| 3383 | } |
| 3384 | |
| 3385 | void SyncValidator::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) { |
| 3386 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3387 | assert(cb_access_context); |
| 3388 | if (!cb_access_context) return; |
| 3389 | |
| 3390 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3391 | pipeline_barrier.Record(cb_access_context); |
| 3392 | } |
| 3393 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3394 | void SyncValidator::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 3395 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result) { |
| 3396 | // The state tracker sets up the device state |
| 3397 | StateTracker::PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, result); |
| 3398 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3399 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 3400 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3401 | // TODO: Find a good way to do this hooklessly. |
| 3402 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 3403 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, LayerObjectTypeSyncValidation); |
| 3404 | SyncValidator *sync_device_state = static_cast<SyncValidator *>(validation_data); |
| 3405 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3406 | sync_device_state->SetCommandBufferResetCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3407 | sync_device_state->ResetCommandBufferCallback(command_buffer); |
| 3408 | }); |
| 3409 | sync_device_state->SetCommandBufferFreeCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3410 | sync_device_state->FreeCommandBufferCallback(command_buffer); |
| 3411 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3412 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3413 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3414 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3415 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd, const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3416 | bool skip = false; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3417 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3418 | if (cb_context) { |
| 3419 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo, cmd_name); |
| 3420 | skip = sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3421 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3422 | return skip; |
| 3423 | } |
| 3424 | |
| 3425 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3426 | VkSubpassContents contents) const { |
| 3427 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3428 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3429 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3430 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3431 | return skip; |
| 3432 | } |
| 3433 | |
| 3434 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3435 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3436 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3437 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3438 | return skip; |
| 3439 | } |
| 3440 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3441 | static const char *kBeginRenderPass2KhrName = "vkCmdBeginRenderPass2KHR"; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3442 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3443 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3444 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3445 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3446 | skip |= |
| 3447 | ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2, kBeginRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3448 | return skip; |
| 3449 | } |
| 3450 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3451 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 3452 | VkResult result) { |
| 3453 | // The state tracker sets up the command buffer state |
| 3454 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 3455 | |
| 3456 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 3457 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 3458 | assert(cb_access_context); |
| 3459 | cb_access_context->Reset(); |
| 3460 | } |
| 3461 | |
| 3462 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3463 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd, const char *cmd_name) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3464 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3465 | if (cb_context) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3466 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo, cmd_name); |
| 3467 | sync_op.Record(cb_context); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3468 | } |
| 3469 | } |
| 3470 | |
| 3471 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3472 | VkSubpassContents contents) { |
| 3473 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3474 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3475 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3476 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3480 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3481 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3482 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3486 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3487 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3488 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3489 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2, kBeginRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3490 | } |
| 3491 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3492 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3493 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3494 | bool skip = false; |
| 3495 | |
| 3496 | auto cb_context = GetAccessContext(commandBuffer); |
| 3497 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3498 | if (!cb_context) return skip; |
| 3499 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo, cmd_name); |
| 3500 | return sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 3504 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3505 | // Convert to a NextSubpass2 |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3506 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3507 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3508 | auto subpass_end_info = LvlInitStruct<VkSubpassEndInfo>(); |
| 3509 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, &subpass_end_info, CMD_NEXTSUBPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3510 | return skip; |
| 3511 | } |
| 3512 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3513 | static const char *kNextSubpass2KhrName = "vkCmdNextSubpass2KHR"; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3514 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3515 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3516 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3517 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2, kNextSubpass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3518 | return skip; |
| 3519 | } |
| 3520 | |
| 3521 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3522 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 3523 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3524 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3525 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3529 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, const char *cmd_name) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3530 | auto cb_context = GetAccessContext(commandBuffer); |
| 3531 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3532 | if (!cb_context) return; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3533 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3534 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo, cmd_name); |
| 3535 | sync_op.Record(cb_context); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3536 | } |
| 3537 | |
| 3538 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 3539 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3540 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3541 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3542 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3546 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3547 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3548 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3552 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3553 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3554 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2, kNextSubpass2KhrName); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3555 | } |
| 3556 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3557 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, |
| 3558 | const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3559 | bool skip = false; |
| 3560 | |
| 3561 | auto cb_context = GetAccessContext(commandBuffer); |
| 3562 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3563 | if (!cb_context) return skip; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3564 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3565 | SyncOpEndRenderPass sync_op(cmd, *this, pSubpassEndInfo, cmd_name); |
| 3566 | skip |= sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3567 | return skip; |
| 3568 | } |
| 3569 | |
| 3570 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 3571 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3572 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3573 | return skip; |
| 3574 | } |
| 3575 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3576 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3577 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3578 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3579 | return skip; |
| 3580 | } |
| 3581 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3582 | const static char *kEndRenderPass2KhrName = "vkEndRenderPass2KHR"; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3583 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3584 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3585 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3586 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2, kEndRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3587 | return skip; |
| 3588 | } |
| 3589 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3590 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, |
| 3591 | const char *cmd_name) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3592 | // Resolve the all subpass contexts to the command buffer contexts |
| 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; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -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 | sync_op.Record(cb_context); |
| 3599 | return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3600 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3601 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 3602 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 3603 | // updates to a resource which do not conflict at the byte level. |
| 3604 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 3605 | // TODO: Add programatic control over suppression heuristics |
| 3606 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 3607 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 3608 | } |
| 3609 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3610 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3611 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3612 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3613 | } |
| 3614 | |
| 3615 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3616 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3617 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3621 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2, kEndRenderPass2KhrName); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3622 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3623 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3624 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3625 | template <typename BufferImageCopyRegionType> |
| 3626 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3627 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3628 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3629 | bool skip = false; |
| 3630 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3631 | assert(cb_access_context); |
| 3632 | if (!cb_access_context) return skip; |
| 3633 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3634 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3635 | const char *func_name = is_2khr ? "vkCmdCopyBufferToImage2KHR()" : "vkCmdCopyBufferToImage()"; |
| 3636 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3637 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3638 | assert(context); |
| 3639 | if (!context) return skip; |
| 3640 | |
| 3641 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3642 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3643 | |
| 3644 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3645 | const auto ©_region = pRegions[region]; |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3646 | HazardResult hazard; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3647 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3648 | if (src_buffer) { |
| 3649 | ResourceAccessRange src_range = |
| 3650 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3651 | hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3652 | if (hazard.hazard) { |
| 3653 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 3654 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3655 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3656 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3657 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3658 | } |
| 3659 | } |
| 3660 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3661 | hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.imageSubresource, |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3662 | copy_region.imageOffset, copy_region.imageExtent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3663 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3664 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3665 | "%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] | 3666 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3667 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3668 | } |
| 3669 | if (skip) break; |
| 3670 | } |
| 3671 | if (skip) break; |
| 3672 | } |
| 3673 | return skip; |
| 3674 | } |
| 3675 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3676 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3677 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3678 | const VkBufferImageCopy *pRegions) const { |
| 3679 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
| 3680 | COPY_COMMAND_VERSION_1); |
| 3681 | } |
| 3682 | |
| 3683 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3684 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 3685 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3686 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3687 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3688 | } |
| 3689 | |
| 3690 | template <typename BufferImageCopyRegionType> |
| 3691 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3692 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3693 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3694 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3695 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3696 | |
| 3697 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3698 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYBUFFERTOIMAGE2KHR : CMD_COPYBUFFERTOIMAGE; |
| 3699 | |
| 3700 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3701 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3702 | assert(context); |
| 3703 | |
| 3704 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3705 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3706 | |
| 3707 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3708 | const auto ©_region = pRegions[region]; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3709 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3710 | if (src_buffer) { |
| 3711 | ResourceAccessRange src_range = |
| 3712 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3713 | 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] | 3714 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3715 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3716 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3717 | } |
| 3718 | } |
| 3719 | } |
| 3720 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3721 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3722 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3723 | const VkBufferImageCopy *pRegions) { |
| 3724 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
| 3725 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3726 | } |
| 3727 | |
| 3728 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3729 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 3730 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 3731 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3732 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3733 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3734 | } |
| 3735 | |
| 3736 | template <typename BufferImageCopyRegionType> |
| 3737 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3738 | VkBuffer dstBuffer, uint32_t regionCount, |
| 3739 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3740 | bool skip = false; |
| 3741 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3742 | assert(cb_access_context); |
| 3743 | if (!cb_access_context) return skip; |
| 3744 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3745 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3746 | const char *func_name = is_2khr ? "vkCmdCopyImageToBuffer2KHR()" : "vkCmdCopyImageToBuffer()"; |
| 3747 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3748 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3749 | assert(context); |
| 3750 | if (!context) return skip; |
| 3751 | |
| 3752 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3753 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3754 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->binding.mem_state->mem : VK_NULL_HANDLE; |
| 3755 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3756 | const auto ©_region = pRegions[region]; |
| 3757 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3758 | 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] | 3759 | copy_region.imageOffset, copy_region.imageExtent); |
| 3760 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3761 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3762 | "%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] | 3763 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3764 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3765 | } |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3766 | if (dst_mem) { |
| 3767 | ResourceAccessRange dst_range = |
| 3768 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3769 | hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3770 | if (hazard.hazard) { |
| 3771 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3772 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3773 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3774 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3775 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3776 | } |
| 3777 | } |
| 3778 | if (skip) break; |
| 3779 | } |
| 3780 | return skip; |
| 3781 | } |
| 3782 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3783 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 3784 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 3785 | const VkBufferImageCopy *pRegions) const { |
| 3786 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
| 3787 | COPY_COMMAND_VERSION_1); |
| 3788 | } |
| 3789 | |
| 3790 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3791 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 3792 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3793 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3794 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3795 | } |
| 3796 | |
| 3797 | template <typename BufferImageCopyRegionType> |
| 3798 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3799 | VkBuffer dstBuffer, uint32_t regionCount, const BufferImageCopyRegionType *pRegions, |
| 3800 | CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3801 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3802 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3803 | |
| 3804 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3805 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYIMAGETOBUFFER2KHR : CMD_COPYIMAGETOBUFFER; |
| 3806 | |
| 3807 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3808 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3809 | assert(context); |
| 3810 | |
| 3811 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3812 | auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3813 | 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] | 3814 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3815 | |
| 3816 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3817 | const auto ©_region = pRegions[region]; |
| 3818 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3819 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3820 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3821 | if (dst_buffer) { |
| 3822 | ResourceAccessRange dst_range = |
| 3823 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3824 | 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] | 3825 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3826 | } |
| 3827 | } |
| 3828 | } |
| 3829 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3830 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3831 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 3832 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
| 3833 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3834 | } |
| 3835 | |
| 3836 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3837 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 3838 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 3839 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3840 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3841 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3842 | } |
| 3843 | |
| 3844 | template <typename RegionType> |
| 3845 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3846 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3847 | const RegionType *pRegions, VkFilter filter, const char *apiName) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3848 | bool skip = false; |
| 3849 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3850 | assert(cb_access_context); |
| 3851 | if (!cb_access_context) return skip; |
| 3852 | |
| 3853 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3854 | assert(context); |
| 3855 | if (!context) return skip; |
| 3856 | |
| 3857 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3858 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3859 | |
| 3860 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3861 | const auto &blit_region = pRegions[region]; |
| 3862 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3863 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3864 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3865 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3866 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3867 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3868 | 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] | 3869 | 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] | 3870 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3871 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3872 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3873 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3874 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3879 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3880 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3881 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3882 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3883 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3884 | 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] | 3885 | 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] | 3886 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3887 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3888 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3889 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3890 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3891 | } |
| 3892 | if (skip) break; |
| 3893 | } |
| 3894 | } |
| 3895 | |
| 3896 | return skip; |
| 3897 | } |
| 3898 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3899 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3900 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3901 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 3902 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
| 3903 | "vkCmdBlitImage"); |
| 3904 | } |
| 3905 | |
| 3906 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 3907 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 3908 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 3909 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 3910 | pBlitImageInfo->filter, "vkCmdBlitImage2KHR"); |
| 3911 | } |
| 3912 | |
| 3913 | template <typename RegionType> |
| 3914 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3915 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3916 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3917 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3918 | assert(cb_access_context); |
| 3919 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3920 | assert(context); |
| 3921 | |
| 3922 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3923 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3924 | |
| 3925 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3926 | const auto &blit_region = pRegions[region]; |
| 3927 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3928 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3929 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3930 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3931 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3932 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3933 | 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] | 3934 | context->UpdateAccessState(*src_image, SYNC_BLIT_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3935 | blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3936 | } |
| 3937 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3938 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3939 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3940 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3941 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3942 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3943 | 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] | 3944 | context->UpdateAccessState(*dst_image, SYNC_BLIT_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3945 | blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3946 | } |
| 3947 | } |
| 3948 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3949 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3950 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3951 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3952 | const VkImageBlit *pRegions, VkFilter filter) { |
| 3953 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3954 | assert(cb_access_context); |
| 3955 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 3956 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 3957 | pRegions, filter); |
| 3958 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 3959 | } |
| 3960 | |
| 3961 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 3962 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 3963 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3964 | assert(cb_access_context); |
| 3965 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 3966 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 3967 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 3968 | pBlitImageInfo->filter, tag); |
| 3969 | } |
| 3970 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3971 | bool SyncValidator::ValidateIndirectBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 3972 | VkCommandBuffer commandBuffer, const VkDeviceSize struct_size, const VkBuffer buffer, |
| 3973 | const VkDeviceSize offset, const uint32_t drawCount, const uint32_t stride, |
| 3974 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3975 | bool skip = false; |
| 3976 | if (drawCount == 0) return skip; |
| 3977 | |
| 3978 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 3979 | VkDeviceSize size = struct_size; |
| 3980 | if (drawCount == 1 || stride == size) { |
| 3981 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3982 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3983 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3984 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3985 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3986 | "%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] | 3987 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3988 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3989 | } |
| 3990 | } else { |
| 3991 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3992 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3993 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3994 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3995 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3996 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
| 3997 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3998 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3999 | break; |
| 4000 | } |
| 4001 | } |
| 4002 | } |
| 4003 | return skip; |
| 4004 | } |
| 4005 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4006 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag &tag, const VkDeviceSize struct_size, |
| 4007 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 4008 | uint32_t stride) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4009 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 4010 | VkDeviceSize size = struct_size; |
| 4011 | if (drawCount == 1 || stride == size) { |
| 4012 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4013 | const ResourceAccessRange range = MakeRange(offset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4014 | 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] | 4015 | } else { |
| 4016 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4017 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4018 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, |
| 4019 | tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4020 | } |
| 4021 | } |
| 4022 | } |
| 4023 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4024 | bool SyncValidator::ValidateCountBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4025 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4026 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4027 | bool skip = false; |
| 4028 | |
| 4029 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4030 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4031 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4032 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4033 | skip |= LogError(count_buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4034 | "%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] | 4035 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4036 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4037 | } |
| 4038 | return skip; |
| 4039 | } |
| 4040 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4041 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag &tag, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4042 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4043 | const ResourceAccessRange range = MakeRange(offset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4044 | 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] | 4045 | } |
| 4046 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4047 | 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] | 4048 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4049 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4050 | assert(cb_access_context); |
| 4051 | if (!cb_access_context) return skip; |
| 4052 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4053 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4054 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | 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] | 4058 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4059 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4060 | assert(cb_access_context); |
| 4061 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4062 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4063 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4064 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4065 | |
| 4066 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4067 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4068 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4069 | assert(cb_access_context); |
| 4070 | if (!cb_access_context) return skip; |
| 4071 | |
| 4072 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4073 | assert(context); |
| 4074 | if (!context) return skip; |
| 4075 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4076 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4077 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, |
| 4078 | 1, sizeof(VkDispatchIndirectCommand), "vkCmdDispatchIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4079 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4083 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4084 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4085 | assert(cb_access_context); |
| 4086 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 4087 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4088 | assert(context); |
| 4089 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4090 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 4091 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4095 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4096 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4097 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4098 | assert(cb_access_context); |
| 4099 | if (!cb_access_context) return skip; |
| 4100 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4101 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw"); |
| 4102 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, "vkCmdDraw"); |
| 4103 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDraw"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4104 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4108 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4109 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4110 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4111 | assert(cb_access_context); |
| 4112 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4113 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4114 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4115 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 4116 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4120 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4121 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4122 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4123 | assert(cb_access_context); |
| 4124 | if (!cb_access_context) return skip; |
| 4125 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4126 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed"); |
| 4127 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, "vkCmdDrawIndexed"); |
| 4128 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexed"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4129 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4133 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4134 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4135 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4136 | assert(cb_access_context); |
| 4137 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4138 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4139 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4140 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 4141 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4142 | } |
| 4143 | |
| 4144 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4145 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4146 | bool skip = false; |
| 4147 | if (drawCount == 0) return skip; |
| 4148 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4149 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4150 | assert(cb_access_context); |
| 4151 | if (!cb_access_context) return skip; |
| 4152 | |
| 4153 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4154 | assert(context); |
| 4155 | if (!context) return skip; |
| 4156 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4157 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect"); |
| 4158 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4159 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4160 | drawCount, stride, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4161 | |
| 4162 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4163 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4164 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4165 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4166 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4170 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4171 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4172 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4173 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4174 | assert(cb_access_context); |
| 4175 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 4176 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4177 | assert(context); |
| 4178 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4179 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4180 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4181 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4182 | |
| 4183 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4184 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4185 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4186 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4187 | } |
| 4188 | |
| 4189 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4190 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4191 | bool skip = false; |
| 4192 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4193 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4194 | assert(cb_access_context); |
| 4195 | if (!cb_access_context) return skip; |
| 4196 | |
| 4197 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4198 | assert(context); |
| 4199 | if (!context) return skip; |
| 4200 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4201 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect"); |
| 4202 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexedIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4203 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4204 | offset, drawCount, stride, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4205 | |
| 4206 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4207 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4208 | // 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] | 4209 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4210 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4214 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4215 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4216 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4217 | assert(cb_access_context); |
| 4218 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 4219 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4220 | assert(context); |
| 4221 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4222 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4223 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4224 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4225 | |
| 4226 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4227 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4228 | // 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] | 4229 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4233 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4234 | uint32_t stride, const char *function) const { |
| 4235 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4236 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4237 | assert(cb_access_context); |
| 4238 | if (!cb_access_context) return skip; |
| 4239 | |
| 4240 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4241 | assert(context); |
| 4242 | if (!context) return skip; |
| 4243 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4244 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4245 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4246 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4247 | maxDrawCount, stride, function); |
| 4248 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4249 | |
| 4250 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4251 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4252 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4253 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4254 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4258 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4259 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4260 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4261 | "vkCmdDrawIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4265 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4266 | uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4267 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4268 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4269 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4270 | assert(cb_access_context); |
| 4271 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECTCOUNT); |
| 4272 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4273 | assert(context); |
| 4274 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4275 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4276 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4277 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 4278 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4279 | |
| 4280 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4281 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4282 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4283 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4287 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4288 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4289 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4290 | "vkCmdDrawIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4291 | } |
| 4292 | |
| 4293 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4294 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4295 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4296 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4297 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4298 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4302 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4303 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4304 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4305 | "vkCmdDrawIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4306 | } |
| 4307 | |
| 4308 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4309 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4310 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4311 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4312 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4313 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4314 | } |
| 4315 | |
| 4316 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4317 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4318 | uint32_t stride, const char *function) const { |
| 4319 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4320 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4321 | assert(cb_access_context); |
| 4322 | if (!cb_access_context) return skip; |
| 4323 | |
| 4324 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4325 | assert(context); |
| 4326 | if (!context) return skip; |
| 4327 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4328 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4329 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4330 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4331 | offset, maxDrawCount, stride, function); |
| 4332 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4333 | |
| 4334 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4335 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4336 | // 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] | 4337 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4338 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4342 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4343 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4344 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4345 | "vkCmdDrawIndexedIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4349 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4350 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4351 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4352 | maxDrawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4353 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4354 | assert(cb_access_context); |
| 4355 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 4356 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4357 | assert(context); |
| 4358 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4359 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4360 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4361 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 4362 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4363 | |
| 4364 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4365 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4366 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 4367 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4371 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4372 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4373 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4374 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4375 | "vkCmdDrawIndexedIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4376 | } |
| 4377 | |
| 4378 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4379 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4380 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4381 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4382 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4383 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4384 | } |
| 4385 | |
| 4386 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4387 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4388 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4389 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4390 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4391 | "vkCmdDrawIndexedIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4392 | } |
| 4393 | |
| 4394 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4395 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4396 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4397 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4398 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4399 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4400 | } |
| 4401 | |
| 4402 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4403 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4404 | const VkImageSubresourceRange *pRanges) const { |
| 4405 | bool skip = false; |
| 4406 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4407 | assert(cb_access_context); |
| 4408 | if (!cb_access_context) return skip; |
| 4409 | |
| 4410 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4411 | assert(context); |
| 4412 | if (!context) return skip; |
| 4413 | |
| 4414 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4415 | |
| 4416 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4417 | const auto &range = pRanges[index]; |
| 4418 | if (image_state) { |
| 4419 | auto hazard = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4420 | 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] | 4421 | if (hazard.hazard) { |
| 4422 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4423 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4424 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4425 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4426 | } |
| 4427 | } |
| 4428 | } |
| 4429 | return skip; |
| 4430 | } |
| 4431 | |
| 4432 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4433 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4434 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4435 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4436 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4437 | assert(cb_access_context); |
| 4438 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 4439 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4440 | assert(context); |
| 4441 | |
| 4442 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4443 | |
| 4444 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4445 | const auto &range = pRanges[index]; |
| 4446 | if (image_state) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4447 | 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] | 4448 | image_state->createInfo.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4449 | } |
| 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 4454 | VkImageLayout imageLayout, |
| 4455 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4456 | const VkImageSubresourceRange *pRanges) const { |
| 4457 | bool skip = false; |
| 4458 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4459 | assert(cb_access_context); |
| 4460 | if (!cb_access_context) return skip; |
| 4461 | |
| 4462 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4463 | assert(context); |
| 4464 | if (!context) return skip; |
| 4465 | |
| 4466 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4467 | |
| 4468 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4469 | const auto &range = pRanges[index]; |
| 4470 | if (image_state) { |
| 4471 | auto hazard = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4472 | 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] | 4473 | if (hazard.hazard) { |
| 4474 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4475 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4476 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4477 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4478 | } |
| 4479 | } |
| 4480 | } |
| 4481 | return skip; |
| 4482 | } |
| 4483 | |
| 4484 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4485 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4486 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4487 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4488 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4489 | assert(cb_access_context); |
| 4490 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 4491 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4492 | assert(context); |
| 4493 | |
| 4494 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4495 | |
| 4496 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4497 | const auto &range = pRanges[index]; |
| 4498 | if (image_state) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4499 | 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] | 4500 | image_state->createInfo.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4501 | } |
| 4502 | } |
| 4503 | } |
| 4504 | |
| 4505 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4506 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 4507 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 4508 | VkQueryResultFlags flags) const { |
| 4509 | bool skip = false; |
| 4510 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4511 | assert(cb_access_context); |
| 4512 | if (!cb_access_context) return skip; |
| 4513 | |
| 4514 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4515 | assert(context); |
| 4516 | if (!context) return skip; |
| 4517 | |
| 4518 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4519 | |
| 4520 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4521 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4522 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4523 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4524 | skip |= |
| 4525 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4526 | "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] | 4527 | 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] | 4528 | } |
| 4529 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4530 | |
| 4531 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4532 | return skip; |
| 4533 | } |
| 4534 | |
| 4535 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 4536 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4537 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4538 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 4539 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4540 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4541 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4542 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4543 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4544 | assert(context); |
| 4545 | |
| 4546 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4547 | |
| 4548 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4549 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4550 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4551 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4552 | |
| 4553 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4554 | } |
| 4555 | |
| 4556 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4557 | VkDeviceSize size, uint32_t data) const { |
| 4558 | bool skip = false; |
| 4559 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4560 | assert(cb_access_context); |
| 4561 | if (!cb_access_context) return skip; |
| 4562 | |
| 4563 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4564 | assert(context); |
| 4565 | if (!context) return skip; |
| 4566 | |
| 4567 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4568 | |
| 4569 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4570 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4571 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4572 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4573 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4574 | "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] | 4575 | 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] | 4576 | } |
| 4577 | } |
| 4578 | return skip; |
| 4579 | } |
| 4580 | |
| 4581 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4582 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4583 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4584 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4585 | assert(cb_access_context); |
| 4586 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 4587 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4588 | assert(context); |
| 4589 | |
| 4590 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4591 | |
| 4592 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4593 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4594 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4595 | } |
| 4596 | } |
| 4597 | |
| 4598 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4599 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4600 | const VkImageResolve *pRegions) const { |
| 4601 | bool skip = false; |
| 4602 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4603 | assert(cb_access_context); |
| 4604 | if (!cb_access_context) return skip; |
| 4605 | |
| 4606 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4607 | assert(context); |
| 4608 | if (!context) return skip; |
| 4609 | |
| 4610 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4611 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4612 | |
| 4613 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4614 | const auto &resolve_region = pRegions[region]; |
| 4615 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4616 | 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] | 4617 | resolve_region.srcOffset, resolve_region.extent); |
| 4618 | if (hazard.hazard) { |
| 4619 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4620 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4621 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4622 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4623 | } |
| 4624 | } |
| 4625 | |
| 4626 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4627 | 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] | 4628 | resolve_region.dstOffset, resolve_region.extent); |
| 4629 | if (hazard.hazard) { |
| 4630 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4631 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4632 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4633 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4634 | } |
| 4635 | if (skip) break; |
| 4636 | } |
| 4637 | } |
| 4638 | |
| 4639 | return skip; |
| 4640 | } |
| 4641 | |
| 4642 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4643 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4644 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4645 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4646 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4647 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4648 | assert(cb_access_context); |
| 4649 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 4650 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4651 | assert(context); |
| 4652 | |
| 4653 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4654 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4655 | |
| 4656 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4657 | const auto &resolve_region = pRegions[region]; |
| 4658 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4659 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4660 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4661 | } |
| 4662 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4663 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4664 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4665 | } |
| 4666 | } |
| 4667 | } |
| 4668 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4669 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4670 | const VkResolveImageInfo2KHR *pResolveImageInfo) const { |
| 4671 | bool skip = false; |
| 4672 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4673 | assert(cb_access_context); |
| 4674 | if (!cb_access_context) return skip; |
| 4675 | |
| 4676 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4677 | assert(context); |
| 4678 | if (!context) return skip; |
| 4679 | |
| 4680 | const auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4681 | const auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4682 | |
| 4683 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4684 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4685 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4686 | 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] | 4687 | resolve_region.srcOffset, resolve_region.extent); |
| 4688 | if (hazard.hazard) { |
| 4689 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 4690 | "vkCmdResolveImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 4691 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4692 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4693 | } |
| 4694 | } |
| 4695 | |
| 4696 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4697 | 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] | 4698 | resolve_region.dstOffset, resolve_region.extent); |
| 4699 | if (hazard.hazard) { |
| 4700 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 4701 | "vkCmdResolveImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 4702 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4703 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4704 | } |
| 4705 | if (skip) break; |
| 4706 | } |
| 4707 | } |
| 4708 | |
| 4709 | return skip; |
| 4710 | } |
| 4711 | |
| 4712 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4713 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 4714 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 4715 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4716 | assert(cb_access_context); |
| 4717 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE2KHR); |
| 4718 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4719 | assert(context); |
| 4720 | |
| 4721 | auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4722 | auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4723 | |
| 4724 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4725 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4726 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4727 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4728 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4729 | } |
| 4730 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4731 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4732 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4733 | } |
| 4734 | } |
| 4735 | } |
| 4736 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4737 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4738 | VkDeviceSize dataSize, const void *pData) const { |
| 4739 | bool skip = false; |
| 4740 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4741 | assert(cb_access_context); |
| 4742 | if (!cb_access_context) return skip; |
| 4743 | |
| 4744 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4745 | assert(context); |
| 4746 | if (!context) return skip; |
| 4747 | |
| 4748 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4749 | |
| 4750 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4751 | // VK_WHOLE_SIZE not allowed |
| 4752 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4753 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4754 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4755 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4756 | "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] | 4757 | 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] | 4758 | } |
| 4759 | } |
| 4760 | return skip; |
| 4761 | } |
| 4762 | |
| 4763 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4764 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4765 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4766 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4767 | assert(cb_access_context); |
| 4768 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 4769 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4770 | assert(context); |
| 4771 | |
| 4772 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4773 | |
| 4774 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4775 | // VK_WHOLE_SIZE not allowed |
| 4776 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4777 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4778 | } |
| 4779 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4780 | |
| 4781 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4782 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 4783 | bool skip = false; |
| 4784 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4785 | assert(cb_access_context); |
| 4786 | if (!cb_access_context) return skip; |
| 4787 | |
| 4788 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4789 | assert(context); |
| 4790 | if (!context) return skip; |
| 4791 | |
| 4792 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4793 | |
| 4794 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4795 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4796 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4797 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4798 | skip |= |
| 4799 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4800 | "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] | 4801 | 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] | 4802 | } |
| 4803 | } |
| 4804 | return skip; |
| 4805 | } |
| 4806 | |
| 4807 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4808 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4809 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4810 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4811 | assert(cb_access_context); |
| 4812 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 4813 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4814 | assert(context); |
| 4815 | |
| 4816 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4817 | |
| 4818 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4819 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4820 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4821 | } |
| 4822 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4823 | |
| 4824 | bool SyncValidator::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
| 4825 | bool skip = false; |
| 4826 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4827 | assert(cb_context); |
| 4828 | if (!cb_context) return skip; |
| 4829 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4830 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 4831 | return set_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | void SyncValidator::PostCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 4835 | StateTracker::PostCallRecordCmdSetEvent(commandBuffer, event, stageMask); |
| 4836 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4837 | assert(cb_context); |
| 4838 | if (!cb_context) return; |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4839 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4840 | set_event_op.Record(cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4843 | bool SyncValidator::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4844 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 4845 | bool skip = false; |
| 4846 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4847 | assert(cb_context); |
| 4848 | if (!cb_context || !pDependencyInfo) return skip; |
| 4849 | |
| 4850 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 4851 | return set_event_op.Validate(*cb_context); |
| 4852 | } |
| 4853 | |
| 4854 | void SyncValidator::PostCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4855 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 4856 | StateTracker::PostCallRecordCmdSetEvent2KHR(commandBuffer, event, pDependencyInfo); |
| 4857 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4858 | assert(cb_context); |
| 4859 | if (!cb_context || !pDependencyInfo) return; |
| 4860 | |
| 4861 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 4862 | set_event_op.Record(cb_context); |
| 4863 | } |
| 4864 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4865 | bool SyncValidator::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4866 | VkPipelineStageFlags stageMask) const { |
| 4867 | bool skip = false; |
| 4868 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4869 | assert(cb_context); |
| 4870 | if (!cb_context) return skip; |
| 4871 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4872 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 4873 | return reset_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | void SyncValidator::PostCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 4877 | StateTracker::PostCallRecordCmdResetEvent(commandBuffer, event, stageMask); |
| 4878 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4879 | assert(cb_context); |
| 4880 | if (!cb_context) return; |
| 4881 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4882 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4883 | reset_event_op.Record(cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4884 | } |
| 4885 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4886 | bool SyncValidator::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4887 | VkPipelineStageFlags2KHR stageMask) const { |
| 4888 | bool skip = false; |
| 4889 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4890 | assert(cb_context); |
| 4891 | if (!cb_context) return skip; |
| 4892 | |
| 4893 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4894 | return reset_event_op.Validate(*cb_context); |
| 4895 | } |
| 4896 | |
| 4897 | void SyncValidator::PostCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4898 | VkPipelineStageFlags2KHR stageMask) { |
| 4899 | StateTracker::PostCallRecordCmdResetEvent2KHR(commandBuffer, event, stageMask); |
| 4900 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4901 | assert(cb_context); |
| 4902 | if (!cb_context) return; |
| 4903 | |
| 4904 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4905 | reset_event_op.Record(cb_context); |
| 4906 | } |
| 4907 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4908 | bool SyncValidator::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4909 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4910 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4911 | uint32_t bufferMemoryBarrierCount, |
| 4912 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4913 | uint32_t imageMemoryBarrierCount, |
| 4914 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 4915 | bool skip = false; |
| 4916 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4917 | assert(cb_context); |
| 4918 | if (!cb_context) return skip; |
| 4919 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4920 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 4921 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 4922 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 4923 | return wait_events_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | void SyncValidator::PostCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4927 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4928 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4929 | uint32_t bufferMemoryBarrierCount, |
| 4930 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4931 | uint32_t imageMemoryBarrierCount, |
| 4932 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 4933 | StateTracker::PostCallRecordCmdWaitEvents(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
| 4934 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 4935 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 4936 | |
| 4937 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4938 | assert(cb_context); |
| 4939 | if (!cb_context) return; |
| 4940 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4941 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 4942 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 4943 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
| 4944 | return wait_events_op.Record(cb_context); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4945 | } |
| 4946 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4947 | bool SyncValidator::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4948 | const VkDependencyInfoKHR *pDependencyInfos) const { |
| 4949 | bool skip = false; |
| 4950 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4951 | assert(cb_context); |
| 4952 | if (!cb_context) return skip; |
| 4953 | |
| 4954 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 4955 | skip |= wait_events_op.Validate(*cb_context); |
| 4956 | return skip; |
| 4957 | } |
| 4958 | |
| 4959 | void SyncValidator::PostCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4960 | const VkDependencyInfoKHR *pDependencyInfos) { |
| 4961 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 4962 | |
| 4963 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4964 | assert(cb_context); |
| 4965 | if (!cb_context) return; |
| 4966 | |
| 4967 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 4968 | wait_events_op.Record(cb_context); |
| 4969 | } |
| 4970 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4971 | void SyncEventState::ResetFirstScope() { |
| 4972 | for (const auto address_type : kAddressTypes) { |
| 4973 | first_scope[static_cast<size_t>(address_type)].clear(); |
| 4974 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 4975 | scope = SyncExecScope(); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | // 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] | 4979 | SyncEventState::IgnoreReason SyncEventState::IsIgnoredByWait(CMD_TYPE cmd, VkPipelineStageFlags2KHR srcStageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4980 | IgnoreReason reason = NotIgnored; |
| 4981 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4982 | if ((CMD_WAITEVENTS2KHR == cmd) && (CMD_SETEVENT == last_command)) { |
| 4983 | reason = SetVsWait2; |
| 4984 | } else if ((last_command == CMD_RESETEVENT || last_command == CMD_RESETEVENT2KHR) && !HasBarrier(0U, 0U)) { |
| 4985 | reason = (last_command == CMD_RESETEVENT) ? ResetWaitRace : Reset2WaitRace; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4986 | } else if (unsynchronized_set) { |
| 4987 | reason = SetRace; |
| 4988 | } else { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4989 | const VkPipelineStageFlags2KHR missing_bits = scope.mask_param & ~srcStageMask; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4990 | if (missing_bits) reason = MissingStageBits; |
| 4991 | } |
| 4992 | |
| 4993 | return reason; |
| 4994 | } |
| 4995 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4996 | bool SyncEventState::HasBarrier(VkPipelineStageFlags2KHR stageMask, VkPipelineStageFlags2KHR exec_scope_arg) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4997 | bool has_barrier = (last_command == CMD_NONE) || (stageMask & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) || |
| 4998 | (barriers & exec_scope_arg) || (barriers & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 4999 | return has_barrier; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5000 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5001 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5002 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5003 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5004 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5005 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5006 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5007 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5008 | : SyncOpBase(cmd), barriers_(1) { |
| 5009 | auto &barrier_set = barriers_[0]; |
| 5010 | barrier_set.dependency_flags = dependencyFlags; |
| 5011 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, srcStageMask); |
| 5012 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, dstStageMask); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5013 | // 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] | 5014 | barrier_set.MakeMemoryBarriers(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, memoryBarrierCount, |
| 5015 | pMemoryBarriers); |
| 5016 | barrier_set.MakeBufferMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 5017 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
| 5018 | barrier_set.MakeImageMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 5019 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5022 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t event_count, |
| 5023 | const VkDependencyInfoKHR *dep_infos) |
| 5024 | : SyncOpBase(cmd), barriers_(event_count) { |
| 5025 | for (uint32_t i = 0; i < event_count; i++) { |
| 5026 | const auto &dep_info = dep_infos[i]; |
| 5027 | auto &barrier_set = barriers_[i]; |
| 5028 | barrier_set.dependency_flags = dep_info.dependencyFlags; |
| 5029 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 5030 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, stage_masks.src); |
| 5031 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, stage_masks.dst); |
| 5032 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
| 5033 | barrier_set.MakeMemoryBarriers(queue_flags, dep_info.dependencyFlags, dep_info.memoryBarrierCount, |
| 5034 | dep_info.pMemoryBarriers); |
| 5035 | barrier_set.MakeBufferMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.bufferMemoryBarrierCount, |
| 5036 | dep_info.pBufferMemoryBarriers); |
| 5037 | barrier_set.MakeImageMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.imageMemoryBarrierCount, |
| 5038 | dep_info.pImageMemoryBarriers); |
| 5039 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5040 | } |
| 5041 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5042 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5043 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5044 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 5045 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5046 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5047 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5048 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5049 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers) {} |
| 5050 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5051 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5052 | const VkDependencyInfoKHR &dep_info) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5053 | : SyncOpBarriers(cmd, sync_state, queue_flags, 1, &dep_info) {} |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5054 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5055 | bool SyncOpPipelineBarrier::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5056 | bool skip = false; |
| 5057 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5058 | assert(context); |
| 5059 | if (!context) return skip; |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5060 | assert(barriers_.size() == 1); // PipelineBarriers only support a single barrier set. |
| 5061 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5062 | // Validate Image Layout transitions |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5063 | const auto &barrier_set = barriers_[0]; |
| 5064 | for (const auto &image_barrier : barrier_set.image_memory_barriers) { |
| 5065 | if (image_barrier.new_layout == image_barrier.old_layout) continue; // Only interested in layout transitions at this point. |
| 5066 | const auto *image_state = image_barrier.image.get(); |
| 5067 | if (!image_state) continue; |
| 5068 | const auto hazard = context->DetectImageBarrierHazard(image_barrier); |
| 5069 | if (hazard.hazard) { |
| 5070 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 5071 | const auto &sync_state = cb_context.GetSyncState(); |
| 5072 | const auto image_handle = image_state->image; |
| 5073 | skip |= sync_state.LogError(image_handle, string_SyncHazardVUID(hazard.hazard), |
| 5074 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5075 | string_SyncHazard(hazard.hazard), image_barrier.index, |
| 5076 | sync_state.report_data->FormatHandle(image_handle).c_str(), |
| 5077 | cb_context.FormatUsage(hazard).c_str()); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5078 | } |
| 5079 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5080 | return skip; |
| 5081 | } |
| 5082 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5083 | struct SyncOpPipelineBarrierFunctorFactory { |
| 5084 | using BarrierOpFunctor = PipelineBarrierOp; |
| 5085 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5086 | using GlobalBarrierOpFunctor = PipelineBarrierOp; |
| 5087 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5088 | using BufferRange = ResourceAccessRange; |
| 5089 | using ImageRange = subresource_adapter::ImageRangeGenerator; |
| 5090 | using GlobalRange = ResourceAccessRange; |
| 5091 | |
| 5092 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier, bool layout_transition) const { |
| 5093 | return ApplyFunctor(BarrierOpFunctor(barrier, layout_transition)); |
| 5094 | } |
| 5095 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, const ResourceUsageTag &tag) const { |
| 5096 | return GlobalApplyFunctor(true /* resolve */, size_hint, tag); |
| 5097 | } |
| 5098 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier) const { |
| 5099 | return GlobalBarrierOpFunctor(barrier, false); |
| 5100 | } |
| 5101 | |
| 5102 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range) const { |
| 5103 | if (!SimpleBinding(buffer)) return ResourceAccessRange(); |
| 5104 | const auto base_address = ResourceBaseAddress(buffer); |
| 5105 | return (range + base_address); |
| 5106 | } |
| 5107 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const SyncImageMemoryBarrier::SubImageRange &range) const { |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 5108 | if (!SimpleBinding(image)) return subresource_adapter::ImageRangeGenerator(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5109 | |
| 5110 | const auto base_address = ResourceBaseAddress(image); |
| 5111 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), range.subresource_range, range.offset, |
| 5112 | range.extent, base_address); |
| 5113 | return range_gen; |
| 5114 | } |
| 5115 | GlobalRange MakeGlobalRangeGen(AccessAddressType) const { return kFullRange; } |
| 5116 | }; |
| 5117 | |
| 5118 | template <typename Barriers, typename FunctorFactory> |
| 5119 | void SyncOpBarriers::ApplyBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag &tag, |
| 5120 | AccessContext *context) { |
| 5121 | for (const auto &barrier : barriers) { |
| 5122 | const auto *state = barrier.GetState(); |
| 5123 | if (state) { |
| 5124 | auto *const accesses = &context->GetAccessStateMap(GetAccessAddressType(*state)); |
| 5125 | auto update_action = factory.MakeApplyFunctor(barrier.barrier, barrier.IsLayoutTransition()); |
| 5126 | auto range_gen = factory.MakeRangeGen(*state, barrier.Range()); |
| 5127 | UpdateMemoryAccessState(accesses, update_action, &range_gen); |
| 5128 | } |
| 5129 | } |
| 5130 | } |
| 5131 | |
| 5132 | template <typename Barriers, typename FunctorFactory> |
| 5133 | void SyncOpBarriers::ApplyGlobalBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag &tag, |
| 5134 | AccessContext *access_context) { |
| 5135 | auto barriers_functor = factory.MakeGlobalApplyFunctor(barriers.size(), tag); |
| 5136 | for (const auto &barrier : barriers) { |
| 5137 | barriers_functor.EmplaceBack(factory.MakeGlobalBarrierOpFunctor(barrier)); |
| 5138 | } |
| 5139 | for (const auto address_type : kAddressTypes) { |
| 5140 | auto range_gen = factory.MakeGlobalRangeGen(address_type); |
| 5141 | UpdateMemoryAccessState(&(access_context->GetAccessStateMap(address_type)), barriers_functor, &range_gen); |
| 5142 | } |
| 5143 | } |
| 5144 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5145 | void SyncOpPipelineBarrier::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5146 | SyncOpPipelineBarrierFunctorFactory factory; |
| 5147 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5148 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5149 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5150 | // Pipeline barriers only have a single barrier set, unlike WaitEvents2 |
| 5151 | assert(barriers_.size() == 1); |
| 5152 | const auto &barrier_set = barriers_[0]; |
| 5153 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5154 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5155 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
| 5156 | |
| 5157 | if (barrier_set.single_exec_scope) { |
| 5158 | cb_context->ApplyGlobalBarriersToEvents(barrier_set.src_exec_scope, barrier_set.dst_exec_scope); |
| 5159 | } else { |
| 5160 | for (const auto &barrier : barrier_set.memory_barriers) { |
| 5161 | cb_context->ApplyGlobalBarriersToEvents(barrier.src_exec_scope, barrier.dst_exec_scope); |
| 5162 | } |
| 5163 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5166 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(const SyncExecScope &src, const SyncExecScope &dst, |
| 5167 | VkDependencyFlags dependency_flags, uint32_t memory_barrier_count, |
| 5168 | const VkMemoryBarrier *barriers) { |
| 5169 | memory_barriers.reserve(std::max<uint32_t>(1, memory_barrier_count)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5170 | 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] | 5171 | const auto &barrier = barriers[barrier_index]; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5172 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5173 | memory_barriers.emplace_back(sync_barrier); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5174 | } |
| 5175 | if (0 == memory_barrier_count) { |
| 5176 | // If there are no global memory barriers, force an exec barrier |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5177 | memory_barriers.emplace_back(SyncBarrier(src, dst)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5178 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5179 | single_exec_scope = true; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5180 | } |
| 5181 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5182 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5183 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5184 | uint32_t barrier_count, const VkBufferMemoryBarrier *barriers) { |
| 5185 | buffer_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5186 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5187 | const auto &barrier = barriers[index]; |
| 5188 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5189 | if (buffer) { |
| 5190 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5191 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5192 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5193 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5194 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5195 | buffer_memory_barriers.emplace_back(); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5196 | } |
| 5197 | } |
| 5198 | } |
| 5199 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5200 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(VkQueueFlags queue_flags, VkDependencyFlags dependency_flags, |
| 5201 | uint32_t memory_barrier_count, const VkMemoryBarrier2KHR *barriers) { |
| 5202 | memory_barriers.reserve(memory_barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5203 | 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] | 5204 | const auto &barrier = barriers[barrier_index]; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5205 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5206 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5207 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5208 | memory_barriers.emplace_back(sync_barrier); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5209 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5210 | single_exec_scope = false; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5211 | } |
| 5212 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5213 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5214 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5215 | const VkBufferMemoryBarrier2KHR *barriers) { |
| 5216 | buffer_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5217 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5218 | const auto &barrier = barriers[index]; |
| 5219 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5220 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5221 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5222 | if (buffer) { |
| 5223 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5224 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5225 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5226 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5227 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5228 | buffer_memory_barriers.emplace_back(); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5229 | } |
| 5230 | } |
| 5231 | } |
| 5232 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5233 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5234 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5235 | uint32_t barrier_count, const VkImageMemoryBarrier *barriers) { |
| 5236 | image_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5237 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5238 | const auto &barrier = barriers[index]; |
| 5239 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5240 | if (image) { |
| 5241 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5242 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5243 | 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] | 5244 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5245 | image_memory_barriers.emplace_back(); |
| 5246 | 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] | 5247 | } |
| 5248 | } |
| 5249 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5250 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5251 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5252 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5253 | const VkImageMemoryBarrier2KHR *barriers) { |
| 5254 | image_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5255 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5256 | const auto &barrier = barriers[index]; |
| 5257 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5258 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5259 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5260 | if (image) { |
| 5261 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5262 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5263 | 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] | 5264 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5265 | image_memory_barriers.emplace_back(); |
| 5266 | 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] | 5267 | } |
| 5268 | } |
| 5269 | } |
| 5270 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5271 | 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] | 5272 | const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5273 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5274 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5275 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5276 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, VkDependencyFlags(0U), memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5277 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 5278 | pImageMemoryBarriers) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5279 | MakeEventsList(sync_state, eventCount, pEvents); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5280 | } |
| 5281 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5282 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t eventCount, |
| 5283 | const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfo) |
| 5284 | : SyncOpBarriers(cmd, sync_state, queue_flags, eventCount, pDependencyInfo) { |
| 5285 | MakeEventsList(sync_state, eventCount, pEvents); |
| 5286 | assert(events_.size() == barriers_.size()); // Just so nobody gets clever and decides to cull the event or barrier arrays |
| 5287 | } |
| 5288 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5289 | bool SyncOpWaitEvents::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5290 | const char *const ignored = "Wait operation is ignored for this event."; |
| 5291 | bool skip = false; |
| 5292 | const auto &sync_state = cb_context.GetSyncState(); |
| 5293 | const auto command_buffer_handle = cb_context.GetCBState().commandBuffer; |
| 5294 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5295 | for (size_t barrier_set_index = 0; barrier_set_index < barriers_.size(); barrier_set_index++) { |
| 5296 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5297 | if (barrier_set.single_exec_scope) { |
| 5298 | if (barrier_set.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5299 | const std::string vuid = std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 5300 | skip = sync_state.LogInfo(command_buffer_handle, vuid, |
| 5301 | "%s, srcStageMask includes %s, unsupported by synchronization validation.", CmdName(), |
| 5302 | string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT)); |
| 5303 | } else { |
| 5304 | const auto &barriers = barrier_set.memory_barriers; |
| 5305 | for (size_t barrier_index = 0; barrier_index < barriers.size(); barrier_index++) { |
| 5306 | const auto &barrier = barriers[barrier_index]; |
| 5307 | if (barrier.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5308 | const std::string vuid = |
| 5309 | std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 5310 | skip = |
| 5311 | sync_state.LogInfo(command_buffer_handle, vuid, |
| 5312 | "%s, srcStageMask %s of %s %zu, %s %zu, unsupported by synchronization validation.", |
| 5313 | CmdName(), string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT), |
| 5314 | "pDependencyInfo", barrier_set_index, "pMemoryBarriers", barrier_index); |
| 5315 | } |
| 5316 | } |
| 5317 | } |
| 5318 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5319 | } |
| 5320 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5321 | VkPipelineStageFlags2KHR event_stage_masks = 0U; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5322 | VkPipelineStageFlags2KHR barrier_mask_params = 0U; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5323 | bool events_not_found = false; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5324 | const auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5325 | assert(events_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5326 | size_t barrier_set_index = 0; |
| 5327 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 5328 | for (size_t event_index = 0; event_index < events_.size(); event_index++) |
| 5329 | for (const auto &event : events_) { |
| 5330 | const auto *sync_event = events_context->Get(event.get()); |
| 5331 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5332 | if (!sync_event) { |
| 5333 | // NOTE PHASE2: This is where we'll need queue submit time validation to come back and check the srcStageMask bits |
| 5334 | // or solve this with replay creating the SyncEventState in the queue context... also this will be a |
| 5335 | // new validation error... wait without previously submitted set event... |
| 5336 | events_not_found = true; // Demote "extra_stage_bits" error to warning, to avoid false positives at *record time* |
| 5337 | barrier_set_index += barrier_set_incr; |
| 5338 | continue; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5339 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5340 | const auto event_handle = sync_event->event->event; |
| 5341 | // TODO add "destroyed" checks |
| 5342 | |
| 5343 | barrier_mask_params |= barrier_set.src_exec_scope.mask_param; |
| 5344 | const auto &src_exec_scope = barrier_set.src_exec_scope; |
| 5345 | event_stage_masks |= sync_event->scope.mask_param; |
| 5346 | const auto ignore_reason = sync_event->IsIgnoredByWait(cmd_, src_exec_scope.mask_param); |
| 5347 | if (ignore_reason) { |
| 5348 | switch (ignore_reason) { |
| 5349 | case SyncEventState::ResetWaitRace: |
| 5350 | case SyncEventState::Reset2WaitRace: { |
| 5351 | // Four permuations of Reset and Wait calls... |
| 5352 | const char *vuid = |
| 5353 | (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent-event-03834" : "VUID-vkCmdResetEvent-event-03835"; |
| 5354 | if (ignore_reason == SyncEventState::Reset2WaitRace) { |
| 5355 | vuid = |
Jeremy Gebben | 476f5e2 | 2021-03-01 15:27:20 -0700 | [diff] [blame] | 5356 | (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent2KHR-event-03831" : "VUID-vkCmdResetEvent2KHR-event-03832"; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5357 | } |
| 5358 | const char *const message = |
| 5359 | "%s: %s %s operation following %s without intervening execution barrier, may cause race condition. %s"; |
| 5360 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5361 | sync_state.report_data->FormatHandle(event_handle).c_str(), CmdName(), |
| 5362 | CommandTypeString(sync_event->last_command), ignored); |
| 5363 | break; |
| 5364 | } |
| 5365 | case SyncEventState::SetRace: { |
| 5366 | // Issue error message that Wait is waiting on an signal subject to race condition, and is thus ignored for |
| 5367 | // this event |
| 5368 | const char *const vuid = "SYNC-vkCmdWaitEvents-unsynchronized-setops"; |
| 5369 | const char *const message = |
| 5370 | "%s: %s Unsychronized %s calls result in race conditions w.r.t. event signalling, %s %s"; |
| 5371 | const char *const reason = "First synchronization scope is undefined."; |
| 5372 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5373 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5374 | CommandTypeString(sync_event->last_command), reason, ignored); |
| 5375 | break; |
| 5376 | } |
| 5377 | case SyncEventState::MissingStageBits: { |
| 5378 | const auto missing_bits = sync_event->scope.mask_param & ~src_exec_scope.mask_param; |
| 5379 | // Issue error message that event waited for is not in wait events scope |
| 5380 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 5381 | const char *const message = |
| 5382 | "%s: %s stageMask %" PRIx64 " includes bits not present in srcStageMask 0x%" PRIx64 |
| 5383 | ". Bits missing from srcStageMask %s. %s"; |
| 5384 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5385 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5386 | sync_event->scope.mask_param, src_exec_scope.mask_param, |
| 5387 | sync_utils::StringPipelineStageFlags(missing_bits).c_str(), ignored); |
| 5388 | break; |
| 5389 | } |
| 5390 | case SyncEventState::SetVsWait2: { |
| 5391 | skip |= sync_state.LogError(event_handle, "VUID-vkCmdWaitEvents2KHR-pEvents-03837", |
| 5392 | "%s: Follows set of %s by %s. Disallowed.", CmdName(), |
| 5393 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5394 | CommandTypeString(sync_event->last_command)); |
| 5395 | break; |
| 5396 | } |
| 5397 | default: |
| 5398 | assert(ignore_reason == SyncEventState::NotIgnored); |
| 5399 | } |
| 5400 | } else if (barrier_set.image_memory_barriers.size()) { |
| 5401 | const auto &image_memory_barriers = barrier_set.image_memory_barriers; |
| 5402 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5403 | assert(context); |
| 5404 | for (const auto &image_memory_barrier : image_memory_barriers) { |
| 5405 | if (image_memory_barrier.old_layout == image_memory_barrier.new_layout) continue; |
| 5406 | const auto *image_state = image_memory_barrier.image.get(); |
| 5407 | if (!image_state) continue; |
| 5408 | const auto &subresource_range = image_memory_barrier.range.subresource_range; |
| 5409 | const auto &src_access_scope = image_memory_barrier.barrier.src_access_scope; |
| 5410 | const auto hazard = |
| 5411 | context->DetectImageBarrierHazard(*image_state, sync_event->scope.exec_scope, src_access_scope, |
| 5412 | subresource_range, *sync_event, AccessContext::DetectOptions::kDetectAll); |
| 5413 | if (hazard.hazard) { |
| 5414 | skip |= sync_state.LogError(image_state->image, string_SyncHazardVUID(hazard.hazard), |
| 5415 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5416 | string_SyncHazard(hazard.hazard), image_memory_barrier.index, |
| 5417 | sync_state.report_data->FormatHandle(image_state->image).c_str(), |
| 5418 | cb_context.FormatUsage(hazard).c_str()); |
| 5419 | break; |
| 5420 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5421 | } |
| 5422 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5423 | // TODO: Add infrastructure for checking pDependencyInfo's vs. CmdSetEvent2 VUID - vkCmdWaitEvents2KHR - pEvents - |
| 5424 | // 03839 |
| 5425 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5426 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5427 | |
| 5428 | // 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] | 5429 | 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] | 5430 | if (extra_stage_bits) { |
| 5431 | // 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] | 5432 | // NOTE: This isn't exactly the right VUID for WaitEvents2, but it's as close as we currently have support for |
| 5433 | const char *const vuid = |
| 5434 | (CMD_WAITEVENTS == cmd_) ? "VUID-vkCmdWaitEvents-srcStageMask-01158" : "VUID-vkCmdWaitEvents2KHR-pEvents-03838"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5435 | const char *const message = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5436 | "%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] | 5437 | if (events_not_found) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5438 | 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] | 5439 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5440 | " vkCmdSetEvent may be in previously submitted command buffer."); |
| 5441 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5442 | 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] | 5443 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), ""); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5444 | } |
| 5445 | } |
| 5446 | return skip; |
| 5447 | } |
| 5448 | |
| 5449 | struct SyncOpWaitEventsFunctorFactory { |
| 5450 | using BarrierOpFunctor = WaitEventBarrierOp; |
| 5451 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5452 | using GlobalBarrierOpFunctor = WaitEventBarrierOp; |
| 5453 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5454 | using BufferRange = EventSimpleRangeGenerator; |
| 5455 | using ImageRange = EventImageRangeGenerator; |
| 5456 | using GlobalRange = EventSimpleRangeGenerator; |
| 5457 | |
| 5458 | // Need to restrict to only valid exec and access scope for this event |
| 5459 | // Pass by value is intentional to get a copy we can change without modifying the passed barrier |
| 5460 | SyncBarrier RestrictToEvent(SyncBarrier barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 5461 | 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] | 5462 | barrier.src_access_scope = sync_event->scope.valid_accesses & barrier.src_access_scope; |
| 5463 | return barrier; |
| 5464 | } |
| 5465 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier_arg, bool layout_transition) const { |
| 5466 | auto barrier = RestrictToEvent(barrier_arg); |
| 5467 | return ApplyFunctor(BarrierOpFunctor(sync_event->first_scope_tag, barrier, layout_transition)); |
| 5468 | } |
| 5469 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, const ResourceUsageTag &tag) const { |
| 5470 | return GlobalApplyFunctor(false /* don't resolve */, size_hint, tag); |
| 5471 | } |
| 5472 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier_arg) const { |
| 5473 | auto barrier = RestrictToEvent(barrier_arg); |
| 5474 | return GlobalBarrierOpFunctor(sync_event->first_scope_tag, barrier, false); |
| 5475 | } |
| 5476 | |
| 5477 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range_arg) const { |
| 5478 | const AccessAddressType address_type = GetAccessAddressType(buffer); |
| 5479 | const auto base_address = ResourceBaseAddress(buffer); |
| 5480 | ResourceAccessRange range = SimpleBinding(buffer) ? (range_arg + base_address) : ResourceAccessRange(); |
| 5481 | EventSimpleRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), range); |
| 5482 | return filtered_range_gen; |
| 5483 | } |
| 5484 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const SyncImageMemoryBarrier::SubImageRange &range) const { |
| 5485 | if (!SimpleBinding(image)) return ImageRange(); |
| 5486 | const auto address_type = GetAccessAddressType(image); |
| 5487 | const auto base_address = ResourceBaseAddress(image); |
| 5488 | subresource_adapter::ImageRangeGenerator image_range_gen(*image.fragment_encoder.get(), range.subresource_range, |
| 5489 | range.offset, range.extent, base_address); |
| 5490 | EventImageRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), image_range_gen); |
| 5491 | |
| 5492 | return filtered_range_gen; |
| 5493 | } |
| 5494 | GlobalRange MakeGlobalRangeGen(AccessAddressType address_type) const { |
| 5495 | return EventSimpleRangeGenerator(sync_event->FirstScope(address_type), kFullRange); |
| 5496 | } |
| 5497 | SyncOpWaitEventsFunctorFactory(SyncEventState *sync_event_) : sync_event(sync_event_) { assert(sync_event); } |
| 5498 | SyncEventState *sync_event; |
| 5499 | }; |
| 5500 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5501 | void SyncOpWaitEvents::Record(CommandBufferAccessContext *cb_context) const { |
| 5502 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5503 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5504 | assert(access_context); |
| 5505 | if (!access_context) return; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5506 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5507 | assert(events_context); |
| 5508 | if (!events_context) return; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5509 | |
| 5510 | // Unlike PipelineBarrier, WaitEvent is *not* limited to accesses within the current subpass (if any) and thus needs to import |
| 5511 | // all accesses. Can instead import for all first_scopes, or a union of them, if this becomes a performance/memory issue, |
| 5512 | // but with no idea of the performance of the union, nor of whether it even matters... take the simplest approach here, |
| 5513 | access_context->ResolvePreviousAccesses(); |
| 5514 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5515 | // TODO... this needs change the SyncEventContext it's using depending on whether this is replay... the recorded |
| 5516 | // 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] | 5517 | size_t barrier_set_index = 0; |
| 5518 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 5519 | assert(barriers_.size() == 1 || (barriers_.size() == events_.size())); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5520 | for (auto &event_shared : events_) { |
| 5521 | if (!event_shared.get()) continue; |
| 5522 | auto *sync_event = events_context->GetFromShared(event_shared); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5523 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5524 | sync_event->last_command = cmd_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5525 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5526 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5527 | const auto &dst = barrier_set.dst_exec_scope; |
| 5528 | if (!sync_event->IsIgnoredByWait(cmd_, barrier_set.src_exec_scope.mask_param)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5529 | // These apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 5530 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 5531 | // of the barriers is maintained. |
| 5532 | SyncOpWaitEventsFunctorFactory factory(sync_event); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5533 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5534 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5535 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5536 | |
| 5537 | // Apply the global barrier to the event itself (for race condition tracking) |
| 5538 | // Events don't happen at a stage, so we need to store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 5539 | sync_event->barriers = dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 5540 | sync_event->barriers |= dst.exec_scope; |
| 5541 | } else { |
| 5542 | // We ignored this wait, so we don't have any effective synchronization barriers for it. |
| 5543 | sync_event->barriers = 0U; |
| 5544 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5545 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5546 | } |
| 5547 | |
| 5548 | // Apply the pending barriers |
| 5549 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
| 5550 | access_context->ApplyToContext(apply_pending_action); |
| 5551 | } |
| 5552 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5553 | bool SyncValidator::PreCallValidateCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 5554 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 5555 | bool skip = false; |
| 5556 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5557 | assert(cb_access_context); |
| 5558 | if (!cb_access_context) return skip; |
| 5559 | |
| 5560 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5561 | assert(context); |
| 5562 | if (!context) return skip; |
| 5563 | |
| 5564 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5565 | |
| 5566 | if (dst_buffer) { |
| 5567 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 5568 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
| 5569 | if (hazard.hazard) { |
| 5570 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5571 | "vkCmdWriteBufferMarkerAMD2: Hazard %s for dstBuffer %s. Access info %s.", |
| 5572 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), |
| 5573 | string_UsageTag(hazard.tag).c_str()); |
| 5574 | } |
| 5575 | } |
| 5576 | return skip; |
| 5577 | } |
| 5578 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5579 | 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] | 5580 | events_.reserve(event_count); |
| 5581 | for (uint32_t event_index = 0; event_index < event_count; event_index++) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5582 | events_.emplace_back(sync_state.GetShared<EVENT_STATE>(events[event_index])); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5583 | } |
| 5584 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5585 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5586 | 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] | 5587 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5588 | : SyncOpBase(cmd), |
| 5589 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
| 5590 | exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5591 | |
| 5592 | bool SyncOpResetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5593 | auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5594 | assert(events_context); |
| 5595 | bool skip = false; |
| 5596 | if (!events_context) return skip; |
| 5597 | |
| 5598 | const auto &sync_state = cb_context.GetSyncState(); |
| 5599 | const auto *sync_event = events_context->Get(event_); |
| 5600 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5601 | |
| 5602 | const char *const set_wait = |
| 5603 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 5604 | "hazards."; |
| 5605 | const char *message = set_wait; // Only one message this call. |
| 5606 | if (!sync_event->HasBarrier(exec_scope_.mask_param, exec_scope_.exec_scope)) { |
| 5607 | const char *vuid = nullptr; |
| 5608 | switch (sync_event->last_command) { |
| 5609 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5610 | case CMD_SETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5611 | // Needs a barrier between set and reset |
| 5612 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-set"; |
| 5613 | break; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5614 | case CMD_WAITEVENTS: |
| 5615 | case CMD_WAITEVENTS2KHR: { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5616 | // Needs to be in the barriers chain (either because of a barrier, or because of dstStageMask |
| 5617 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-wait"; |
| 5618 | break; |
| 5619 | } |
| 5620 | default: |
| 5621 | // The only other valid last command that wasn't one. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5622 | assert((sync_event->last_command == CMD_NONE) || (sync_event->last_command == CMD_RESETEVENT) || |
| 5623 | (sync_event->last_command == CMD_RESETEVENT2KHR)); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5624 | break; |
| 5625 | } |
| 5626 | if (vuid) { |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5627 | skip |= sync_state.LogError(event_->event, vuid, message, CmdName(), |
| 5628 | sync_state.report_data->FormatHandle(event_->event).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5629 | CommandTypeString(sync_event->last_command)); |
| 5630 | } |
| 5631 | } |
| 5632 | return skip; |
| 5633 | } |
| 5634 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5635 | void SyncOpResetEvent::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5636 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5637 | assert(events_context); |
| 5638 | if (!events_context) return; |
| 5639 | |
| 5640 | auto *sync_event = events_context->GetFromShared(event_); |
| 5641 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5642 | |
| 5643 | // Update the event state |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5644 | sync_event->last_command = cmd_; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5645 | sync_event->unsynchronized_set = CMD_NONE; |
| 5646 | sync_event->ResetFirstScope(); |
| 5647 | sync_event->barriers = 0U; |
| 5648 | } |
| 5649 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5650 | 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] | 5651 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5652 | : SyncOpBase(cmd), |
| 5653 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5654 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)), |
| 5655 | dep_info_() {} |
| 5656 | |
| 5657 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
| 5658 | const VkDependencyInfoKHR &dep_info) |
| 5659 | : SyncOpBase(cmd), |
| 5660 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
| 5661 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, sync_utils::GetGlobalStageMasks(dep_info).src)), |
| 5662 | dep_info_(new safe_VkDependencyInfoKHR(&dep_info)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5663 | |
| 5664 | bool SyncOpSetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5665 | // 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] | 5666 | bool skip = false; |
| 5667 | |
| 5668 | const auto &sync_state = cb_context.GetSyncState(); |
| 5669 | auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5670 | assert(events_context); |
| 5671 | if (!events_context) return skip; |
| 5672 | |
| 5673 | const auto *sync_event = events_context->Get(event_); |
| 5674 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5675 | |
| 5676 | const char *const reset_set = |
| 5677 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 5678 | "hazards."; |
| 5679 | const char *const wait = |
| 5680 | "%s: %s %s operation following %s without intervening vkCmdResetEvent, may result in data hazard and is ignored."; |
| 5681 | |
| 5682 | 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] | 5683 | const char *vuid_stem = nullptr; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5684 | const char *message = nullptr; |
| 5685 | switch (sync_event->last_command) { |
| 5686 | case CMD_RESETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5687 | case CMD_RESETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5688 | // Needs a barrier between reset and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5689 | vuid_stem = "-missingbarrier-reset"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5690 | message = reset_set; |
| 5691 | break; |
| 5692 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5693 | case CMD_SETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5694 | // Needs a barrier between set and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5695 | vuid_stem = "-missingbarrier-set"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5696 | message = reset_set; |
| 5697 | break; |
| 5698 | case CMD_WAITEVENTS: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5699 | case CMD_WAITEVENTS2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5700 | // Needs a barrier or is in second execution scope |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5701 | vuid_stem = "-missingbarrier-wait"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5702 | message = wait; |
| 5703 | break; |
| 5704 | default: |
| 5705 | // The only other valid last command that wasn't one. |
| 5706 | assert(sync_event->last_command == CMD_NONE); |
| 5707 | break; |
| 5708 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5709 | if (vuid_stem) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5710 | assert(nullptr != message); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5711 | std::string vuid("SYNC-"); |
| 5712 | vuid.append(CmdName()).append(vuid_stem); |
| 5713 | skip |= sync_state.LogError(event_->event, vuid.c_str(), message, CmdName(), |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5714 | sync_state.report_data->FormatHandle(event_->event).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5715 | CommandTypeString(sync_event->last_command)); |
| 5716 | } |
| 5717 | } |
| 5718 | |
| 5719 | return skip; |
| 5720 | } |
| 5721 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5722 | void SyncOpSetEvent::Record(CommandBufferAccessContext *cb_context) const { |
| 5723 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5724 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5725 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5726 | assert(events_context); |
| 5727 | if (!events_context) return; |
| 5728 | |
| 5729 | auto *sync_event = events_context->GetFromShared(event_); |
| 5730 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5731 | |
| 5732 | // NOTE: We're going to simply record the sync scope here, as anything else would be implementation defined/undefined |
| 5733 | // and we're issuing errors re: missing barriers between event commands, which if the user fixes would fix |
| 5734 | // any issues caused by naive scope setting here. |
| 5735 | |
| 5736 | // What happens with two SetEvent is that one cannot know what group of operations will be waited for. |
| 5737 | // Given: |
| 5738 | // Stuff1; SetEvent; Stuff2; SetEvent; WaitEvents; |
| 5739 | // WaitEvents cannot know which of Stuff1, Stuff2, or both has completed execution. |
| 5740 | |
| 5741 | if (!sync_event->HasBarrier(src_exec_scope_.mask_param, src_exec_scope_.exec_scope)) { |
| 5742 | sync_event->unsynchronized_set = sync_event->last_command; |
| 5743 | sync_event->ResetFirstScope(); |
| 5744 | } else if (sync_event->scope.exec_scope == 0) { |
| 5745 | // We only set the scope if there isn't one |
| 5746 | sync_event->scope = src_exec_scope_; |
| 5747 | |
| 5748 | auto set_scope = [&sync_event](AccessAddressType address_type, const ResourceAccessRangeMap::value_type &access) { |
| 5749 | auto &scope_map = sync_event->first_scope[static_cast<size_t>(address_type)]; |
| 5750 | if (access.second.InSourceScopeOrChain(sync_event->scope.exec_scope, sync_event->scope.valid_accesses)) { |
| 5751 | scope_map.insert(scope_map.end(), std::make_pair(access.first, true)); |
| 5752 | } |
| 5753 | }; |
| 5754 | access_context->ForAll(set_scope); |
| 5755 | sync_event->unsynchronized_set = CMD_NONE; |
| 5756 | sync_event->first_scope_tag = tag; |
| 5757 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5758 | // TODO: Store dep_info_ shared ptr in sync_state for WaitEvents2 validation |
| 5759 | sync_event->last_command = cmd_; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5760 | sync_event->barriers = 0U; |
| 5761 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 5762 | |
| 5763 | SyncOpBeginRenderPass::SyncOpBeginRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, |
| 5764 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 5765 | const VkSubpassBeginInfo *pSubpassBeginInfo, const char *cmd_name) |
| 5766 | : SyncOpBase(cmd, cmd_name) { |
| 5767 | if (pRenderPassBegin) { |
| 5768 | rp_state_ = sync_state.GetShared<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
| 5769 | renderpass_begin_info_ = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
| 5770 | const auto *fb_state = sync_state.Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
| 5771 | if (fb_state) { |
| 5772 | shared_attachments_ = sync_state.GetSharedAttachmentViews(*renderpass_begin_info_.ptr(), *fb_state); |
| 5773 | // TODO: Revisit this when all attachment validation is through SyncOps to see if we can discard the plain pointer copy |
| 5774 | // Note that this a safe to presist as long as shared_attachments is not cleared |
| 5775 | attachments_.reserve(shared_attachments_.size()); |
sfricke-samsung | 01c9ae9 | 2021-02-09 22:30:52 -0800 | [diff] [blame] | 5776 | for (const auto &attachment : shared_attachments_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 5777 | attachments_.emplace_back(attachment.get()); |
| 5778 | } |
| 5779 | } |
| 5780 | if (pSubpassBeginInfo) { |
| 5781 | subpass_begin_info_ = safe_VkSubpassBeginInfo(pSubpassBeginInfo); |
| 5782 | } |
| 5783 | } |
| 5784 | } |
| 5785 | |
| 5786 | bool SyncOpBeginRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5787 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 5788 | bool skip = false; |
| 5789 | |
| 5790 | assert(rp_state_.get()); |
| 5791 | if (nullptr == rp_state_.get()) return skip; |
| 5792 | auto &rp_state = *rp_state_.get(); |
| 5793 | |
| 5794 | const uint32_t subpass = 0; |
| 5795 | |
| 5796 | // Construct the state we can use to validate against... (since validation is const and RecordCmdBeginRenderPass |
| 5797 | // hasn't happened yet) |
| 5798 | const std::vector<AccessContext> empty_context_vector; |
| 5799 | AccessContext temp_context(subpass, cb_context.GetQueueFlags(), rp_state.subpass_dependencies, empty_context_vector, |
| 5800 | cb_context.GetCurrentAccessContext()); |
| 5801 | |
| 5802 | // Validate attachment operations |
| 5803 | if (attachments_.size() == 0) return skip; |
| 5804 | const auto &render_area = renderpass_begin_info_.renderArea; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 5805 | |
| 5806 | // Since the isn't a valid RenderPassAccessContext until Record, needs to create the view/generator list... we could limit this |
| 5807 | // by predicating on whether subpass 0 uses the attachment if it is too expensive to create the full list redundantly here. |
| 5808 | // More broadly we could look at thread specific state shared between Validate and Record as is done for other heavyweight |
| 5809 | // operations (though it's currently a messy approach) |
| 5810 | AttachmentViewGenVector view_gens = RenderPassAccessContext::CreateAttachmentViewGen(render_area, attachments_); |
| 5811 | skip |= temp_context.ValidateLayoutTransitions(cb_context, rp_state, render_area, subpass, view_gens, CmdName()); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 5812 | |
| 5813 | // Validate load operations if there were no layout transition hazards |
| 5814 | if (!skip) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 5815 | temp_context.RecordLayoutTransitions(rp_state, subpass, view_gens, kCurrentCommandTag); |
| 5816 | skip |= temp_context.ValidateLoadOperation(cb_context, rp_state, render_area, subpass, view_gens, CmdName()); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | return skip; |
| 5820 | } |
| 5821 | |
| 5822 | void SyncOpBeginRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
| 5823 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5824 | assert(rp_state_.get()); |
| 5825 | if (nullptr == rp_state_.get()) return; |
| 5826 | const auto tag = cb_context->NextCommandTag(cmd_); |
| 5827 | cb_context->RecordBeginRenderPass(*rp_state_.get(), renderpass_begin_info_.renderArea, attachments_, tag); |
| 5828 | } |
| 5829 | |
| 5830 | SyncOpNextSubpass::SyncOpNextSubpass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 5831 | const VkSubpassEndInfo *pSubpassEndInfo, const char *name_override) |
| 5832 | : SyncOpBase(cmd, name_override) { |
| 5833 | if (pSubpassBeginInfo) { |
| 5834 | subpass_begin_info_.initialize(pSubpassBeginInfo); |
| 5835 | } |
| 5836 | if (pSubpassEndInfo) { |
| 5837 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 5838 | } |
| 5839 | } |
| 5840 | |
| 5841 | bool SyncOpNextSubpass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5842 | bool skip = false; |
| 5843 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 5844 | if (!renderpass_context) return skip; |
| 5845 | |
| 5846 | skip |= renderpass_context->ValidateNextSubpass(cb_context.GetExecutionContext(), CmdName()); |
| 5847 | return skip; |
| 5848 | } |
| 5849 | |
| 5850 | void SyncOpNextSubpass::Record(CommandBufferAccessContext *cb_context) const { |
| 5851 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5852 | cb_context->RecordNextSubpass(cmd_); |
| 5853 | } |
| 5854 | |
| 5855 | SyncOpEndRenderPass::SyncOpEndRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassEndInfo *pSubpassEndInfo, |
| 5856 | const char *name_override) |
| 5857 | : SyncOpBase(cmd, name_override) { |
| 5858 | if (pSubpassEndInfo) { |
| 5859 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 5860 | } |
| 5861 | } |
| 5862 | |
| 5863 | bool SyncOpEndRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5864 | bool skip = false; |
| 5865 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 5866 | |
| 5867 | if (!renderpass_context) return skip; |
| 5868 | skip |= renderpass_context->ValidateEndRenderPass(cb_context.GetExecutionContext(), CmdName()); |
| 5869 | return skip; |
| 5870 | } |
| 5871 | |
| 5872 | void SyncOpEndRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
| 5873 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5874 | cb_context->RecordEndRenderPass(cmd_); |
| 5875 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5876 | |
| 5877 | void SyncValidator::PreCallRecordCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 5878 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
| 5879 | StateTracker::PreCallRecordCmdWriteBufferMarker2AMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
| 5880 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5881 | assert(cb_access_context); |
| 5882 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 5883 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5884 | assert(context); |
| 5885 | |
| 5886 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5887 | |
| 5888 | if (dst_buffer) { |
| 5889 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 5890 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
| 5891 | } |
| 5892 | } |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 5893 | |
| 5894 | #ifdef SYNCVAL_DIAGNOSTICS |
| 5895 | bool SyncValidator::PreCallValidateDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) const { |
| 5896 | sync_diagnostics.InstanceDump(instance); |
| 5897 | ImageRangeGen::diag_.Report(); |
| 5898 | return StateTracker::PreCallValidateDestroyInstance(instance, pAllocator); |
| 5899 | } |
| 5900 | #endif |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame^] | 5901 | |
| 5902 | AttachmentViewGen::AttachmentViewGen(const IMAGE_VIEW_STATE *view, const VkOffset3D &offset, const VkExtent3D &extent) |
| 5903 | : view_(view), view_mask_(), gen_store_() { |
| 5904 | if (!view_ || !view_->image_state || !SimpleBinding(*view_->image_state)) return; |
| 5905 | const IMAGE_STATE &image_state = *view_->image_state.get(); |
| 5906 | const auto base_address = ResourceBaseAddress(image_state); |
| 5907 | const auto *encoder = image_state.fragment_encoder.get(); |
| 5908 | if (!encoder) return; |
| 5909 | const VkOffset3D zero_offset = {0, 0, 0}; |
| 5910 | const VkExtent3D &image_extent = image_state.createInfo.extent; |
| 5911 | // Intentional copy |
| 5912 | VkImageSubresourceRange subres_range = view_->normalized_subresource_range; |
| 5913 | view_mask_ = subres_range.aspectMask; |
| 5914 | gen_store_[Gen::kViewSubresource].emplace(*encoder, subres_range, zero_offset, image_extent, base_address); |
| 5915 | gen_store_[Gen::kRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 5916 | |
| 5917 | const auto depth = view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT; |
| 5918 | if (depth && (depth != view_mask_)) { |
| 5919 | subres_range.aspectMask = depth; |
| 5920 | gen_store_[Gen::kDepthOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 5921 | } |
| 5922 | const auto stencil = view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT; |
| 5923 | if (stencil && (stencil != view_mask_)) { |
| 5924 | subres_range.aspectMask = stencil; |
| 5925 | gen_store_[Gen::kStencilOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 5926 | } |
| 5927 | } |
| 5928 | |
| 5929 | const ImageRangeGen *AttachmentViewGen::GetRangeGen(AttachmentViewGen::Gen gen_type) const { |
| 5930 | const ImageRangeGen *got = nullptr; |
| 5931 | switch (gen_type) { |
| 5932 | case kViewSubresource: |
| 5933 | got = &gen_store_[kViewSubresource]; |
| 5934 | break; |
| 5935 | case kRenderArea: |
| 5936 | got = &gen_store_[kRenderArea]; |
| 5937 | break; |
| 5938 | case kDepthOnlyRenderArea: |
| 5939 | got = |
| 5940 | (view_mask_ == VK_IMAGE_ASPECT_DEPTH_BIT) ? &gen_store_[Gen::kRenderArea] : &gen_store_[Gen::kDepthOnlyRenderArea]; |
| 5941 | break; |
| 5942 | case kStencilOnlyRenderArea: |
| 5943 | got = (view_mask_ == VK_IMAGE_ASPECT_STENCIL_BIT) ? &gen_store_[Gen::kRenderArea] |
| 5944 | : &gen_store_[Gen::kStencilOnlyRenderArea]; |
| 5945 | break; |
| 5946 | default: |
| 5947 | assert(got); |
| 5948 | } |
| 5949 | return got; |
| 5950 | } |
| 5951 | |
| 5952 | AttachmentViewGen::Gen AttachmentViewGen::GetDepthStencilRenderAreaGenType(bool depth_op, bool stencil_op) const { |
| 5953 | assert(IsValid()); |
| 5954 | assert(view_mask_ & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); |
| 5955 | if (depth_op) { |
| 5956 | assert(view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 5957 | if (stencil_op) { |
| 5958 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 5959 | return kRenderArea; |
| 5960 | } |
| 5961 | return kDepthOnlyRenderArea; |
| 5962 | } |
| 5963 | if (stencil_op) { |
| 5964 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 5965 | return kStencilOnlyRenderArea; |
| 5966 | } |
| 5967 | |
| 5968 | assert(depth_op || stencil_op); |
| 5969 | return kRenderArea; |
| 5970 | } |
| 5971 | |
| 5972 | AccessAddressType AttachmentViewGen::GetAddressType() const { return AccessContext::ImageAddressType(*view_->image_state); } |