John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2019-2021 The Khronos Group Inc. |
| 2 | * Copyright (c) 2019-2021 Valve Corporation |
| 3 | * Copyright (c) 2019-2021 LunarG, Inc. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | * Author: John Zulauf <jzulauf@lunarg.com> |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 18 | * Author: Locke Lin <locke@lunarg.com> |
| 19 | * Author: Jeremy Gebben <jeremyg@lunarg.com> |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <limits> |
| 23 | #include <vector> |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 24 | #include <memory> |
| 25 | #include <bitset> |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 26 | #include "synchronization_validation.h" |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 27 | #include "sync_utils.h" |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 28 | |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 29 | static bool SimpleBinding(const BINDABLE &bindable) { return !bindable.sparse && bindable.Binding(); } |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 30 | |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 31 | static bool SimpleBinding(const IMAGE_STATE &image_state) { |
| 32 | bool simple = SimpleBinding(static_cast<const BINDABLE &>(image_state)) || image_state.is_swapchain_image || |
| 33 | (VK_NULL_HANDLE != image_state.bind_swapchain); |
| 34 | |
| 35 | // If it's not simple we must have an encoder. |
| 36 | assert(!simple || image_state.fragment_encoder.get()); |
| 37 | return simple; |
| 38 | } |
| 39 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 40 | const static std::array<AccessAddressType, static_cast<size_t>(AccessAddressType::kTypeCount)> kAddressTypes = { |
| 41 | AccessAddressType::kLinear, AccessAddressType::kIdealized}; |
| 42 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 43 | static constexpr AccessAddressType GetAccessAddressType(const BUFFER_STATE &) { return AccessAddressType::kLinear; }; |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 44 | static AccessAddressType GetAccessAddressType(const IMAGE_STATE &image) { |
| 45 | return SimpleBinding(image) ? AccessContext::ImageAddressType(image) : AccessAddressType::kIdealized; |
| 46 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 47 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 48 | static const char *string_SyncHazardVUID(SyncHazard hazard) { |
| 49 | switch (hazard) { |
| 50 | case SyncHazard::NONE: |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 51 | return "SYNC-HAZARD-NONE"; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 52 | break; |
| 53 | case SyncHazard::READ_AFTER_WRITE: |
| 54 | return "SYNC-HAZARD-READ_AFTER_WRITE"; |
| 55 | break; |
| 56 | case SyncHazard::WRITE_AFTER_READ: |
| 57 | return "SYNC-HAZARD-WRITE_AFTER_READ"; |
| 58 | break; |
| 59 | case SyncHazard::WRITE_AFTER_WRITE: |
| 60 | return "SYNC-HAZARD-WRITE_AFTER_WRITE"; |
| 61 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 62 | case SyncHazard::READ_RACING_WRITE: |
| 63 | return "SYNC-HAZARD-READ-RACING-WRITE"; |
| 64 | break; |
| 65 | case SyncHazard::WRITE_RACING_WRITE: |
| 66 | return "SYNC-HAZARD-WRITE-RACING-WRITE"; |
| 67 | break; |
| 68 | case SyncHazard::WRITE_RACING_READ: |
| 69 | return "SYNC-HAZARD-WRITE-RACING-READ"; |
| 70 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 71 | default: |
| 72 | assert(0); |
| 73 | } |
| 74 | return "SYNC-HAZARD-INVALID"; |
| 75 | } |
| 76 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 77 | static bool IsHazardVsRead(SyncHazard hazard) { |
| 78 | switch (hazard) { |
| 79 | case SyncHazard::NONE: |
| 80 | return false; |
| 81 | break; |
| 82 | case SyncHazard::READ_AFTER_WRITE: |
| 83 | return false; |
| 84 | break; |
| 85 | case SyncHazard::WRITE_AFTER_READ: |
| 86 | return true; |
| 87 | break; |
| 88 | case SyncHazard::WRITE_AFTER_WRITE: |
| 89 | return false; |
| 90 | break; |
| 91 | case SyncHazard::READ_RACING_WRITE: |
| 92 | return false; |
| 93 | break; |
| 94 | case SyncHazard::WRITE_RACING_WRITE: |
| 95 | return false; |
| 96 | break; |
| 97 | case SyncHazard::WRITE_RACING_READ: |
| 98 | return true; |
| 99 | break; |
| 100 | default: |
| 101 | assert(0); |
| 102 | } |
| 103 | return false; |
| 104 | } |
| 105 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 106 | static const char *string_SyncHazard(SyncHazard hazard) { |
| 107 | switch (hazard) { |
| 108 | case SyncHazard::NONE: |
| 109 | return "NONR"; |
| 110 | break; |
| 111 | case SyncHazard::READ_AFTER_WRITE: |
| 112 | return "READ_AFTER_WRITE"; |
| 113 | break; |
| 114 | case SyncHazard::WRITE_AFTER_READ: |
| 115 | return "WRITE_AFTER_READ"; |
| 116 | break; |
| 117 | case SyncHazard::WRITE_AFTER_WRITE: |
| 118 | return "WRITE_AFTER_WRITE"; |
| 119 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 120 | case SyncHazard::READ_RACING_WRITE: |
| 121 | return "READ_RACING_WRITE"; |
| 122 | break; |
| 123 | case SyncHazard::WRITE_RACING_WRITE: |
| 124 | return "WRITE_RACING_WRITE"; |
| 125 | break; |
| 126 | case SyncHazard::WRITE_RACING_READ: |
| 127 | return "WRITE_RACING_READ"; |
| 128 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 129 | default: |
| 130 | assert(0); |
| 131 | } |
| 132 | return "INVALID HAZARD"; |
| 133 | } |
| 134 | |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 135 | static const SyncStageAccessInfoType *SyncStageAccessInfoFromMask(SyncStageAccessFlags flags) { |
| 136 | // Return the info for the first bit found |
| 137 | const SyncStageAccessInfoType *info = nullptr; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 138 | for (size_t i = 0; i < flags.size(); i++) { |
| 139 | if (flags.test(i)) { |
| 140 | info = &syncStageAccessInfoByStageAccessIndex[i]; |
| 141 | break; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | return info; |
| 145 | } |
| 146 | |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 147 | static std::string string_SyncStageAccessFlags(const SyncStageAccessFlags &flags, const char *sep = "|") { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 148 | std::string out_str; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 149 | if (flags.none()) { |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 150 | out_str = "0"; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 151 | } else { |
| 152 | for (size_t i = 0; i < syncStageAccessInfoByStageAccessIndex.size(); i++) { |
| 153 | const auto &info = syncStageAccessInfoByStageAccessIndex[i]; |
| 154 | if ((flags & info.stage_access_bit).any()) { |
| 155 | if (!out_str.empty()) { |
| 156 | out_str.append(sep); |
| 157 | } |
| 158 | out_str.append(info.name); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 159 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 160 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 161 | if (out_str.length() == 0) { |
| 162 | out_str.append("Unhandled SyncStageAccess"); |
| 163 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 164 | } |
| 165 | return out_str; |
| 166 | } |
| 167 | |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 168 | static std::string string_UsageTag(const ResourceUsageTag &tag) { |
| 169 | std::stringstream out; |
| 170 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 171 | out << "command: " << CommandTypeString(tag.command); |
| 172 | out << ", seq_no: " << tag.seq_num; |
| 173 | if (tag.sub_command != 0) { |
| 174 | out << ", subcmd: " << tag.sub_command; |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 175 | } |
| 176 | return out.str(); |
| 177 | } |
| 178 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 179 | std::string CommandBufferAccessContext::FormatUsage(const HazardResult &hazard) const { |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 180 | const auto &tag = hazard.tag; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 181 | assert(hazard.usage_index < static_cast<SyncStageAccessIndex>(syncStageAccessInfoByStageAccessIndex.size())); |
| 182 | const auto &usage_info = syncStageAccessInfoByStageAccessIndex[hazard.usage_index]; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 183 | std::stringstream out; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 184 | const auto *info = SyncStageAccessInfoFromMask(hazard.prior_access); |
| 185 | const char *stage_access_name = info ? info->name : "INVALID_STAGE_ACCESS"; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 186 | out << "(usage: " << usage_info.name << ", prior_usage: " << stage_access_name; |
| 187 | if (IsHazardVsRead(hazard.hazard)) { |
| 188 | const auto barriers = hazard.access_state->GetReadBarriers(hazard.prior_access); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 189 | out << ", read_barriers: " << string_VkPipelineStageFlags2KHR(barriers); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 190 | } else { |
| 191 | SyncStageAccessFlags write_barrier = hazard.access_state->GetWriteBarriers(); |
| 192 | out << ", write_barriers: " << string_SyncStageAccessFlags(write_barrier); |
| 193 | } |
| 194 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 195 | // PHASE2 TODO -- add comand buffer and reset from secondary if applicable |
ZaOniRinku | 56b8647 | 2021-03-23 20:25:05 +0100 | [diff] [blame] | 196 | out << ", " << string_UsageTag(tag) << ", reset_no: " << reset_count_ << ")"; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 197 | return out.str(); |
| 198 | } |
| 199 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 200 | // NOTE: the attachement read flag is put *only* in the access scope and not in the exect scope, since the ordering |
| 201 | // rules apply only to this specific access for this stage, and not the stage as a whole. The ordering detection |
| 202 | // 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] | 203 | 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] | 204 | static const SyncStageAccessFlags kColorAttachmentAccessScope = |
| 205 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_BIT | |
| 206 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT | |
| 207 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE_BIT | |
| 208 | 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] | 209 | static constexpr VkPipelineStageFlags2KHR kDepthStencilAttachmentExecScope = |
| 210 | 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] | 211 | static const SyncStageAccessFlags kDepthStencilAttachmentAccessScope = |
| 212 | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 213 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 214 | 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] | 215 | static constexpr VkPipelineStageFlags2KHR kRasterAttachmentExecScope = kDepthStencilAttachmentExecScope | kColorAttachmentExecScope; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 216 | static const SyncStageAccessFlags kRasterAttachmentAccessScope = kDepthStencilAttachmentAccessScope | kColorAttachmentAccessScope; |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 217 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 218 | ResourceAccessState::OrderingBarriers ResourceAccessState::kOrderingRules = { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 219 | {{VK_PIPELINE_STAGE_2_NONE_KHR, SyncStageAccessFlags()}, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 220 | {kColorAttachmentExecScope, kColorAttachmentAccessScope}, |
| 221 | {kDepthStencilAttachmentExecScope, kDepthStencilAttachmentAccessScope}, |
| 222 | {kRasterAttachmentExecScope, kRasterAttachmentAccessScope}}}; |
| 223 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 224 | // 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] | 225 | static const ResourceUsageTag kCurrentCommandTag(ResourceUsageTag::kMaxIndex, ResourceUsageTag::kMaxCount, |
| 226 | ResourceUsageTag::kMaxCount, CMD_NONE); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 227 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 228 | static VkDeviceSize ResourceBaseAddress(const BINDABLE &bindable) { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 229 | const auto *binding = bindable.Binding(); |
| 230 | return binding ? binding->offset + binding->mem_state->fake_base_address : 0; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 231 | } |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 232 | static VkDeviceSize ResourceBaseAddress(const IMAGE_STATE &image_state) { |
| 233 | VkDeviceSize base_address; |
| 234 | if (image_state.is_swapchain_image || (VK_NULL_HANDLE != image_state.bind_swapchain)) { |
| 235 | base_address = image_state.swapchain_fake_address; |
| 236 | } else { |
| 237 | base_address = ResourceBaseAddress(static_cast<const BINDABLE &>(image_state)); |
| 238 | } |
| 239 | return base_address; |
| 240 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 241 | |
locke-lunarg | 3c03800 | 2020-04-30 23:08:08 -0600 | [diff] [blame] | 242 | inline VkDeviceSize GetRealWholeSize(VkDeviceSize offset, VkDeviceSize size, VkDeviceSize whole_size) { |
| 243 | if (size == VK_WHOLE_SIZE) { |
| 244 | return (whole_size - offset); |
| 245 | } |
| 246 | return size; |
| 247 | } |
| 248 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 249 | static inline VkDeviceSize GetBufferWholeSize(const BUFFER_STATE &buf_state, VkDeviceSize offset, VkDeviceSize size) { |
| 250 | return GetRealWholeSize(offset, size, buf_state.createInfo.size); |
| 251 | } |
| 252 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 253 | template <typename T> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 254 | static ResourceAccessRange MakeRange(const T &has_offset_and_size) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 255 | return ResourceAccessRange(has_offset_and_size.offset, (has_offset_and_size.offset + has_offset_and_size.size)); |
| 256 | } |
| 257 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 258 | static ResourceAccessRange MakeRange(VkDeviceSize start, VkDeviceSize size) { return ResourceAccessRange(start, (start + size)); } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 259 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 260 | static inline ResourceAccessRange MakeRange(const BUFFER_STATE &buffer, VkDeviceSize offset, VkDeviceSize size) { |
| 261 | return MakeRange(offset, GetBufferWholeSize(buffer, offset, size)); |
| 262 | } |
| 263 | |
| 264 | static inline ResourceAccessRange MakeRange(const BUFFER_VIEW_STATE &buf_view_state) { |
| 265 | return MakeRange(*buf_view_state.buffer_state.get(), buf_view_state.create_info.offset, buf_view_state.create_info.range); |
| 266 | } |
| 267 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 268 | // Range generators for to allow event scope filtration to be limited to the top of the resource access traversal pipeline |
| 269 | // |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 270 | // Note: there is no "begin/end" or reset facility. These are each written as "one time through" generators. |
| 271 | // |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 272 | // Usage: |
| 273 | // Constructor() -- initializes the generator to point to the begin of the space declared. |
| 274 | // * -- the current range of the generator empty signfies end |
| 275 | // ++ -- advance to the next non-empty range (or end) |
| 276 | |
| 277 | // A wrapper for a single range with the same semantics as the actual generators below |
| 278 | template <typename KeyType> |
| 279 | class SingleRangeGenerator { |
| 280 | public: |
| 281 | SingleRangeGenerator(const KeyType &range) : current_(range) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 282 | const KeyType &operator*() const { return current_; } |
| 283 | const KeyType *operator->() const { return ¤t_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 284 | SingleRangeGenerator &operator++() { |
| 285 | current_ = KeyType(); // just one real range |
| 286 | return *this; |
| 287 | } |
| 288 | |
| 289 | bool operator==(const SingleRangeGenerator &other) const { return current_ == other.current_; } |
| 290 | |
| 291 | private: |
| 292 | SingleRangeGenerator() = default; |
| 293 | const KeyType range_; |
| 294 | KeyType current_; |
| 295 | }; |
| 296 | |
| 297 | // Generate the ranges that are the intersection of range and the entries in the FilterMap |
| 298 | template <typename FilterMap, typename KeyType = typename FilterMap::key_type> |
| 299 | class FilteredRangeGenerator { |
| 300 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 301 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 302 | FilteredRangeGenerator() : range_(), filter_(nullptr), filter_pos_(), current_() { |
| 303 | // Default construction for KeyType *must* be empty range |
| 304 | assert(current_.empty()); |
| 305 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 306 | FilteredRangeGenerator(const FilterMap &filter, const KeyType &range) |
| 307 | : range_(range), filter_(&filter), filter_pos_(), current_() { |
| 308 | SeekBegin(); |
| 309 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 310 | FilteredRangeGenerator(const FilteredRangeGenerator &from) = default; |
| 311 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 312 | const KeyType &operator*() const { return current_; } |
| 313 | const KeyType *operator->() const { return ¤t_; } |
| 314 | FilteredRangeGenerator &operator++() { |
| 315 | ++filter_pos_; |
| 316 | UpdateCurrent(); |
| 317 | return *this; |
| 318 | } |
| 319 | |
| 320 | bool operator==(const FilteredRangeGenerator &other) const { return current_ == other.current_; } |
| 321 | |
| 322 | private: |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 323 | void UpdateCurrent() { |
| 324 | if (filter_pos_ != filter_->cend()) { |
| 325 | current_ = range_ & filter_pos_->first; |
| 326 | } else { |
| 327 | current_ = KeyType(); |
| 328 | } |
| 329 | } |
| 330 | void SeekBegin() { |
| 331 | filter_pos_ = filter_->lower_bound(range_); |
| 332 | UpdateCurrent(); |
| 333 | } |
| 334 | const KeyType range_; |
| 335 | const FilterMap *filter_; |
| 336 | typename FilterMap::const_iterator filter_pos_; |
| 337 | KeyType current_; |
| 338 | }; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 339 | using SingleAccessRangeGenerator = SingleRangeGenerator<ResourceAccessRange>; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 340 | using EventSimpleRangeGenerator = FilteredRangeGenerator<SyncEventState::ScopeMap>; |
| 341 | |
| 342 | // Templated to allow for different Range generators or map sources... |
| 343 | |
| 344 | // 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] | 345 | template <typename FilterMap, typename RangeGen, typename KeyType = typename FilterMap::key_type> |
| 346 | class FilteredGeneratorGenerator { |
| 347 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 348 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 349 | FilteredGeneratorGenerator() : filter_(nullptr), gen_(), filter_pos_(), current_() { |
| 350 | // Default construction for KeyType *must* be empty range |
| 351 | assert(current_.empty()); |
| 352 | } |
| 353 | 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] | 354 | SeekBegin(); |
| 355 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 356 | FilteredGeneratorGenerator(const FilteredGeneratorGenerator &from) = default; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 357 | const KeyType &operator*() const { return current_; } |
| 358 | const KeyType *operator->() const { return ¤t_; } |
| 359 | FilteredGeneratorGenerator &operator++() { |
| 360 | KeyType gen_range = GenRange(); |
| 361 | KeyType filter_range = FilterRange(); |
| 362 | current_ = KeyType(); |
| 363 | while (gen_range.non_empty() && filter_range.non_empty() && current_.empty()) { |
| 364 | if (gen_range.end > filter_range.end) { |
| 365 | // if the generated range is beyond the filter_range, advance the filter range |
| 366 | filter_range = AdvanceFilter(); |
| 367 | } else { |
| 368 | gen_range = AdvanceGen(); |
| 369 | } |
| 370 | current_ = gen_range & filter_range; |
| 371 | } |
| 372 | return *this; |
| 373 | } |
| 374 | |
| 375 | bool operator==(const FilteredGeneratorGenerator &other) const { return current_ == other.current_; } |
| 376 | |
| 377 | private: |
| 378 | KeyType AdvanceFilter() { |
| 379 | ++filter_pos_; |
| 380 | auto filter_range = FilterRange(); |
| 381 | if (filter_range.valid()) { |
| 382 | FastForwardGen(filter_range); |
| 383 | } |
| 384 | return filter_range; |
| 385 | } |
| 386 | KeyType AdvanceGen() { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 387 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 388 | auto gen_range = GenRange(); |
| 389 | if (gen_range.valid()) { |
| 390 | FastForwardFilter(gen_range); |
| 391 | } |
| 392 | return gen_range; |
| 393 | } |
| 394 | |
| 395 | KeyType FilterRange() const { return (filter_pos_ != filter_->cend()) ? filter_pos_->first : KeyType(); } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 396 | KeyType GenRange() const { return *gen_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 397 | |
| 398 | KeyType FastForwardFilter(const KeyType &range) { |
| 399 | auto filter_range = FilterRange(); |
| 400 | int retry_count = 0; |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 401 | const static int kRetryLimit = 2; // TODO -- determine whether this limit is optimal |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 402 | while (!filter_range.empty() && (filter_range.end <= range.begin)) { |
| 403 | if (retry_count < kRetryLimit) { |
| 404 | ++filter_pos_; |
| 405 | filter_range = FilterRange(); |
| 406 | retry_count++; |
| 407 | } else { |
| 408 | // Okay we've tried walking, do a seek. |
| 409 | filter_pos_ = filter_->lower_bound(range); |
| 410 | break; |
| 411 | } |
| 412 | } |
| 413 | return FilterRange(); |
| 414 | } |
| 415 | |
| 416 | // TODO: Consider adding "seek" (or an absolute bound "get" to range generators to make this walk |
| 417 | // faster. |
| 418 | KeyType FastForwardGen(const KeyType &range) { |
| 419 | auto gen_range = GenRange(); |
| 420 | while (!gen_range.empty() && (gen_range.end <= range.begin)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 421 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 422 | gen_range = GenRange(); |
| 423 | } |
| 424 | return gen_range; |
| 425 | } |
| 426 | |
| 427 | void SeekBegin() { |
| 428 | auto gen_range = GenRange(); |
| 429 | if (gen_range.empty()) { |
| 430 | current_ = KeyType(); |
| 431 | filter_pos_ = filter_->cend(); |
| 432 | } else { |
| 433 | filter_pos_ = filter_->lower_bound(gen_range); |
| 434 | current_ = gen_range & FilterRange(); |
| 435 | } |
| 436 | } |
| 437 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 438 | const FilterMap *filter_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 439 | RangeGen gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 440 | typename FilterMap::const_iterator filter_pos_; |
| 441 | KeyType current_; |
| 442 | }; |
| 443 | |
| 444 | using EventImageRangeGenerator = FilteredGeneratorGenerator<SyncEventState::ScopeMap, subresource_adapter::ImageRangeGenerator>; |
| 445 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 446 | 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] | 447 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 448 | ResourceAccessRange GetBufferRange(VkDeviceSize offset, VkDeviceSize buf_whole_size, uint32_t first_index, uint32_t count, |
| 449 | VkDeviceSize stride) { |
| 450 | VkDeviceSize range_start = offset + first_index * stride; |
| 451 | VkDeviceSize range_size = 0; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 452 | if (count == UINT32_MAX) { |
| 453 | range_size = buf_whole_size - range_start; |
| 454 | } else { |
| 455 | range_size = count * stride; |
| 456 | } |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 457 | return MakeRange(range_start, range_size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 458 | } |
| 459 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 460 | SyncStageAccessIndex GetSyncStageAccessIndexsByDescriptorSet(VkDescriptorType descriptor_type, const interface_var &descriptor_data, |
| 461 | VkShaderStageFlagBits stage_flag) { |
| 462 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 463 | assert(stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT); |
| 464 | return SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ; |
| 465 | } |
| 466 | auto stage_access = syncStageAccessMaskByShaderStage.find(stage_flag); |
| 467 | if (stage_access == syncStageAccessMaskByShaderStage.end()) { |
| 468 | assert(0); |
| 469 | } |
| 470 | if (descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) { |
| 471 | return stage_access->second.uniform_read; |
| 472 | } |
| 473 | |
| 474 | // If the desriptorSet is writable, we don't need to care SHADER_READ. SHADER_WRITE is enough. |
| 475 | // Because if write hazard happens, read hazard might or might not happen. |
| 476 | // But if write hazard doesn't happen, read hazard is impossible to happen. |
| 477 | if (descriptor_data.is_writable) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 478 | return stage_access->second.storage_write; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 479 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 480 | // TODO: sampled_read |
| 481 | return stage_access->second.storage_read; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 482 | } |
| 483 | |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 484 | bool IsImageLayoutDepthWritable(VkImageLayout image_layout) { |
| 485 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 486 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL || |
| 487 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) |
| 488 | ? true |
| 489 | : false; |
| 490 | } |
| 491 | |
| 492 | bool IsImageLayoutStencilWritable(VkImageLayout image_layout) { |
| 493 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 494 | image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL || |
| 495 | image_layout == VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL) |
| 496 | ? true |
| 497 | : false; |
| 498 | } |
| 499 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 500 | // 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] | 501 | template <typename Action> |
| 502 | static void ApplyOverImageRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &subresource_range_arg, |
| 503 | Action &action) { |
| 504 | // At this point the "apply over range" logic only supports a single memory binding |
| 505 | if (!SimpleBinding(image_state)) return; |
| 506 | auto subresource_range = NormalizeSubresourceRange(image_state.createInfo, subresource_range_arg); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 507 | const auto base_address = ResourceBaseAddress(image_state); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 508 | subresource_adapter::ImageRangeGenerator range_gen(*image_state.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
| 509 | image_state.createInfo.extent, base_address); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 510 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 511 | action(*range_gen); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 515 | // Tranverse the attachment resolves for this a specific subpass, and do action() to them. |
| 516 | // Used by both validation and record operations |
| 517 | // |
| 518 | // The signature for Action() reflect the needs of both uses. |
| 519 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 520 | void ResolveOperation(Action &action, const RENDER_PASS_STATE &rp_state, const AttachmentViewGenVector &attachment_views, |
| 521 | uint32_t subpass) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 522 | const auto &rp_ci = rp_state.createInfo; |
| 523 | const auto *attachment_ci = rp_ci.pAttachments; |
| 524 | const auto &subpass_ci = rp_ci.pSubpasses[subpass]; |
| 525 | |
| 526 | // Color resolves -- require an inuse color attachment and a matching inuse resolve attachment |
| 527 | const auto *color_attachments = subpass_ci.pColorAttachments; |
| 528 | const auto *color_resolve = subpass_ci.pResolveAttachments; |
| 529 | if (color_resolve && color_attachments) { |
| 530 | for (uint32_t i = 0; i < subpass_ci.colorAttachmentCount; i++) { |
| 531 | const auto &color_attach = color_attachments[i].attachment; |
| 532 | const auto &resolve_attach = subpass_ci.pResolveAttachments[i].attachment; |
| 533 | if ((color_attach != VK_ATTACHMENT_UNUSED) && (resolve_attach != VK_ATTACHMENT_UNUSED)) { |
| 534 | action("color", "resolve read", color_attach, resolve_attach, attachment_views[color_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 535 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, |
| 536 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 537 | action("color", "resolve write", color_attach, resolve_attach, attachment_views[resolve_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 538 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 539 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | // Depth stencil resolve only if the extension is present |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 545 | const auto ds_resolve = LvlFindInChain<VkSubpassDescriptionDepthStencilResolve>(subpass_ci.pNext); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 546 | if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment && |
| 547 | (ds_resolve->pDepthStencilResolveAttachment->attachment != VK_ATTACHMENT_UNUSED) && subpass_ci.pDepthStencilAttachment && |
| 548 | (subpass_ci.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) { |
| 549 | const auto src_at = subpass_ci.pDepthStencilAttachment->attachment; |
| 550 | const auto src_ci = attachment_ci[src_at]; |
| 551 | // The formats are required to match so we can pick either |
| 552 | const bool resolve_depth = (ds_resolve->depthResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasDepth(src_ci.format); |
| 553 | const bool resolve_stencil = (ds_resolve->stencilResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasStencil(src_ci.format); |
| 554 | const auto dst_at = ds_resolve->pDepthStencilResolveAttachment->attachment; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 555 | |
| 556 | // Figure out which aspects are actually touched during resolve operations |
| 557 | const char *aspect_string = nullptr; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 558 | AttachmentViewGen::Gen gen_type = AttachmentViewGen::Gen::kRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 559 | if (resolve_depth && resolve_stencil) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 560 | aspect_string = "depth/stencil"; |
| 561 | } else if (resolve_depth) { |
| 562 | // Validate depth only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 563 | gen_type = AttachmentViewGen::Gen::kDepthOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 564 | aspect_string = "depth"; |
| 565 | } else if (resolve_stencil) { |
| 566 | // Validate all stencil only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 567 | gen_type = AttachmentViewGen::Gen::kStencilOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 568 | aspect_string = "stencil"; |
| 569 | } |
| 570 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 571 | if (aspect_string) { |
| 572 | action(aspect_string, "resolve read", src_at, dst_at, attachment_views[src_at], gen_type, |
| 573 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, SyncOrdering::kRaster); |
| 574 | action(aspect_string, "resolve write", src_at, dst_at, attachment_views[dst_at], gen_type, |
| 575 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | // Action for validating resolve operations |
| 581 | class ValidateResolveAction { |
| 582 | public: |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 583 | ValidateResolveAction(VkRenderPass render_pass, uint32_t subpass, const AccessContext &context, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 584 | const CommandExecutionContext &ex_context, const char *func_name) |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 585 | : render_pass_(render_pass), |
| 586 | subpass_(subpass), |
| 587 | context_(context), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 588 | ex_context_(ex_context), |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 589 | func_name_(func_name), |
| 590 | skip_(false) {} |
| 591 | 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] | 592 | const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, |
| 593 | SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 594 | HazardResult hazard; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 595 | hazard = context_.DetectHazard(view_gen, gen_type, current_usage, ordering_rule); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 596 | if (hazard.hazard) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 597 | skip_ |= |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 598 | ex_context_.GetSyncState().LogError(render_pass_, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 599 | "%s: Hazard %s in subpass %" PRIu32 "during %s %s, from attachment %" PRIu32 |
| 600 | " to resolve attachment %" PRIu32 ". Access info %s.", |
| 601 | func_name_, string_SyncHazard(hazard.hazard), subpass_, aspect_name, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 602 | attachment_name, src_at, dst_at, ex_context_.FormatUsage(hazard).c_str()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | // Providing a mechanism for the constructing caller to get the result of the validation |
| 606 | bool GetSkip() const { return skip_; } |
| 607 | |
| 608 | private: |
| 609 | VkRenderPass render_pass_; |
| 610 | const uint32_t subpass_; |
| 611 | const AccessContext &context_; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 612 | const CommandExecutionContext &ex_context_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 613 | const char *func_name_; |
| 614 | bool skip_; |
| 615 | }; |
| 616 | |
| 617 | // Update action for resolve operations |
| 618 | class UpdateStateResolveAction { |
| 619 | public: |
| 620 | UpdateStateResolveAction(AccessContext &context, const ResourceUsageTag &tag) : context_(context), tag_(tag) {} |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 621 | void operator()(const char *, const char *, uint32_t, uint32_t, const AttachmentViewGen &view_gen, |
| 622 | AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 623 | // Ignores validation only arguments... |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 624 | context_.UpdateAccessState(view_gen, gen_type, current_usage, ordering_rule, tag_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | private: |
| 628 | AccessContext &context_; |
| 629 | const ResourceUsageTag &tag_; |
| 630 | }; |
| 631 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 632 | void HazardResult::Set(const ResourceAccessState *access_state_, SyncStageAccessIndex usage_index_, SyncHazard hazard_, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 633 | const SyncStageAccessFlags &prior_, const ResourceUsageTag &tag_) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 634 | access_state = std::unique_ptr<const ResourceAccessState>(new ResourceAccessState(*access_state_)); |
| 635 | usage_index = usage_index_; |
| 636 | hazard = hazard_; |
| 637 | prior_access = prior_; |
| 638 | tag = tag_; |
| 639 | } |
| 640 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 641 | AccessContext::AccessContext(uint32_t subpass, VkQueueFlags queue_flags, |
| 642 | const std::vector<SubpassDependencyGraphNode> &dependencies, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 643 | const std::vector<AccessContext> &contexts, const AccessContext *external_context) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 644 | Reset(); |
| 645 | const auto &subpass_dep = dependencies[subpass]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 646 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 647 | prev_.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 648 | 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] | 649 | for (const auto &prev_dep : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 650 | const auto prev_pass = prev_dep.first->pass; |
| 651 | const auto &prev_barriers = prev_dep.second; |
| 652 | assert(prev_dep.second.size()); |
| 653 | prev_.emplace_back(&contexts[prev_pass], queue_flags, prev_barriers); |
| 654 | prev_by_subpass_[prev_pass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 655 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 656 | |
| 657 | async_.reserve(subpass_dep.async.size()); |
| 658 | for (const auto async_subpass : subpass_dep.async) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 659 | async_.emplace_back(&contexts[async_subpass]); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 660 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 661 | if (has_barrier_from_external) { |
| 662 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 663 | prev_.emplace_back(external_context, queue_flags, subpass_dep.barrier_from_external); |
| 664 | src_external_ = &prev_.back(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 665 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 666 | if (subpass_dep.barrier_to_external.size()) { |
| 667 | dst_external_ = TrackBack(this, queue_flags, subpass_dep.barrier_to_external); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 668 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 669 | } |
| 670 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 671 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 672 | HazardResult AccessContext::DetectPreviousHazard(AccessAddressType type, const Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 673 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 674 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 675 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 676 | |
| 677 | HazardResult hazard; |
| 678 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 679 | hazard = detector.Detect(prev); |
| 680 | } |
| 681 | return hazard; |
| 682 | } |
| 683 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 684 | template <typename Action> |
| 685 | void AccessContext::ForAll(Action &&action) { |
| 686 | for (const auto address_type : kAddressTypes) { |
| 687 | auto &accesses = GetAccessStateMap(address_type); |
| 688 | for (const auto &access : accesses) { |
| 689 | action(address_type, access); |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 694 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 695 | // the DAG of the contexts (for example subpasses) |
| 696 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 697 | HazardResult AccessContext::DetectHazard(AccessAddressType type, const Detector &detector, const ResourceAccessRange &range, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 698 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 699 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 700 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 701 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 702 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 703 | // so we'll check these first |
| 704 | for (const auto &async_context : async_) { |
| 705 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 706 | if (hazard.hazard) return hazard; |
| 707 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 708 | } |
| 709 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 710 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 711 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 712 | const auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 713 | const auto the_end = accesses.cend(); // End is not invalidated |
| 714 | auto pos = accesses.lower_bound(range); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 715 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 716 | |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 717 | while (pos != the_end && pos->first.begin < range.end) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 718 | // Cover any leading gap, or gap between entries |
| 719 | if (detect_prev) { |
| 720 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 721 | // Cover any leading gap, or gap between entries |
| 722 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 723 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 724 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 725 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 726 | if (hazard.hazard) return hazard; |
| 727 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 728 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 729 | gap.begin = pos->first.end; |
| 730 | } |
| 731 | |
| 732 | hazard = detector.Detect(pos); |
| 733 | if (hazard.hazard) return hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 734 | ++pos; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | if (detect_prev) { |
| 738 | // Detect in the trailing empty as needed |
| 739 | gap.end = range.end; |
| 740 | if (gap.non_empty()) { |
| 741 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 742 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | return hazard; |
| 746 | } |
| 747 | |
| 748 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 749 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 750 | HazardResult AccessContext::DetectAsyncHazard(AccessAddressType type, const Detector &detector, |
| 751 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 752 | auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 753 | auto pos = accesses.lower_bound(range); |
| 754 | const auto the_end = accesses.end(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 755 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 756 | HazardResult hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 757 | while (pos != the_end && pos->first.begin < range.end) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 758 | hazard = detector.DetectAsync(pos, start_tag_); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame] | 759 | if (hazard.hazard) break; |
| 760 | ++pos; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 761 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 762 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 763 | return hazard; |
| 764 | } |
| 765 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 766 | struct ApplySubpassTransitionBarriersAction { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 767 | explicit ApplySubpassTransitionBarriersAction(const std::vector<SyncBarrier> &barriers_) : barriers(barriers_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 768 | void operator()(ResourceAccessState *access) const { |
| 769 | assert(access); |
| 770 | access->ApplyBarriers(barriers, true); |
| 771 | } |
| 772 | const std::vector<SyncBarrier> &barriers; |
| 773 | }; |
| 774 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 775 | struct ApplyTrackbackStackAction { |
| 776 | explicit ApplyTrackbackStackAction(const std::vector<SyncBarrier> &barriers_, |
| 777 | const ResourceAccessStateFunction *previous_barrier_ = nullptr) |
| 778 | : barriers(barriers_), previous_barrier(previous_barrier_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 779 | void operator()(ResourceAccessState *access) const { |
| 780 | assert(access); |
| 781 | assert(!access->HasPendingState()); |
| 782 | access->ApplyBarriers(barriers, false); |
| 783 | access->ApplyPendingBarriers(kCurrentCommandTag); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 784 | if (previous_barrier) { |
| 785 | assert(bool(*previous_barrier)); |
| 786 | (*previous_barrier)(access); |
| 787 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 788 | } |
| 789 | const std::vector<SyncBarrier> &barriers; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 790 | const ResourceAccessStateFunction *previous_barrier; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 791 | }; |
| 792 | |
| 793 | // Splits a single map entry into piece matching the entries in [first, last) the total range over [first, last) must be |
| 794 | // contained with entry. Entry must be an iterator pointing to dest, first and last must be iterators pointing to a |
| 795 | // *different* map from dest. |
| 796 | // Returns the position past the last resolved range -- the entry covering the remainder of entry->first not included in the |
| 797 | // range [first, last) |
| 798 | template <typename BarrierAction> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 799 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 800 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 801 | BarrierAction &barrier_action) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 802 | auto at = entry; |
| 803 | for (auto pos = first; pos != last; ++pos) { |
| 804 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 805 | assert(at->first.includes(pos->first)); |
| 806 | assert(at != dest->end()); |
| 807 | // Trim up at to the same size as the entry to resolve |
| 808 | at = sparse_container::split(at, *dest, pos->first); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 809 | auto access = pos->second; // intentional copy |
| 810 | barrier_action(&access); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 811 | at->second.Resolve(access); |
| 812 | ++at; // Go to the remaining unused section of entry |
| 813 | } |
| 814 | } |
| 815 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 816 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 817 | SyncBarrier merged = {}; |
| 818 | for (const auto &barrier : barriers) { |
| 819 | merged.Merge(barrier); |
| 820 | } |
| 821 | return merged; |
| 822 | } |
| 823 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 824 | template <typename BarrierAction> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 825 | void AccessContext::ResolveAccessRange(AccessAddressType type, const ResourceAccessRange &range, BarrierAction &barrier_action, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 826 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 827 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 828 | if (!range.non_empty()) return; |
| 829 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 830 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 831 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 832 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 833 | if (current->pos_B->valid) { |
| 834 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 835 | auto access = src_pos->second; // intentional copy |
| 836 | barrier_action(&access); |
| 837 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 838 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 839 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 840 | trimmed->second.Resolve(access); |
| 841 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 842 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 843 | 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] | 844 | 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] | 845 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 846 | } else { |
| 847 | // we have to descend to fill this gap |
| 848 | if (recur_to_infill) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 849 | ResourceAccessRange recurrence_range = current_range; |
| 850 | // The current context is empty for the current range, so recur to fill the gap. |
| 851 | // Since we will be recurring back up the DAG, expand the gap descent to cover the full range for which B |
| 852 | // is not valid, to minimize that recurrence |
| 853 | if (current->pos_B.at_end()) { |
| 854 | // Do the remainder here.... |
| 855 | recurrence_range.end = range.end; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 856 | } else { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 857 | // Recur only over the range until B becomes valid (within the limits of range). |
| 858 | 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] | 859 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 860 | ResolvePreviousAccessStack(type, recurrence_range, resolve_map, infill_state, barrier_action); |
| 861 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 862 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 863 | // iterator of the outer while. |
| 864 | |
| 865 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 866 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 867 | // we stepped on the dest map |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 868 | 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] | 869 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 870 | current.seek(seek_to); |
| 871 | } else if (!current->pos_A->valid && infill_state) { |
| 872 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 873 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 874 | 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] | 875 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 876 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 877 | ++current; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 878 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 879 | |
| 880 | // Infill if range goes passed both the current and resolve map prior contents |
| 881 | if (recur_to_infill && (current->range.end < range.end)) { |
| 882 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 883 | ResolvePreviousAccessStack<BarrierAction>(type, trailing_fill_range, resolve_map, infill_state, barrier_action); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 884 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 885 | } |
| 886 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 887 | template <typename BarrierAction> |
| 888 | void AccessContext::ResolvePreviousAccessStack(AccessAddressType type, const ResourceAccessRange &range, |
| 889 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 890 | const BarrierAction &previous_barrier) const { |
| 891 | ResourceAccessStateFunction stacked_barrier(std::ref(previous_barrier)); |
| 892 | ResolvePreviousAccess(type, range, descent_map, infill_state, &stacked_barrier); |
| 893 | } |
| 894 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 895 | void AccessContext::ResolvePreviousAccess(AccessAddressType type, const ResourceAccessRange &range, |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 896 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 897 | const ResourceAccessStateFunction *previous_barrier) const { |
| 898 | if (prev_.size() == 0) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 899 | if (range.non_empty() && infill_state) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 900 | // Fill the empty poritions of descent_map with the default_state with the barrier function applied (iff present) |
| 901 | ResourceAccessState state_copy; |
| 902 | if (previous_barrier) { |
| 903 | assert(bool(*previous_barrier)); |
| 904 | state_copy = *infill_state; |
| 905 | (*previous_barrier)(&state_copy); |
| 906 | infill_state = &state_copy; |
| 907 | } |
| 908 | sparse_container::update_range_value(*descent_map, range, *infill_state, |
| 909 | sparse_container::value_precedence::prefer_dest); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 910 | } |
| 911 | } else { |
| 912 | // Look for something to fill the gap further along. |
| 913 | for (const auto &prev_dep : prev_) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 914 | const ApplyTrackbackStackAction barrier_action(prev_dep.barriers, previous_barrier); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 915 | prev_dep.context->ResolveAccessRange(type, range, barrier_action, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 916 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 917 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 918 | } |
| 919 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 920 | // Non-lazy import of all accesses, WaitEvents needs this. |
| 921 | void AccessContext::ResolvePreviousAccesses() { |
| 922 | ResourceAccessState default_state; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 923 | if (!prev_.size()) return; // If no previous contexts, nothing to do |
| 924 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 925 | for (const auto address_type : kAddressTypes) { |
| 926 | ResolvePreviousAccess(address_type, kFullRange, &GetAccessStateMap(address_type), &default_state); |
| 927 | } |
| 928 | } |
| 929 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 930 | AccessAddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
| 931 | return (image.fragment_encoder->IsLinearImage()) ? AccessAddressType::kLinear : AccessAddressType::kIdealized; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 932 | } |
| 933 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 934 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
| 935 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 936 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE; |
| 937 | return stage_access; |
| 938 | } |
| 939 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
| 940 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 941 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE; |
| 942 | return stage_access; |
| 943 | } |
| 944 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 945 | // Caller must manage returned pointer |
| 946 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 947 | uint32_t subpass, const AttachmentViewGenVector &attachment_views) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 948 | auto *proxy = new AccessContext(context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 949 | proxy->UpdateAttachmentResolveAccess(rp_state, attachment_views, subpass, kCurrentCommandTag); |
| 950 | proxy->UpdateAttachmentStoreAccess(rp_state, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 951 | return proxy; |
| 952 | } |
| 953 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 954 | template <typename BarrierAction> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 955 | void AccessContext::ResolveAccessRange(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 956 | BarrierAction &barrier_action, ResourceAccessRangeMap *descent_map, |
| 957 | const ResourceAccessState *infill_state) const { |
| 958 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 959 | if (!attachment_gen) return; |
| 960 | |
| 961 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 962 | const AccessAddressType address_type = view_gen.GetAddressType(); |
| 963 | for (; range_gen->non_empty(); ++range_gen) { |
| 964 | ResolveAccessRange(address_type, *range_gen, barrier_action, descent_map, infill_state); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 965 | } |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 966 | } |
| 967 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 968 | // 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] | 969 | 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] | 970 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 971 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 972 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 973 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 974 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 975 | // those affects have not been recorded yet. |
| 976 | // |
| 977 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 978 | // to apply and only copy then, if this proves a hot spot. |
| 979 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 980 | TrackBack proxy_track_back; |
| 981 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 982 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 983 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 984 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 985 | |
| 986 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 987 | assert(track_back); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 988 | if (prev_needs_proxy) { |
| 989 | if (!proxy_for_prev) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 990 | proxy_for_prev.reset( |
| 991 | CreateStoreResolveProxyContext(*track_back->context, rp_state, transition.prev_pass, attachment_views)); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 992 | proxy_track_back = *track_back; |
| 993 | proxy_track_back.context = proxy_for_prev.get(); |
| 994 | } |
| 995 | track_back = &proxy_track_back; |
| 996 | } |
| 997 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 998 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 999 | skip |= ex_context.GetSyncState().LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1000 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1001 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 1002 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1003 | string_VkImageLayout(transition.old_layout), |
| 1004 | string_VkImageLayout(transition.new_layout), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1005 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | return skip; |
| 1009 | } |
| 1010 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1011 | 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] | 1012 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1013 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1014 | bool skip = false; |
| 1015 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1016 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1017 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1018 | if (subpass == rp_state.attachment_first_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1019 | const auto &view_gen = attachment_views[i]; |
| 1020 | if (!view_gen.IsValid()) continue; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1021 | const auto &ci = attachment_ci[i]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1022 | |
| 1023 | // Need check in the following way |
| 1024 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 1025 | // vs. transition |
| 1026 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 1027 | // for each aspect loaded. |
| 1028 | |
| 1029 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1030 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1031 | const bool is_color = !(has_depth || has_stencil); |
| 1032 | |
| 1033 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1034 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1035 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1036 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1037 | const char *aspect = nullptr; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1038 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1039 | bool checked_stencil = false; |
| 1040 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1041 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, load_index, SyncOrdering::kColorAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1042 | aspect = "color"; |
| 1043 | } else { |
| 1044 | if (has_depth) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1045 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_index, |
| 1046 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1047 | aspect = "depth"; |
| 1048 | } |
| 1049 | if (!hazard.hazard && has_stencil) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1050 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, stencil_load_index, |
| 1051 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1052 | aspect = "stencil"; |
| 1053 | checked_stencil = true; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | if (hazard.hazard) { |
| 1058 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1059 | const auto &sync_state = ex_context.GetSyncState(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1060 | if (hazard.tag == kCurrentCommandTag) { |
| 1061 | // Hazard vs. ILT |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1062 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1063 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1064 | " aspect %s during load with loadOp %s.", |
| 1065 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string); |
| 1066 | } else { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1067 | skip |= sync_state.LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1068 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1069 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1070 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1071 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | return skip; |
| 1077 | } |
| 1078 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1079 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 1080 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 1081 | // store is part of the same Next/End operation. |
| 1082 | // The latter is handled in layout transistion validation directly |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1083 | 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] | 1084 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1085 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1086 | bool skip = false; |
| 1087 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1088 | |
| 1089 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1090 | if (subpass == rp_state.attachment_last_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1091 | const AttachmentViewGen &view_gen = attachment_views[i]; |
| 1092 | if (!view_gen.IsValid()) continue; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1093 | const auto &ci = attachment_ci[i]; |
| 1094 | |
| 1095 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1096 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 1097 | // sake, we treat DONT_CARE as writing. |
| 1098 | const bool has_depth = FormatHasDepth(ci.format); |
| 1099 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1100 | const bool is_color = !(has_depth || has_stencil); |
| 1101 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1102 | if (!has_stencil && !store_op_stores) continue; |
| 1103 | |
| 1104 | HazardResult hazard; |
| 1105 | const char *aspect = nullptr; |
| 1106 | bool checked_stencil = false; |
| 1107 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1108 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1109 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1110 | aspect = "color"; |
| 1111 | } else { |
| 1112 | 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] | 1113 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1114 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1115 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1116 | aspect = "depth"; |
| 1117 | } |
| 1118 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1119 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1120 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1121 | aspect = "stencil"; |
| 1122 | checked_stencil = true; |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | if (hazard.hazard) { |
| 1127 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 1128 | const char *const store_op_string = string_VkAttachmentStoreOp(checked_stencil ? ci.stencilStoreOp : ci.storeOp); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1129 | skip |= ex_context.GetSyncState().LogError(rp_state.renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1130 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1131 | " %s aspect during store with %s %s. Access info %s", |
| 1132 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1133 | op_type_string, store_op_string, ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | } |
| 1137 | return skip; |
| 1138 | } |
| 1139 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1140 | 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] | 1141 | const VkRect2D &render_area, const AttachmentViewGenVector &attachment_views, |
| 1142 | const char *func_name, uint32_t subpass) const { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1143 | ValidateResolveAction validate_action(rp_state.renderPass(), subpass, *this, ex_context, func_name); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1144 | ResolveOperation(validate_action, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1145 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1146 | } |
| 1147 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1148 | class HazardDetector { |
| 1149 | SyncStageAccessIndex usage_index_; |
| 1150 | |
| 1151 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1152 | 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] | 1153 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1154 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1155 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1156 | explicit HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1157 | }; |
| 1158 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1159 | class HazardDetectorWithOrdering { |
| 1160 | const SyncStageAccessIndex usage_index_; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1161 | const SyncOrdering ordering_rule_; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1162 | |
| 1163 | public: |
| 1164 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1165 | return pos->second.DetectHazard(usage_index_, ordering_rule_); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1166 | } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1167 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1168 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1169 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1170 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, SyncOrdering ordering) : usage_index_(usage), ordering_rule_(ordering) {} |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1171 | }; |
| 1172 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1173 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1174 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1175 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1176 | const auto base_address = ResourceBaseAddress(buffer); |
| 1177 | HazardDetector detector(usage_index); |
| 1178 | return DetectHazard(AccessAddressType::kLinear, detector, (range + base_address), DetectOptions::kDetectAll); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 1179 | } |
| 1180 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1181 | template <typename Detector> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1182 | HazardResult AccessContext::DetectHazard(Detector &detector, const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1183 | DetectOptions options) const { |
| 1184 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1185 | if (!attachment_gen) return HazardResult(); |
| 1186 | |
| 1187 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1188 | const auto address_type = view_gen.GetAddressType(); |
| 1189 | for (; range_gen->non_empty(); ++range_gen) { |
| 1190 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1191 | if (hazard.hazard) return hazard; |
| 1192 | } |
| 1193 | |
| 1194 | return HazardResult(); |
| 1195 | } |
| 1196 | |
| 1197 | template <typename Detector> |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1198 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1199 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1200 | const VkExtent3D &extent, DetectOptions options) const { |
| 1201 | if (!SimpleBinding(image)) return HazardResult(); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1202 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1203 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1204 | base_address); |
| 1205 | const auto address_type = ImageAddressType(image); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1206 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1207 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1208 | if (hazard.hazard) return hazard; |
| 1209 | } |
| 1210 | return HazardResult(); |
| 1211 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1212 | template <typename Detector> |
| 1213 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1214 | const VkImageSubresourceRange &subresource_range, DetectOptions options) const { |
| 1215 | if (!SimpleBinding(image)) return HazardResult(); |
| 1216 | const auto base_address = ResourceBaseAddress(image); |
| 1217 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
| 1218 | const auto address_type = ImageAddressType(image); |
| 1219 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1220 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1221 | if (hazard.hazard) return hazard; |
| 1222 | } |
| 1223 | return HazardResult(); |
| 1224 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1225 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1226 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1227 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1228 | const VkExtent3D &extent) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1229 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1230 | subresource.layerCount}; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1231 | HazardDetector detector(current_usage); |
| 1232 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1236 | const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1237 | HazardDetector detector(current_usage); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1238 | return DetectHazard(detector, image, subresource_range, DetectOptions::kDetectAll); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1239 | } |
| 1240 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1241 | HazardResult AccessContext::DetectHazard(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1242 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) const { |
| 1243 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
| 1244 | return DetectHazard(detector, view_gen, gen_type, DetectOptions::kDetectAll); |
| 1245 | } |
| 1246 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1247 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1248 | const VkImageSubresourceRange &subresource_range, SyncOrdering ordering_rule, |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1249 | const VkOffset3D &offset, const VkExtent3D &extent) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1250 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1251 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1252 | } |
| 1253 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1254 | class BarrierHazardDetector { |
| 1255 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1256 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1257 | SyncStageAccessFlags src_access_scope) |
| 1258 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1259 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1260 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1261 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1262 | } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1263 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1264 | // 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] | 1265 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | private: |
| 1269 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1270 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1271 | SyncStageAccessFlags src_access_scope_; |
| 1272 | }; |
| 1273 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1274 | class EventBarrierHazardDetector { |
| 1275 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1276 | EventBarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1277 | SyncStageAccessFlags src_access_scope, const SyncEventState::ScopeMap &event_scope, |
| 1278 | const ResourceUsageTag &scope_tag) |
| 1279 | : usage_index_(usage_index), |
| 1280 | src_exec_scope_(src_exec_scope), |
| 1281 | src_access_scope_(src_access_scope), |
| 1282 | event_scope_(event_scope), |
| 1283 | scope_pos_(event_scope.cbegin()), |
| 1284 | scope_end_(event_scope.cend()), |
| 1285 | scope_tag_(scope_tag) {} |
| 1286 | |
| 1287 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1288 | // TODO NOTE: This is almost the slowest way to do this... need to intelligently walk this... |
| 1289 | // Need to find a more efficient sync, since we know pos->first is strictly increasing call to call |
| 1290 | // NOTE: "cached_lower_bound_impl" with upgrades could do this. |
| 1291 | if (scope_pos_ == scope_end_) return HazardResult(); |
| 1292 | if (!scope_pos_->first.intersects(pos->first)) { |
| 1293 | event_scope_.lower_bound(pos->first); |
| 1294 | if ((scope_pos_ == scope_end_) || !scope_pos_->first.intersects(pos->first)) return HazardResult(); |
| 1295 | } |
| 1296 | |
| 1297 | // Some portion of this pos is in the event_scope, so check for a barrier hazard |
| 1298 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_, scope_tag_); |
| 1299 | } |
| 1300 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1301 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1302 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
| 1303 | } |
| 1304 | |
| 1305 | private: |
| 1306 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1307 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1308 | SyncStageAccessFlags src_access_scope_; |
| 1309 | const SyncEventState::ScopeMap &event_scope_; |
| 1310 | SyncEventState::ScopeMap::const_iterator scope_pos_; |
| 1311 | SyncEventState::ScopeMap::const_iterator scope_end_; |
| 1312 | const ResourceUsageTag &scope_tag_; |
| 1313 | }; |
| 1314 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1315 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1316 | const SyncStageAccessFlags &src_access_scope, |
| 1317 | const VkImageSubresourceRange &subresource_range, |
| 1318 | const SyncEventState &sync_event, DetectOptions options) const { |
| 1319 | // It's not particularly DRY to get the address type in this function as well as lower down, but we have to select the |
| 1320 | // first access scope map to use, and there's no easy way to plumb it in below. |
| 1321 | const auto address_type = ImageAddressType(image); |
| 1322 | const auto &event_scope = sync_event.FirstScope(address_type); |
| 1323 | |
| 1324 | EventBarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope, |
| 1325 | event_scope, sync_event.first_scope_tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1326 | return DetectHazard(detector, image, subresource_range, options); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1329 | HazardResult AccessContext::DetectImageBarrierHazard(const AttachmentViewGen &view_gen, const SyncBarrier &barrier, |
| 1330 | DetectOptions options) const { |
| 1331 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, barrier.src_exec_scope.exec_scope, |
| 1332 | barrier.src_access_scope); |
| 1333 | return DetectHazard(detector, view_gen, AttachmentViewGen::Gen::kViewSubresource, options); |
| 1334 | } |
| 1335 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1336 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1337 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1338 | const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1339 | const DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1340 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1341 | return DetectHazard(detector, image, subresource_range, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1344 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1345 | const SyncStageAccessFlags &src_stage_accesses, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1346 | const VkImageMemoryBarrier &barrier) const { |
| 1347 | auto subresource_range = NormalizeSubresourceRange(image.createInfo, barrier.subresourceRange); |
| 1348 | const auto src_access_scope = SyncStageAccess::AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 1349 | return DetectImageBarrierHazard(image, src_exec_scope, src_access_scope, subresource_range, kDetectAll); |
| 1350 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1351 | HazardResult AccessContext::DetectImageBarrierHazard(const SyncImageMemoryBarrier &image_barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1352 | return DetectImageBarrierHazard(*image_barrier.image.get(), image_barrier.barrier.src_exec_scope.exec_scope, |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1353 | image_barrier.barrier.src_access_scope, image_barrier.range, kDetectAll); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1354 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1355 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1356 | template <typename Flags, typename Map> |
| 1357 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1358 | SyncStageAccessFlags scope = 0; |
| 1359 | for (const auto &bit_scope : map) { |
| 1360 | if (flag_mask < bit_scope.first) break; |
| 1361 | |
| 1362 | if (flag_mask & bit_scope.first) { |
| 1363 | scope |= bit_scope.second; |
| 1364 | } |
| 1365 | } |
| 1366 | return scope; |
| 1367 | } |
| 1368 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1369 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags2KHR stages) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1370 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1371 | } |
| 1372 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1373 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags2KHR accesses) { |
| 1374 | return AccessScopeImpl(sync_utils::ExpandAccessFlags(accesses), syncStageAccessMaskByAccessBit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1375 | } |
| 1376 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1377 | // Getting from stage mask and access mask to stage/access masks is something we need to be good at... |
| 1378 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags2KHR stages, VkAccessFlags2KHR accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1379 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1380 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1381 | // 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] | 1382 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1383 | } |
| 1384 | |
| 1385 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1386 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1387 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1388 | // that do incrementalupdates |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1389 | assert(accesses); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1390 | auto pos = accesses->lower_bound(range); |
| 1391 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1392 | // The range is empty, fill it with a default value. |
| 1393 | pos = action.Infill(accesses, pos, range); |
| 1394 | } else if (range.begin < pos->first.begin) { |
| 1395 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1396 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1397 | } else if (pos->first.begin < range.begin) { |
| 1398 | // Trim the beginning if needed |
| 1399 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1400 | ++pos; |
| 1401 | } |
| 1402 | |
| 1403 | const auto the_end = accesses->end(); |
| 1404 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1405 | if (pos->first.end > range.end) { |
| 1406 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1407 | } |
| 1408 | |
| 1409 | pos = action(accesses, pos); |
| 1410 | if (pos == the_end) break; |
| 1411 | |
| 1412 | auto next = pos; |
| 1413 | ++next; |
| 1414 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1415 | // Need to infill if next is disjoint |
| 1416 | 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] | 1417 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1418 | next = action.Infill(accesses, next, new_range); |
| 1419 | } |
| 1420 | pos = next; |
| 1421 | } |
| 1422 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1423 | |
| 1424 | // Give a comparable interface for range generators and ranges |
| 1425 | template <typename Action> |
| 1426 | inline void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, ResourceAccessRange *range) { |
| 1427 | assert(range); |
| 1428 | UpdateMemoryAccessState(accesses, *range, action); |
| 1429 | } |
| 1430 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1431 | template <typename Action, typename RangeGen> |
| 1432 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, RangeGen *range_gen_arg) { |
| 1433 | assert(range_gen_arg); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1434 | 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] | 1435 | for (; range_gen->non_empty(); ++range_gen) { |
| 1436 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1437 | } |
| 1438 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1439 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1440 | template <typename Action, typename RangeGen> |
| 1441 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, const RangeGen &range_gen_prebuilt) { |
| 1442 | RangeGen range_gen(range_gen_prebuilt); // RangeGenerators can be expensive to create from scratch... initialize from built |
| 1443 | for (; range_gen->non_empty(); ++range_gen) { |
| 1444 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1445 | } |
| 1446 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1447 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1448 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1449 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1450 | // this is only called on gaps, and never returns a gap. |
| 1451 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1452 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1453 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1454 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1455 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1456 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1457 | auto &access_state = pos->second; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1458 | access_state.Update(usage, ordering_rule, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1459 | return pos; |
| 1460 | } |
| 1461 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1462 | UpdateMemoryAccessStateFunctor(AccessAddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1463 | SyncOrdering ordering_rule_, const ResourceUsageTag &tag_) |
| 1464 | : type(type_), context(context_), usage(usage_), ordering_rule(ordering_rule_), tag(tag_) {} |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1465 | const AccessAddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1466 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1467 | const SyncStageAccessIndex usage; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1468 | const SyncOrdering ordering_rule; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1469 | const ResourceUsageTag &tag; |
| 1470 | }; |
| 1471 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1472 | // The barrier operation for pipeline and subpass dependencies` |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1473 | struct PipelineBarrierOp { |
| 1474 | SyncBarrier barrier; |
| 1475 | bool layout_transition; |
| 1476 | PipelineBarrierOp(const SyncBarrier &barrier_, bool layout_transition_) |
| 1477 | : barrier(barrier_), layout_transition(layout_transition_) {} |
| 1478 | PipelineBarrierOp() = default; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1479 | PipelineBarrierOp(const PipelineBarrierOp &) = default; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1480 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(barrier, layout_transition); } |
| 1481 | }; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1482 | // The barrier operation for wait events |
| 1483 | struct WaitEventBarrierOp { |
| 1484 | const ResourceUsageTag *scope_tag; |
| 1485 | SyncBarrier barrier; |
| 1486 | bool layout_transition; |
| 1487 | WaitEventBarrierOp(const ResourceUsageTag &scope_tag_, const SyncBarrier &barrier_, bool layout_transition_) |
| 1488 | : scope_tag(&scope_tag_), barrier(barrier_), layout_transition(layout_transition_) {} |
| 1489 | WaitEventBarrierOp() = default; |
| 1490 | void operator()(ResourceAccessState *access_state) const { |
| 1491 | assert(scope_tag); // Not valid to have a non-scope op executed, default construct included for std::vector support |
| 1492 | access_state->ApplyBarrier(*scope_tag, barrier, layout_transition); |
| 1493 | } |
| 1494 | }; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1495 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1496 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1497 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1498 | // of a collection is known/present. |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1499 | template <typename BarrierOp> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1500 | class ApplyBarrierOpsFunctor { |
| 1501 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1502 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1503 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1504 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1505 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1506 | auto &access_state = pos->second; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1507 | for (const auto &op : barrier_ops_) { |
| 1508 | op(&access_state); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1509 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1510 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1511 | if (resolve_) { |
| 1512 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1513 | // another walk |
| 1514 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1515 | } |
| 1516 | return pos; |
| 1517 | } |
| 1518 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1519 | // 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] | 1520 | ApplyBarrierOpsFunctor(bool resolve, size_t size_hint, const ResourceUsageTag &tag) |
| 1521 | : resolve_(resolve), barrier_ops_(), tag_(tag) { |
| 1522 | barrier_ops_.reserve(size_hint); |
| 1523 | } |
| 1524 | void EmplaceBack(const BarrierOp &op) { barrier_ops_.emplace_back(op); } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1525 | |
| 1526 | private: |
| 1527 | bool resolve_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1528 | std::vector<BarrierOp> barrier_ops_; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1529 | const ResourceUsageTag &tag_; |
| 1530 | }; |
| 1531 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1532 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1533 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1534 | template <typename BarrierOp> |
| 1535 | class ApplyBarrierFunctor { |
| 1536 | public: |
| 1537 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1538 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
| 1539 | |
| 1540 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
| 1541 | auto &access_state = pos->second; |
| 1542 | barrier_op_(&access_state); |
| 1543 | return pos; |
| 1544 | } |
| 1545 | |
| 1546 | ApplyBarrierFunctor(const BarrierOp &barrier_op) : barrier_op_(barrier_op) {} |
| 1547 | |
| 1548 | private: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1549 | BarrierOp barrier_op_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1550 | }; |
| 1551 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1552 | // This functor resolves the pendinging state. |
| 1553 | class ResolvePendingBarrierFunctor { |
| 1554 | public: |
| 1555 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1556 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
| 1557 | |
| 1558 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
| 1559 | auto &access_state = pos->second; |
| 1560 | access_state.ApplyPendingBarriers(tag_); |
| 1561 | return pos; |
| 1562 | } |
| 1563 | |
| 1564 | ResolvePendingBarrierFunctor(const ResourceUsageTag &tag) : tag_(tag) {} |
| 1565 | |
| 1566 | private: |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1567 | const ResourceUsageTag &tag_; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1568 | }; |
| 1569 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1570 | void AccessContext::UpdateAccessState(AccessAddressType type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
| 1571 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
| 1572 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1573 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1574 | } |
| 1575 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1576 | 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] | 1577 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1578 | if (!SimpleBinding(buffer)) return; |
| 1579 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1580 | UpdateAccessState(AccessAddressType::kLinear, current_usage, ordering_rule, range + base_address, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1581 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1582 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1583 | void AccessContext::UpdateAccessState(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1584 | const VkImageSubresourceRange &subresource_range, const ResourceUsageTag &tag) { |
| 1585 | if (!SimpleBinding(image)) return; |
| 1586 | const auto base_address = ResourceBaseAddress(image); |
| 1587 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
| 1588 | const auto address_type = ImageAddressType(image); |
| 1589 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1590 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
| 1591 | } |
| 1592 | 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] | 1593 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1594 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1595 | if (!SimpleBinding(image)) return; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1596 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1597 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1598 | base_address); |
| 1599 | const auto address_type = ImageAddressType(image); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1600 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1601 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1602 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1603 | |
| 1604 | void AccessContext::UpdateAccessState(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1605 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, const ResourceUsageTag &tag) { |
| 1606 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1607 | if (!gen) return; |
| 1608 | subresource_adapter::ImageRangeGenerator range_gen(*gen); |
| 1609 | const auto address_type = view_gen.GetAddressType(); |
| 1610 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1611 | ApplyUpdateAction(address_type, action, &range_gen); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1612 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1613 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1614 | 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] | 1615 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1616 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1617 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1618 | subresource.layerCount}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1619 | UpdateAccessState(image, current_usage, ordering_rule, subresource_range, offset, extent, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1620 | } |
| 1621 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1622 | template <typename Action, typename RangeGen> |
| 1623 | void AccessContext::ApplyUpdateAction(AccessAddressType address_type, const Action &action, RangeGen *range_gen_arg) { |
| 1624 | assert(range_gen_arg); // Old Google C++ styleguide require non-const object pass by * not &, but this isn't an optional arg. |
| 1625 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, range_gen_arg); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1629 | void AccessContext::ApplyUpdateAction(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, const Action &action) { |
| 1630 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1631 | if (!gen) return; |
| 1632 | UpdateMemoryAccessState(&GetAccessStateMap(view_gen.GetAddressType()), action, *gen); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1633 | } |
| 1634 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1635 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, |
| 1636 | const AttachmentViewGenVector &attachment_views, uint32_t subpass, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1637 | const ResourceUsageTag &tag) { |
| 1638 | UpdateStateResolveAction update(*this, tag); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1639 | ResolveOperation(update, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1640 | } |
| 1641 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1642 | void AccessContext::UpdateAttachmentStoreAccess(const RENDER_PASS_STATE &rp_state, const AttachmentViewGenVector &attachment_views, |
| 1643 | uint32_t subpass, const ResourceUsageTag &tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1644 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1645 | |
| 1646 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1647 | if (rp_state.attachment_last_subpass[i] == subpass) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1648 | const auto &view_gen = attachment_views[i]; |
| 1649 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1650 | |
| 1651 | const auto &ci = attachment_ci[i]; |
| 1652 | const bool has_depth = FormatHasDepth(ci.format); |
| 1653 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1654 | const bool is_color = !(has_depth || has_stencil); |
| 1655 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1656 | |
| 1657 | if (is_color && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1658 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1659 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1660 | } else { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1661 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1662 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1663 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1664 | } |
| 1665 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1666 | if (has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1667 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1668 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | } |
| 1674 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1675 | template <typename Action> |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1676 | void AccessContext::ApplyToContext(const Action &barrier_action) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1677 | // 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] | 1678 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1679 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), kFullRange, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1684 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1685 | auto &context = contexts[subpass_index]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1686 | ApplyTrackbackStackAction barrier_action(context.GetDstExternalTrackBack().barriers); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1687 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1688 | context.ResolveAccessRange(address_type, kFullRange, barrier_action, &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1689 | } |
| 1690 | } |
| 1691 | } |
| 1692 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1693 | // Suitable only for *subpass* access contexts |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1694 | HazardResult AccessContext::DetectSubpassTransitionHazard(const TrackBack &track_back, const AttachmentViewGen &attach_view) const { |
| 1695 | if (!attach_view.IsValid()) return HazardResult(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1696 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1697 | // 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] | 1698 | assert(track_back.context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1699 | |
| 1700 | // 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] | 1701 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1702 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1703 | HazardResult hazard = track_back.context->DetectImageBarrierHazard(attach_view, merged_barrier, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1704 | if (!hazard.hazard) { |
| 1705 | // The Async hazard check is against the current context's async set. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1706 | hazard = DetectImageBarrierHazard(attach_view, merged_barrier, kDetectAsync); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1707 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1708 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1709 | return hazard; |
| 1710 | } |
| 1711 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1712 | void AccessContext::RecordLayoutTransitions(const RENDER_PASS_STATE &rp_state, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1713 | const AttachmentViewGenVector &attachment_views, const ResourceUsageTag &tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1714 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1715 | const ResourceAccessState empty_infill; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1716 | for (const auto &transition : transitions) { |
| 1717 | const auto prev_pass = transition.prev_pass; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1718 | const auto &view_gen = attachment_views[transition.attachment]; |
| 1719 | if (!view_gen.IsValid()) continue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1720 | |
| 1721 | const auto *trackback = GetTrackBackFromSubpass(prev_pass); |
| 1722 | assert(trackback); |
| 1723 | |
| 1724 | // Import the attachments into the current context |
| 1725 | const auto *prev_context = trackback->context; |
| 1726 | assert(prev_context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1727 | const auto address_type = view_gen.GetAddressType(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1728 | auto &target_map = GetAccessStateMap(address_type); |
| 1729 | ApplySubpassTransitionBarriersAction barrier_action(trackback->barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1730 | prev_context->ResolveAccessRange(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action, &target_map, |
| 1731 | &empty_infill); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1732 | } |
| 1733 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1734 | // If there were no transitions skip this global map walk |
| 1735 | if (transitions.size()) { |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1736 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1737 | ApplyToContext(apply_pending_action); |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1738 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1739 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1740 | |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1741 | void CommandBufferAccessContext::ApplyGlobalBarriersToEvents(const SyncExecScope &src, const SyncExecScope &dst) { |
| 1742 | 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] | 1743 | |
| 1744 | auto *events_context = GetCurrentEventsContext(); |
| 1745 | assert(events_context); |
| 1746 | for (auto &event_pair : *events_context) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1747 | assert(event_pair.second); // Shouldn't be storing empty |
| 1748 | auto &sync_event = *event_pair.second; |
| 1749 | // 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] | 1750 | if ((sync_event.barriers & src.exec_scope) || all_commands_bit) { |
| 1751 | sync_event.barriers |= dst.exec_scope; |
| 1752 | sync_event.barriers |= dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1757 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1758 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1759 | const char *func_name) const { |
| 1760 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1761 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1762 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 1763 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1764 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1765 | return skip; |
| 1766 | } |
| 1767 | |
| 1768 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1769 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1770 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1771 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1772 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1773 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1774 | for (const auto &stage_state : pipe->stage_state) { |
| 1775 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->graphicsPipelineCI.pRasterizationState && |
| 1776 | pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1777 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1778 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1779 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1780 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1781 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1782 | set_binding.first.second); |
| 1783 | const auto descriptor_type = binding_it.GetType(); |
| 1784 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1785 | auto array_idx = 0; |
| 1786 | |
| 1787 | if (binding_it.IsVariableDescriptorCount()) { |
| 1788 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1789 | } |
| 1790 | SyncStageAccessIndex sync_index = |
| 1791 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1792 | |
| 1793 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1794 | uint32_t index = i - index_range.start; |
| 1795 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1796 | switch (descriptor->GetClass()) { |
| 1797 | case DescriptorClass::ImageSampler: |
| 1798 | case DescriptorClass::Image: { |
| 1799 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1800 | VkImageLayout image_layout; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1801 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1802 | const auto image_sampler_descriptor = static_cast<const ImageSamplerDescriptor *>(descriptor); |
| 1803 | img_view_state = image_sampler_descriptor->GetImageViewState(); |
| 1804 | image_layout = image_sampler_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1805 | } else { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1806 | const auto image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 1807 | img_view_state = image_descriptor->GetImageViewState(); |
| 1808 | image_layout = image_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1809 | } |
| 1810 | if (!img_view_state) continue; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1811 | HazardResult hazard; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1812 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1813 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1814 | |
| 1815 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1816 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1817 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1818 | // Input attachments are subject to raster ordering rules |
| 1819 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1820 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1821 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1822 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1823 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1824 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1825 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1826 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1827 | img_view_state->image_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1828 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 1829 | ", index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1830 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1831 | sync_state_->report_data->FormatHandle(img_view_state->image_view()).c_str(), |
| 1832 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 1833 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1834 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1835 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1836 | set_binding.first.second, index, FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1837 | } |
| 1838 | break; |
| 1839 | } |
| 1840 | case DescriptorClass::TexelBuffer: { |
| 1841 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1842 | if (!buf_view_state) continue; |
| 1843 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1844 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1845 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1846 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1847 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1848 | buf_view_state->buffer_view(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1849 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1850 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1851 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view()).c_str(), |
| 1852 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 1853 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1854 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1855 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1856 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1857 | } |
| 1858 | break; |
| 1859 | } |
| 1860 | case DescriptorClass::GeneralBuffer: { |
| 1861 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1862 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1863 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1864 | const ResourceAccessRange range = |
| 1865 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1866 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 1867 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1868 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1869 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1870 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1871 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1872 | sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 1873 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer()).c_str(), |
| 1874 | sync_state_->report_data->FormatHandle(pipe->pipeline()).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1875 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1876 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1877 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1878 | } |
| 1879 | break; |
| 1880 | } |
| 1881 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1882 | default: |
| 1883 | break; |
| 1884 | } |
| 1885 | } |
| 1886 | } |
| 1887 | } |
| 1888 | return skip; |
| 1889 | } |
| 1890 | |
| 1891 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1892 | const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1893 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1894 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 1895 | cb_state_->GetCurrentPipelineAndDesriptorSets(pipelineBindPoint, &pipe, &per_sets); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1896 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1897 | return; |
| 1898 | } |
| 1899 | |
| 1900 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1901 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1902 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1903 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1904 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1905 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1906 | for (const auto &stage_state : pipe->stage_state) { |
| 1907 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->graphicsPipelineCI.pRasterizationState && |
| 1908 | pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1909 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1910 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1911 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1912 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1913 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1914 | set_binding.first.second); |
| 1915 | const auto descriptor_type = binding_it.GetType(); |
| 1916 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1917 | auto array_idx = 0; |
| 1918 | |
| 1919 | if (binding_it.IsVariableDescriptorCount()) { |
| 1920 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1921 | } |
| 1922 | SyncStageAccessIndex sync_index = |
| 1923 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1924 | |
| 1925 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1926 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1927 | switch (descriptor->GetClass()) { |
| 1928 | case DescriptorClass::ImageSampler: |
| 1929 | case DescriptorClass::Image: { |
| 1930 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
| 1931 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
| 1932 | img_view_state = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetImageViewState(); |
| 1933 | } else { |
| 1934 | img_view_state = static_cast<const ImageDescriptor *>(descriptor)->GetImageViewState(); |
| 1935 | } |
| 1936 | if (!img_view_state) continue; |
| 1937 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1938 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1939 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1940 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1941 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kRaster, |
| 1942 | img_view_state->normalized_subresource_range, offset, extent, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1943 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1944 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kNonAttachment, |
| 1945 | img_view_state->normalized_subresource_range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1946 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1947 | break; |
| 1948 | } |
| 1949 | case DescriptorClass::TexelBuffer: { |
| 1950 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1951 | if (!buf_view_state) continue; |
| 1952 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1953 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1954 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1955 | break; |
| 1956 | } |
| 1957 | case DescriptorClass::GeneralBuffer: { |
| 1958 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1959 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1960 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1961 | const ResourceAccessRange range = |
| 1962 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1963 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1964 | break; |
| 1965 | } |
| 1966 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1967 | default: |
| 1968 | break; |
| 1969 | } |
| 1970 | } |
| 1971 | } |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const char *func_name) const { |
| 1976 | bool skip = false; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 1977 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1978 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1979 | return skip; |
| 1980 | } |
| 1981 | |
| 1982 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 1983 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1984 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1985 | |
| 1986 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1987 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1988 | if (binding_description.binding < binding_buffers_size) { |
| 1989 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1990 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1991 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 1992 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1993 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 1994 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1995 | 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] | 1996 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1997 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1998 | buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for vertex %s in %s. Access info %s.", |
| 1999 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(buf_state->buffer()).c_str(), |
| 2000 | 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] | 2001 | } |
| 2002 | } |
| 2003 | } |
| 2004 | return skip; |
| 2005 | } |
| 2006 | |
| 2007 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag &tag) { |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2008 | const auto *pipe = cb_state_->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2009 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2010 | return; |
| 2011 | } |
| 2012 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2013 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2014 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2015 | |
| 2016 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2017 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2018 | if (binding_description.binding < binding_buffers_size) { |
| 2019 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2020 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->Destroyed()) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2021 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2022 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2023 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2024 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2025 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ, |
| 2026 | SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2027 | } |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const char *func_name) const { |
| 2032 | bool skip = false; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2033 | 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] | 2034 | return skip; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2035 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2036 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2037 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2038 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2039 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2040 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2041 | 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] | 2042 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2043 | skip |= sync_state_->LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2044 | index_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for index %s in %s. Access info %s.", |
| 2045 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(index_buf_state->buffer()).c_str(), |
| 2046 | 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] | 2047 | } |
| 2048 | |
| 2049 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2050 | // We will detect more accurate range in the future. |
| 2051 | skip |= ValidateDrawVertex(UINT32_MAX, 0, func_name); |
| 2052 | return skip; |
| 2053 | } |
| 2054 | |
| 2055 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag &tag) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2056 | 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] | 2057 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2058 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2059 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2060 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2061 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2062 | 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] | 2063 | |
| 2064 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2065 | // We will detect more accurate range in the future. |
| 2066 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 2067 | } |
| 2068 | |
| 2069 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(const char *func_name) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2070 | bool skip = false; |
| 2071 | if (!current_renderpass_context_) return skip; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2072 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(GetExecutionContext(), *cb_state_.get(), func_name); |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2073 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2077 | if (current_renderpass_context_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2078 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), tag); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2079 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2080 | } |
| 2081 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2082 | void CommandBufferAccessContext::RecordBeginRenderPass(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2083 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2084 | const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2085 | // Create an access context the current renderpass. |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2086 | 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] | 2087 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2088 | current_renderpass_context_->RecordBeginRenderPass(tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2089 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2090 | } |
| 2091 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2092 | void CommandBufferAccessContext::RecordNextSubpass(CMD_TYPE command) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2093 | assert(current_renderpass_context_); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2094 | auto prev_tag = NextCommandTag(command); |
| 2095 | auto next_tag = NextSubcommandTag(command); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2096 | current_renderpass_context_->RecordNextSubpass(prev_tag, next_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2097 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
| 2098 | } |
| 2099 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2100 | void CommandBufferAccessContext::RecordEndRenderPass(CMD_TYPE command) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2101 | assert(current_renderpass_context_); |
| 2102 | if (!current_renderpass_context_) return; |
| 2103 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2104 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, NextCommandTag(command)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2105 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2106 | current_renderpass_context_ = nullptr; |
| 2107 | } |
| 2108 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2109 | void CommandBufferAccessContext::RecordDestroyEvent(VkEvent event) { |
| 2110 | // Erase is okay with the key not being |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2111 | const auto *event_state = sync_state_->Get<EVENT_STATE>(event); |
| 2112 | if (event_state) { |
| 2113 | GetCurrentEventsContext()->Destroy(event_state); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2114 | } |
| 2115 | } |
| 2116 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2117 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const CommandExecutionContext &ex_context, const CMD_BUFFER_STATE &cmd, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2118 | const char *func_name) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2119 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2120 | const auto &sync_state = ex_context.GetSyncState(); |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2121 | const auto *pipe = cmd.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2122 | if (!pipe || |
| 2123 | (pipe->graphicsPipelineCI.pRasterizationState && pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2124 | return skip; |
| 2125 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2126 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2127 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2128 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2129 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2130 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2131 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2132 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2133 | if (location >= subpass.colorAttachmentCount || |
| 2134 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2135 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2136 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2137 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2138 | if (!view_gen.IsValid()) continue; |
| 2139 | HazardResult hazard = |
| 2140 | current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2141 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2142 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2143 | const VkImageView view_handle = view_gen.GetViewState()->image_view(); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2144 | skip |= sync_state.LogError(view_handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2145 | "%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] | 2146 | func_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2147 | sync_state.report_data->FormatHandle(view_handle).c_str(), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2148 | sync_state.report_data->FormatHandle(cmd.commandBuffer()).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2149 | location, ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2150 | } |
| 2151 | } |
| 2152 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2153 | |
| 2154 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2155 | // 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] | 2156 | const uint32_t depth_stencil_attachment = |
| 2157 | GetSubpassDepthStencilAttachmentIndex(pipe->graphicsPipelineCI.pDepthStencilState, subpass.pDepthStencilAttachment); |
| 2158 | |
| 2159 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2160 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2161 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2162 | bool depth_write = false, stencil_write = false; |
| 2163 | |
| 2164 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2165 | if (!FormatIsStencilOnly(view_state.create_info.format) && pipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2166 | pipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2167 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2168 | depth_write = true; |
| 2169 | } |
| 2170 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2171 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2172 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2173 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2174 | if (!FormatIsDepthOnly(view_state.create_info.format) && pipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2175 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2176 | stencil_write = true; |
| 2177 | } |
| 2178 | |
| 2179 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2180 | if (depth_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2181 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2182 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2183 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2184 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2185 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2186 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2187 | "%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] | 2188 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2189 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
| 2190 | sync_state.report_data->FormatHandle(cmd.commandBuffer()).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2191 | ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2192 | } |
| 2193 | } |
| 2194 | if (stencil_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2195 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2196 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2197 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2198 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2199 | skip |= sync_state.LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2200 | view_state.image_view(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2201 | "%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] | 2202 | func_name, string_SyncHazard(hazard.hazard), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2203 | sync_state.report_data->FormatHandle(view_state.image_view()).c_str(), |
| 2204 | sync_state.report_data->FormatHandle(cmd.commandBuffer()).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2205 | ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2206 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2207 | } |
| 2208 | } |
| 2209 | return skip; |
| 2210 | } |
| 2211 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2212 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd, const ResourceUsageTag &tag) { |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2213 | const auto *pipe = cmd.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2214 | if (!pipe || |
| 2215 | (pipe->graphicsPipelineCI.pRasterizationState && pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2216 | return; |
| 2217 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2218 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2219 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2220 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2221 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2222 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2223 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2224 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2225 | if (location >= subpass.colorAttachmentCount || |
| 2226 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2227 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2228 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2229 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2230 | current_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2231 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment, |
| 2232 | tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2233 | } |
| 2234 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2235 | |
| 2236 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2237 | // 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] | 2238 | const uint32_t depth_stencil_attachment = |
| 2239 | GetSubpassDepthStencilAttachmentIndex(pipe->graphicsPipelineCI.pDepthStencilState, subpass.pDepthStencilAttachment); |
| 2240 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2241 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2242 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2243 | bool depth_write = false, stencil_write = false; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2244 | const bool has_depth = 0 != (view_state.normalized_subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 2245 | 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] | 2246 | |
| 2247 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2248 | if (has_depth && !FormatIsStencilOnly(view_state.create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2249 | pipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 2250 | pipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2251 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2252 | depth_write = true; |
| 2253 | } |
| 2254 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2255 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2256 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2257 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2258 | if (has_stencil && !FormatIsDepthOnly(view_state.create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2259 | pipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2260 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2261 | stencil_write = true; |
| 2262 | } |
| 2263 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2264 | if (depth_write || stencil_write) { |
| 2265 | const auto ds_gentype = view_gen.GetDepthStencilRenderAreaGenType(depth_write, stencil_write); |
| 2266 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2267 | current_context.UpdateAccessState(view_gen, ds_gentype, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2268 | SyncOrdering::kDepthStencilAttachment, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2269 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2270 | } |
| 2271 | } |
| 2272 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2273 | bool RenderPassAccessContext::ValidateNextSubpass(const CommandExecutionContext &ex_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2274 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2275 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2276 | 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] | 2277 | current_subpass_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2278 | 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] | 2279 | func_name); |
| 2280 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2281 | const auto next_subpass = current_subpass_ + 1; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2282 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2283 | skip |= |
| 2284 | 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] | 2285 | if (!skip) { |
| 2286 | // To avoid complex (and buggy) duplication of the affect of layout transitions on load operations, we'll record them |
| 2287 | // on a copy of the (empty) next context. |
| 2288 | // Note: The resource access map should be empty so hopefully this copy isn't too horrible from a perf POV. |
| 2289 | AccessContext temp_context(next_context); |
| 2290 | temp_context.RecordLayoutTransitions(*rp_state_, next_subpass, attachment_views_, kCurrentCommandTag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2291 | skip |= |
| 2292 | 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] | 2293 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2294 | return skip; |
| 2295 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2296 | bool RenderPassAccessContext::ValidateEndRenderPass(const CommandExecutionContext &ex_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2297 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2298 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2299 | 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] | 2300 | current_subpass_); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2301 | skip |= CurrentContext().ValidateStoreOperation(ex_context, *rp_state_, render_area_, current_subpass_, |
| 2302 | |
| 2303 | attachment_views_, func_name); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2304 | skip |= ValidateFinalSubpassLayoutTransitions(ex_context, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2305 | return skip; |
| 2306 | } |
| 2307 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2308 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy() const { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2309 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, attachment_views_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2310 | } |
| 2311 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2312 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const CommandExecutionContext &ex_context, |
| 2313 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2314 | bool skip = false; |
| 2315 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2316 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2317 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2318 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2319 | // to apply and only copy then, if this proves a hot spot. |
| 2320 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2321 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2322 | // Validate the "finalLayout" transitions to external |
| 2323 | // Get them from where there we're hidding in the extra entry. |
| 2324 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2325 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2326 | const auto &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2327 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
| 2328 | 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] | 2329 | auto *context = trackback.context; |
| 2330 | |
| 2331 | if (transition.prev_pass == current_subpass_) { |
| 2332 | if (!proxy_for_current) { |
| 2333 | // 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] | 2334 | proxy_for_current.reset(CreateStoreResolveProxy()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2335 | } |
| 2336 | context = proxy_for_current.get(); |
| 2337 | } |
| 2338 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2339 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2340 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2341 | auto hazard = context->DetectImageBarrierHazard(view_gen, merged_barrier, AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2342 | if (hazard.hazard) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2343 | skip |= ex_context.GetSyncState().LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2344 | rp_state_->renderPass(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2345 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
| 2346 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 2347 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2348 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2349 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2350 | } |
| 2351 | } |
| 2352 | return skip; |
| 2353 | } |
| 2354 | |
| 2355 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag &tag) { |
| 2356 | // Add layout transitions... |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2357 | subpass_contexts_[current_subpass_].RecordLayoutTransitions(*rp_state_, current_subpass_, attachment_views_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2358 | } |
| 2359 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2360 | void RenderPassAccessContext::RecordLoadOperations(const ResourceUsageTag &tag) { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2361 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2362 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2363 | |
| 2364 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2365 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2366 | const AttachmentViewGen &view_gen = attachment_views_[i]; |
| 2367 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2368 | |
| 2369 | const auto &ci = attachment_ci[i]; |
| 2370 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2371 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2372 | const bool is_color = !(has_depth || has_stencil); |
| 2373 | |
| 2374 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2375 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, ColorLoadUsage(ci.loadOp), |
| 2376 | SyncOrdering::kColorAttachment, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2377 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2378 | if (has_depth) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2379 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2380 | DepthStencilLoadUsage(ci.loadOp), SyncOrdering::kDepthStencilAttachment, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2381 | } |
| 2382 | if (has_stencil) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2383 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2384 | DepthStencilLoadUsage(ci.stencilLoadOp), |
| 2385 | SyncOrdering::kDepthStencilAttachment, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | } |
| 2390 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2391 | AttachmentViewGenVector RenderPassAccessContext::CreateAttachmentViewGen( |
| 2392 | const VkRect2D &render_area, const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
| 2393 | AttachmentViewGenVector view_gens; |
| 2394 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2395 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2396 | view_gens.reserve(attachment_views.size()); |
| 2397 | for (const auto *view : attachment_views) { |
| 2398 | view_gens.emplace_back(view, offset, extent); |
| 2399 | } |
| 2400 | return view_gens; |
| 2401 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2402 | RenderPassAccessContext::RenderPassAccessContext(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2403 | VkQueueFlags queue_flags, |
| 2404 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2405 | const AccessContext *external_context) |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2406 | : 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] | 2407 | // 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] | 2408 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2409 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2410 | 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] | 2411 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2412 | attachment_views_ = CreateAttachmentViewGen(render_area, attachment_views); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2413 | } |
| 2414 | void RenderPassAccessContext::RecordBeginRenderPass(const ResourceUsageTag &tag) { |
| 2415 | assert(0 == current_subpass_); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2416 | subpass_contexts_[current_subpass_].SetStartTag(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2417 | RecordLayoutTransitions(tag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2418 | RecordLoadOperations(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2419 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2420 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2421 | void RenderPassAccessContext::RecordNextSubpass(const ResourceUsageTag &prev_subpass_tag, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2422 | const ResourceUsageTag &next_subpass_tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2423 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2424 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, prev_subpass_tag); |
| 2425 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, prev_subpass_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2426 | |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 2427 | // Move to the next sub-command for the new subpass. The resolve and store are logically part of the previous |
| 2428 | // 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] | 2429 | current_subpass_++; |
| 2430 | assert(current_subpass_ < subpass_contexts_.size()); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2431 | subpass_contexts_[current_subpass_].SetStartTag(next_subpass_tag); |
| 2432 | RecordLayoutTransitions(next_subpass_tag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2433 | RecordLoadOperations(next_subpass_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2434 | } |
| 2435 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2436 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const ResourceUsageTag &tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2437 | // Add the resolve and store accesses |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2438 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, tag); |
| 2439 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2440 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2441 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2442 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2443 | |
| 2444 | // Add the "finalLayout" transitions to external |
| 2445 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2446 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2447 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2448 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2449 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2450 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2451 | const AttachmentViewGen &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2452 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | aa97d8b | 2020-07-14 10:58:13 -0600 | [diff] [blame] | 2453 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2454 | ApplyBarrierOpsFunctor<PipelineBarrierOp> barrier_action(true /* resolve */, last_trackback.barriers.size(), tag); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2455 | for (const auto &barrier : last_trackback.barriers) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2456 | barrier_action.EmplaceBack(PipelineBarrierOp(barrier, true)); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2457 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2458 | external_context->ApplyUpdateAction(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2459 | } |
| 2460 | } |
| 2461 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2462 | SyncExecScope SyncExecScope::MakeSrc(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2463 | SyncExecScope result; |
| 2464 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2465 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2466 | result.exec_scope = sync_utils::WithEarlierPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2467 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2468 | return result; |
| 2469 | } |
| 2470 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2471 | SyncExecScope SyncExecScope::MakeDst(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2472 | SyncExecScope result; |
| 2473 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2474 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2475 | result.exec_scope = sync_utils::WithLaterPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2476 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2477 | return result; |
| 2478 | } |
| 2479 | |
| 2480 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2481 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2482 | src_access_scope = 0; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2483 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2484 | dst_access_scope = 0; |
| 2485 | } |
| 2486 | |
| 2487 | template <typename Barrier> |
| 2488 | SyncBarrier::SyncBarrier(const Barrier &barrier, const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2489 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2490 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2491 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2492 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
| 2493 | } |
| 2494 | |
| 2495 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &subpass) { |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2496 | const auto barrier = lvl_find_in_chain<VkMemoryBarrier2KHR>(subpass.pNext); |
| 2497 | if (barrier) { |
| 2498 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier->srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2499 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2500 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier->srcAccessMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2501 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2502 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier->dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2503 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2504 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier->dstAccessMask); |
| 2505 | |
| 2506 | } else { |
| 2507 | auto src = SyncExecScope::MakeSrc(queue_flags, subpass.srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2508 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2509 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, subpass.srcAccessMask); |
| 2510 | |
| 2511 | auto dst = SyncExecScope::MakeDst(queue_flags, subpass.dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2512 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2513 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, subpass.dstAccessMask); |
| 2514 | } |
| 2515 | } |
| 2516 | |
| 2517 | template <typename Barrier> |
| 2518 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const Barrier &barrier) { |
| 2519 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 2520 | src_exec_scope = src.exec_scope; |
| 2521 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
| 2522 | |
| 2523 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2524 | dst_exec_scope = dst.exec_scope; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2525 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2526 | } |
| 2527 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2528 | // Apply a list of barriers, without resolving pending state, useful for subpass layout transitions |
| 2529 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
| 2530 | for (const auto &barrier : barriers) { |
| 2531 | ApplyBarrier(barrier, layout_transition); |
| 2532 | } |
| 2533 | } |
| 2534 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2535 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2536 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2537 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2538 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, const ResourceUsageTag &tag) { |
| 2539 | 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] | 2540 | assert(pending_write_barriers.none()); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2541 | assert(!pending_write_dep_chain); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2542 | for (const auto &barrier : barriers) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2543 | ApplyBarrier(barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2544 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2545 | ApplyPendingBarriers(tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2546 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2547 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2548 | HazardResult hazard; |
| 2549 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2550 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2551 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2552 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2553 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2554 | } |
| 2555 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2556 | // Write operation: |
| 2557 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2558 | // If reads exists -- test only against them because either: |
| 2559 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2560 | // * 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 |
| 2561 | // the current write happens after the reads, so just test the write against the reades |
| 2562 | // Otherwise test against last_write |
| 2563 | // |
| 2564 | // Look for casus belli for WAR |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2565 | if (last_reads.size()) { |
| 2566 | for (const auto &read_access : last_reads) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2567 | if (IsReadHazard(usage_stage, read_access)) { |
| 2568 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2569 | break; |
| 2570 | } |
| 2571 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2572 | } else if (last_write.any() && IsWriteHazard(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2573 | // Write-After-Write check -- if we have a previous write to test against |
| 2574 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2575 | } |
| 2576 | } |
| 2577 | return hazard; |
| 2578 | } |
| 2579 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2580 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrdering &ordering_rule) const { |
| 2581 | const auto &ordering = GetOrderingRules(ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2582 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 2583 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2584 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2585 | const auto usage_stage = PipelineStageBit(usage_index); |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2586 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
| 2587 | const bool last_write_is_ordered = (last_write & ordering.access_scope).any(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2588 | if (IsRead(usage_bit)) { |
| 2589 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 2590 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 2591 | if (is_raw_hazard) { |
| 2592 | // NOTE: we know last_write is non-zero |
| 2593 | // See if the ordering rules save us from the simple RAW check above |
| 2594 | // First check to see if the current usage is covered by the ordering rules |
| 2595 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 2596 | const bool usage_is_ordered = |
| 2597 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 2598 | if (usage_is_ordered) { |
| 2599 | // Now see of the most recent write (or a subsequent read) are ordered |
| 2600 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(ordering)); |
| 2601 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2602 | } |
| 2603 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2604 | if (is_raw_hazard) { |
| 2605 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 2606 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2607 | } else { |
| 2608 | // Only check for WAW if there are no reads since last_write |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2609 | bool usage_write_is_ordered = (usage_bit & ordering.access_scope).any(); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2610 | if (last_reads.size()) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2611 | // Look for any WAR hazards outside the ordered set of stages |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2612 | VkPipelineStageFlags2KHR ordered_stages = 0; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2613 | if (usage_write_is_ordered) { |
| 2614 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
| 2615 | ordered_stages = GetOrderedStages(ordering); |
| 2616 | } |
| 2617 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 2618 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2619 | for (const auto &read_access : last_reads) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2620 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 2621 | if (IsReadHazard(usage_stage, read_access)) { |
| 2622 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2623 | break; |
| 2624 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2625 | } |
| 2626 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2627 | } else if (!(last_write_is_ordered && usage_write_is_ordered)) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2628 | if (last_write.any() && IsWriteHazard(usage_bit)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2629 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2630 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2631 | } |
| 2632 | } |
| 2633 | return hazard; |
| 2634 | } |
| 2635 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2636 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2637 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index, const ResourceUsageTag &start_tag) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2638 | HazardResult hazard; |
| 2639 | auto usage = FlagBit(usage_index); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2640 | // Async checks need to not go back further than the start of the subpass, as we only want to find hazards between the async |
| 2641 | // subpasses. Anything older than that should have been checked at the start of each subpass, taking into account all of |
| 2642 | // the raster ordering rules. |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2643 | if (IsRead(usage)) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2644 | if (last_write.any() && (write_tag.index >= start_tag.index)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2645 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2646 | } |
| 2647 | } else { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2648 | if (last_write.any() && (write_tag.index >= start_tag.index)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2649 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2650 | } else if (last_reads.size() > 0) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2651 | // 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] | 2652 | for (const auto &read_access : last_reads) { |
| 2653 | if (read_access.tag.index >= start_tag.index) { |
| 2654 | 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] | 2655 | break; |
| 2656 | } |
| 2657 | } |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2658 | } |
| 2659 | } |
| 2660 | return hazard; |
| 2661 | } |
| 2662 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2663 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2664 | const SyncStageAccessFlags &src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2665 | // Only supporting image layout transitions for now |
| 2666 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2667 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2668 | // only test for WAW if there no intervening read operations. |
| 2669 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2670 | if (last_reads.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2671 | // Look at the reads if any |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2672 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2673 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2674 | 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] | 2675 | break; |
| 2676 | } |
| 2677 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2678 | } else if (last_write.any() && IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2679 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2680 | } |
| 2681 | |
| 2682 | return hazard; |
| 2683 | } |
| 2684 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2685 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2686 | const SyncStageAccessFlags &src_access_scope, |
| 2687 | const ResourceUsageTag &event_tag) const { |
| 2688 | // Only supporting image layout transitions for now |
| 2689 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2690 | HazardResult hazard; |
| 2691 | // only test for WAW if there no intervening read operations. |
| 2692 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 2693 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2694 | if (last_reads.size()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2695 | // Look at the reads if any... if reads exist, they are either the resaon the access is in the event |
| 2696 | // first scope, or they are a hazard. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2697 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2698 | if (read_access.tag.IsBefore(event_tag)) { |
| 2699 | // The read is in the events first synchronization scope, so we use a barrier hazard check |
| 2700 | // If the read stage is not in the src sync scope |
| 2701 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 2702 | // then the barrier access is unsafe (R/W after R) |
| 2703 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
| 2704 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2705 | break; |
| 2706 | } |
| 2707 | } else { |
| 2708 | // The read not in the event first sync scope and so is a hazard vs. the layout transition |
| 2709 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2710 | } |
| 2711 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2712 | } else if (last_write.any()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2713 | // if there are no reads, the write is either the reason the access is in the event scope... they are a hazard |
| 2714 | if (write_tag.IsBefore(event_tag)) { |
| 2715 | // The write is in the first sync scope of the event (sync their aren't any reads to be the reason) |
| 2716 | // So do a normal barrier hazard check |
| 2717 | if (IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2718 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2719 | } |
| 2720 | } else { |
| 2721 | // 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] | 2722 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2723 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2724 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2725 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2726 | return hazard; |
| 2727 | } |
| 2728 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2729 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 2730 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 2731 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 2732 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
| 2733 | if (write_tag.IsBefore(other.write_tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2734 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 2735 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2736 | *this = other; |
| 2737 | } else if (!other.write_tag.IsBefore(write_tag)) { |
| 2738 | // This is the *equals* case for write operations, we merged the write barriers and the read state (but without the |
| 2739 | // dependency chaining logic or any stage expansion) |
| 2740 | write_barriers |= other.write_barriers; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2741 | pending_write_barriers |= other.pending_write_barriers; |
| 2742 | pending_layout_transition |= other.pending_layout_transition; |
| 2743 | pending_write_dep_chain |= other.pending_write_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2744 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2745 | // Merge the read states |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2746 | const auto pre_merge_count = last_reads.size(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2747 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2748 | 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] | 2749 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2750 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2751 | // 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] | 2752 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 2753 | // but we should wait on profiling data for that. |
| 2754 | 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] | 2755 | auto &my_read = last_reads[my_read_index]; |
| 2756 | if (other_read.stage == my_read.stage) { |
| 2757 | if (my_read.tag.IsBefore(other_read.tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2758 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2759 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2760 | my_read.tag = other_read.tag; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2761 | my_read.pending_dep_chain = other_read.pending_dep_chain; |
| 2762 | // TODO: Phase 2 -- review the state merge logic to avoid false positive from overwriting the barriers |
| 2763 | // May require tracking more than one access per stage. |
| 2764 | my_read.barriers = other_read.barriers; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2765 | if (my_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2766 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 2767 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2768 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2769 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2770 | } else if (other_read.tag.IsBefore(my_read.tag)) { |
| 2771 | // The read tags match so merge the barriers |
| 2772 | my_read.barriers |= other_read.barriers; |
| 2773 | my_read.pending_dep_chain |= other_read.pending_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2774 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2775 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2776 | break; |
| 2777 | } |
| 2778 | } |
| 2779 | } else { |
| 2780 | // The other read stage doesn't exist in this, so add it. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2781 | last_reads.emplace_back(other_read); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2782 | last_read_stages |= other_read.stage; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2783 | if (other_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2784 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2785 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2786 | } |
| 2787 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2788 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2789 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 2790 | // ignore it. |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2791 | |
| 2792 | // Merge first access information by making a copy of this first_access and reconstructing with a shuffle |
| 2793 | // of the copy and other into this using the update first logic. |
| 2794 | // NOTE: All sorts of additional cleverness could be put into short circuts. (for example back is write and is before front |
| 2795 | // of the other first_accesses... ) |
| 2796 | if (!(first_accesses_ == other.first_accesses_) && !other.first_accesses_.empty()) { |
| 2797 | FirstAccesses firsts(std::move(first_accesses_)); |
| 2798 | first_accesses_.clear(); |
| 2799 | first_read_stages_ = 0U; |
| 2800 | auto a = firsts.begin(); |
| 2801 | auto a_end = firsts.end(); |
| 2802 | for (auto &b : other.first_accesses_) { |
| 2803 | // TODO: Determine whether "IsBefore" or "IsGloballyBefore" is needed... |
| 2804 | while (a != a_end && a->tag.IsBefore(b.tag)) { |
| 2805 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 2806 | ++a; |
| 2807 | } |
| 2808 | UpdateFirst(b.tag, b.usage_index, b.ordering_rule); |
| 2809 | } |
| 2810 | for (; a != a_end; ++a) { |
| 2811 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 2812 | } |
| 2813 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2814 | } |
| 2815 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2816 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, SyncOrdering ordering_rule, const ResourceUsageTag &tag) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2817 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 2818 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2819 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2820 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 2821 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 2822 | const auto usage_stage = PipelineStageBit(usage_index); |
| 2823 | if (usage_stage & last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2824 | for (auto &read_access : last_reads) { |
| 2825 | if (read_access.stage == usage_stage) { |
| 2826 | read_access.Set(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2827 | break; |
| 2828 | } |
| 2829 | } |
| 2830 | } else { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2831 | last_reads.emplace_back(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2832 | last_read_stages |= usage_stage; |
| 2833 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2834 | |
| 2835 | // 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] | 2836 | if (usage_stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2837 | // TODO Revisit re: multiple reads for a given stage |
| 2838 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2839 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2840 | } else { |
| 2841 | // Assume write |
| 2842 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2843 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2844 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2845 | UpdateFirst(tag, usage_index, ordering_rule); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2846 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2847 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2848 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 2849 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 2850 | // We can overwrite them as *this* write is now after them. |
| 2851 | // |
| 2852 | // 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] | 2853 | void ResourceAccessState::SetWrite(const SyncStageAccessFlags &usage_bit, const ResourceUsageTag &tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2854 | last_reads.clear(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2855 | last_read_stages = 0; |
| 2856 | read_execution_barriers = 0; |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2857 | 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] | 2858 | |
| 2859 | write_barriers = 0; |
| 2860 | write_dependency_chain = 0; |
| 2861 | write_tag = tag; |
| 2862 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2863 | } |
| 2864 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2865 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 2866 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 2867 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 2868 | // replace the current write barriers or add to them, so accumulate to pending as well. |
| 2869 | void ResourceAccessState::ApplyBarrier(const SyncBarrier &barrier, bool layout_transition) { |
| 2870 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 2871 | // applying the memory barriers |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 2872 | // NOTE: We update the write barrier if the write is in the first access scope or if there is a layout |
| 2873 | // transistion, under the theory of "most recent access". If the read/write *isn't* safe |
| 2874 | // vs. this layout transition DetectBarrierHazard should report it. We treat the layout |
| 2875 | // 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] | 2876 | 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] | 2877 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2878 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2879 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2880 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 2881 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2882 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2883 | if (!pending_layout_transition) { |
| 2884 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 2885 | // 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] | 2886 | for (auto &read_access : last_reads) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2887 | // 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] | 2888 | if (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers)) { |
| 2889 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2890 | } |
| 2891 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2892 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2893 | } |
| 2894 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2895 | // Apply the tag scoped memory barrier without updating the existing barriers. The execution barrier |
| 2896 | // changes the "chaining" state, but to keep barriers independent. See discussion above. |
| 2897 | void ResourceAccessState::ApplyBarrier(const ResourceUsageTag &scope_tag, const SyncBarrier &barrier, bool layout_transition) { |
| 2898 | // The scope logic for events is, if we're here, the resource usage was flagged as "in the first execution scope" at |
| 2899 | // the time of the SetEvent, thus all we need check is whether the access is the same one (i.e. before the scope tag |
| 2900 | // in order to know if it's in the excecution scope |
| 2901 | // Notice that the layout transition sets the pending barriers *regardless*, as any lack of src_access_scope to |
| 2902 | // guard against the layout transition should be reported in the detect barrier hazard phase, and we only report |
| 2903 | // errors w.r.t. "most recent" accesses. |
| 2904 | if (layout_transition || ((write_tag.IsBefore(scope_tag)) && (barrier.src_access_scope & last_write).any())) { |
| 2905 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2906 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2907 | } |
| 2908 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 2909 | pending_layout_transition |= layout_transition; |
| 2910 | |
| 2911 | if (!pending_layout_transition) { |
| 2912 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 2913 | // 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] | 2914 | for (auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2915 | // If this read is the same one we included in the set event and in scope, then apply the execution barrier... |
| 2916 | // NOTE: That's not really correct... this read stage might *not* have been included in the setevent, and the barriers |
| 2917 | // representing the chain might have changed since then (that would be an odd usage), so as a first approximation |
| 2918 | // we'll assume the barriers *haven't* been changed since (if the tag hasn't), and while this could be a false |
| 2919 | // positive in the case of Set; SomeBarrier; Wait; we'll live with it until we can add more state to the first scope |
| 2920 | // capture (the specific write and read stages that *were* in scope at the moment of SetEvents. |
| 2921 | // 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] | 2922 | if (read_access.tag.IsBefore(scope_tag) && |
| 2923 | (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers))) { |
| 2924 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2925 | } |
| 2926 | } |
| 2927 | } |
| 2928 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2929 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag &tag) { |
| 2930 | if (pending_layout_transition) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2931 | // SetWrite clobbers the read count, and thus we don't have to clear the read_state out. |
| 2932 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2933 | UpdateFirst(tag, SYNC_IMAGE_LAYOUT_TRANSITION, SyncOrdering::kNonAttachment); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2934 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2935 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2936 | |
| 2937 | // Apply the accumulate execution barriers (and thus update chaining information) |
| 2938 | // 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] | 2939 | for (auto &read_access : last_reads) { |
| 2940 | read_access.barriers |= read_access.pending_dep_chain; |
| 2941 | read_execution_barriers |= read_access.barriers; |
| 2942 | read_access.pending_dep_chain = 0; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 2946 | write_dependency_chain |= pending_write_dep_chain; |
| 2947 | write_barriers |= pending_write_barriers; |
| 2948 | pending_write_dep_chain = 0; |
| 2949 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2950 | } |
| 2951 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2952 | // 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] | 2953 | VkPipelineStageFlags2KHR ResourceAccessState::GetReadBarriers(const SyncStageAccessFlags &usage_bit) const { |
| 2954 | VkPipelineStageFlags2KHR barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2955 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2956 | for (const auto &read_access : last_reads) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2957 | if ((read_access.access & usage_bit).any()) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2958 | barriers = read_access.barriers; |
| 2959 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2960 | } |
| 2961 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2962 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2963 | return barriers; |
| 2964 | } |
| 2965 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2966 | inline bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlags2KHR usage_stage, const SyncStageAccessFlags &usage) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2967 | assert(IsRead(usage)); |
| 2968 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 2969 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 2970 | // any reads that happen after. |
| 2971 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 2972 | // 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] | 2973 | return last_write.any() && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2974 | } |
| 2975 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2976 | VkPipelineStageFlags2KHR ResourceAccessState::GetOrderedStages(const OrderingBarrier &ordering) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2977 | // 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] | 2978 | VkPipelineStageFlags2KHR ordered_stages = last_read_stages & ordering.exec_scope; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2979 | // Special input attachment handling as always (not encoded in exec_scop) |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2980 | 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] | 2981 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2982 | // 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] | 2983 | ordered_stages |= VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | return ordered_stages; |
| 2987 | } |
| 2988 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2989 | void ResourceAccessState::UpdateFirst(const ResourceUsageTag &tag, SyncStageAccessIndex usage_index, SyncOrdering ordering_rule) { |
| 2990 | // Only record until we record a write. |
| 2991 | if (first_accesses_.empty() || IsRead(first_accesses_.back().usage_index)) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2992 | const VkPipelineStageFlags2KHR usage_stage = IsRead(usage_index) ? PipelineStageBit(usage_index) : 0U; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2993 | if (0 == (usage_stage & first_read_stages_)) { |
| 2994 | // If this is a read we haven't seen or a write, record. |
| 2995 | first_read_stages_ |= usage_stage; |
| 2996 | first_accesses_.emplace_back(tag, usage_index, ordering_rule); |
| 2997 | } |
| 2998 | } |
| 2999 | } |
| 3000 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3001 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3002 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 3003 | if (access_context) { |
| 3004 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3008 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 3009 | auto access_found = cb_access_state.find(command_buffer); |
| 3010 | if (access_found != cb_access_state.end()) { |
| 3011 | access_found->second->Reset(); |
| 3012 | cb_access_state.erase(access_found); |
| 3013 | } |
| 3014 | } |
| 3015 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3016 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3017 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 3018 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3019 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3020 | assert(cb_context); |
| 3021 | if (!cb_context) return skip; |
| 3022 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3023 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3024 | // If we have no previous accesses, we have no hazards |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3025 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3026 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3027 | |
| 3028 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3029 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3030 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3031 | 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] | 3032 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3033 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3034 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3035 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3036 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3037 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3038 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3039 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3040 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3041 | 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] | 3042 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3043 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3044 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3045 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3046 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3047 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3048 | } |
| 3049 | } |
| 3050 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3051 | } |
| 3052 | return skip; |
| 3053 | } |
| 3054 | |
| 3055 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3056 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3057 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3058 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3059 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3060 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3061 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3062 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3063 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3064 | |
| 3065 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3066 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3067 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3068 | 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] | 3069 | 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] | 3070 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3071 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3072 | 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] | 3073 | 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] | 3074 | } |
| 3075 | } |
| 3076 | } |
| 3077 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3078 | void SyncValidator::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 3079 | // Clear out events from the command buffer contexts |
| 3080 | for (auto &cb_context : cb_access_state) { |
| 3081 | cb_context.second->RecordDestroyEvent(event); |
| 3082 | } |
| 3083 | } |
| 3084 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3085 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3086 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 3087 | bool skip = false; |
| 3088 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3089 | assert(cb_context); |
| 3090 | if (!cb_context) return skip; |
| 3091 | const auto *context = cb_context->GetCurrentAccessContext(); |
| 3092 | |
| 3093 | // If we have no previous accesses, we have no hazards |
| 3094 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3095 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3096 | |
| 3097 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3098 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3099 | if (src_buffer) { |
| 3100 | 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] | 3101 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3102 | if (hazard.hazard) { |
| 3103 | // TODO -- add tag information to log msg when useful. |
| 3104 | skip |= LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3105 | "vkCmdCopyBuffer2KHR(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3106 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3107 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3108 | } |
| 3109 | } |
| 3110 | if (dst_buffer && !skip) { |
| 3111 | 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] | 3112 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3113 | if (hazard.hazard) { |
| 3114 | skip |= LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3115 | "vkCmdCopyBuffer2KHR(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3116 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3117 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3118 | } |
| 3119 | } |
| 3120 | if (skip) break; |
| 3121 | } |
| 3122 | return skip; |
| 3123 | } |
| 3124 | |
| 3125 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 3126 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3127 | assert(cb_context); |
| 3128 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER2KHR); |
| 3129 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3130 | |
| 3131 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3132 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3133 | |
| 3134 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3135 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3136 | if (src_buffer) { |
| 3137 | 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] | 3138 | 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] | 3139 | } |
| 3140 | if (dst_buffer) { |
| 3141 | 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] | 3142 | 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] | 3143 | } |
| 3144 | } |
| 3145 | } |
| 3146 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3147 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3148 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3149 | const VkImageCopy *pRegions) const { |
| 3150 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3151 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3152 | assert(cb_access_context); |
| 3153 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3154 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3155 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3156 | assert(context); |
| 3157 | if (!context) return skip; |
| 3158 | |
| 3159 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3160 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3161 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3162 | const auto ©_region = pRegions[region]; |
| 3163 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3164 | 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] | 3165 | copy_region.srcOffset, copy_region.extent); |
| 3166 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3167 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3168 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3169 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3170 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3171 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3175 | VkExtent3D dst_copy_extent = |
| 3176 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3177 | 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] | 3178 | copy_region.dstOffset, dst_copy_extent); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3179 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3180 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3181 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3182 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3183 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3184 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 3185 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3186 | } |
| 3187 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3188 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3189 | return skip; |
| 3190 | } |
| 3191 | |
| 3192 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3193 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3194 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3195 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3196 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3197 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3198 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3199 | assert(context); |
| 3200 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3201 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3202 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3203 | |
| 3204 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3205 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3206 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3207 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3208 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3209 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3210 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3211 | VkExtent3D dst_copy_extent = |
| 3212 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3213 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3214 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3215 | } |
| 3216 | } |
| 3217 | } |
| 3218 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3219 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 3220 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 3221 | bool skip = false; |
| 3222 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3223 | assert(cb_access_context); |
| 3224 | if (!cb_access_context) return skip; |
| 3225 | |
| 3226 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3227 | assert(context); |
| 3228 | if (!context) return skip; |
| 3229 | |
| 3230 | const auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3231 | const auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3232 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3233 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3234 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3235 | 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] | 3236 | copy_region.srcOffset, copy_region.extent); |
| 3237 | if (hazard.hazard) { |
| 3238 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 3239 | "vkCmdCopyImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 3240 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3241 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | if (dst_image) { |
| 3246 | VkExtent3D dst_copy_extent = |
| 3247 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3248 | 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] | 3249 | copy_region.dstOffset, dst_copy_extent); |
| 3250 | if (hazard.hazard) { |
| 3251 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 3252 | "vkCmdCopyImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 3253 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3254 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3255 | } |
| 3256 | if (skip) break; |
| 3257 | } |
| 3258 | } |
| 3259 | |
| 3260 | return skip; |
| 3261 | } |
| 3262 | |
| 3263 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 3264 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3265 | assert(cb_access_context); |
| 3266 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE2KHR); |
| 3267 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3268 | assert(context); |
| 3269 | |
| 3270 | auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3271 | auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3272 | |
| 3273 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3274 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3275 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3276 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3277 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3278 | } |
| 3279 | if (dst_image) { |
| 3280 | VkExtent3D dst_copy_extent = |
| 3281 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3282 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3283 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3284 | } |
| 3285 | } |
| 3286 | } |
| 3287 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3288 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3289 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3290 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3291 | uint32_t bufferMemoryBarrierCount, |
| 3292 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3293 | uint32_t imageMemoryBarrierCount, |
| 3294 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 3295 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3296 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3297 | assert(cb_access_context); |
| 3298 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3299 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 3300 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 3301 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 3302 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 3303 | pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 3304 | skip = pipeline_barrier.Validate(*cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3305 | return skip; |
| 3306 | } |
| 3307 | |
| 3308 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3309 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3310 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3311 | uint32_t bufferMemoryBarrierCount, |
| 3312 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3313 | uint32_t imageMemoryBarrierCount, |
| 3314 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3315 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3316 | assert(cb_access_context); |
| 3317 | if (!cb_access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3318 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 3319 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 3320 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 3321 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 3322 | pImageMemoryBarriers); |
| 3323 | pipeline_barrier.Record(cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3324 | } |
| 3325 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 3326 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 3327 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 3328 | bool skip = false; |
| 3329 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3330 | assert(cb_access_context); |
| 3331 | if (!cb_access_context) return skip; |
| 3332 | |
| 3333 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3334 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 3335 | return skip; |
| 3336 | } |
| 3337 | |
| 3338 | void SyncValidator::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) { |
| 3339 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3340 | assert(cb_access_context); |
| 3341 | if (!cb_access_context) return; |
| 3342 | |
| 3343 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3344 | pipeline_barrier.Record(cb_access_context); |
| 3345 | } |
| 3346 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3347 | void SyncValidator::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 3348 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result) { |
| 3349 | // The state tracker sets up the device state |
| 3350 | StateTracker::PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, result); |
| 3351 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3352 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 3353 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3354 | // TODO: Find a good way to do this hooklessly. |
| 3355 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 3356 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, LayerObjectTypeSyncValidation); |
| 3357 | SyncValidator *sync_device_state = static_cast<SyncValidator *>(validation_data); |
| 3358 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3359 | sync_device_state->SetCommandBufferResetCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3360 | sync_device_state->ResetCommandBufferCallback(command_buffer); |
| 3361 | }); |
| 3362 | sync_device_state->SetCommandBufferFreeCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3363 | sync_device_state->FreeCommandBufferCallback(command_buffer); |
| 3364 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3365 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3366 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3367 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3368 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd, const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3369 | bool skip = false; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3370 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3371 | if (cb_context) { |
| 3372 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo, cmd_name); |
| 3373 | skip = sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3374 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3375 | return skip; |
| 3376 | } |
| 3377 | |
| 3378 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3379 | VkSubpassContents contents) const { |
| 3380 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3381 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3382 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3383 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3384 | return skip; |
| 3385 | } |
| 3386 | |
| 3387 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3388 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3389 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3390 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3391 | return skip; |
| 3392 | } |
| 3393 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3394 | static const char *kBeginRenderPass2KhrName = "vkCmdBeginRenderPass2KHR"; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3395 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3396 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3397 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3398 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3399 | skip |= |
| 3400 | ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2, kBeginRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3401 | return skip; |
| 3402 | } |
| 3403 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3404 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 3405 | VkResult result) { |
| 3406 | // The state tracker sets up the command buffer state |
| 3407 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 3408 | |
| 3409 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 3410 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 3411 | assert(cb_access_context); |
| 3412 | cb_access_context->Reset(); |
| 3413 | } |
| 3414 | |
| 3415 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3416 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd, const char *cmd_name) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3417 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3418 | if (cb_context) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3419 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo, cmd_name); |
| 3420 | sync_op.Record(cb_context); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3421 | } |
| 3422 | } |
| 3423 | |
| 3424 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3425 | VkSubpassContents contents) { |
| 3426 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3427 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3428 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3429 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3433 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3434 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3435 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3436 | } |
| 3437 | |
| 3438 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3439 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3440 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3441 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3442 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2, kBeginRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3443 | } |
| 3444 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3445 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3446 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3447 | bool skip = false; |
| 3448 | |
| 3449 | auto cb_context = GetAccessContext(commandBuffer); |
| 3450 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3451 | if (!cb_context) return skip; |
| 3452 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo, cmd_name); |
| 3453 | return sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 3457 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3458 | // Convert to a NextSubpass2 |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3459 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3460 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3461 | auto subpass_end_info = LvlInitStruct<VkSubpassEndInfo>(); |
| 3462 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, &subpass_end_info, CMD_NEXTSUBPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3463 | return skip; |
| 3464 | } |
| 3465 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3466 | static const char *kNextSubpass2KhrName = "vkCmdNextSubpass2KHR"; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3467 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3468 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3469 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3470 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2, kNextSubpass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3471 | return skip; |
| 3472 | } |
| 3473 | |
| 3474 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3475 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 3476 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3477 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3478 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3482 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, const char *cmd_name) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3483 | auto cb_context = GetAccessContext(commandBuffer); |
| 3484 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3485 | if (!cb_context) return; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3486 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3487 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo, cmd_name); |
| 3488 | sync_op.Record(cb_context); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 3492 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3493 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3494 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3495 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3499 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3500 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3501 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3505 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3506 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3507 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2, kNextSubpass2KhrName); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3508 | } |
| 3509 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3510 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, |
| 3511 | const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3512 | bool skip = false; |
| 3513 | |
| 3514 | auto cb_context = GetAccessContext(commandBuffer); |
| 3515 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3516 | if (!cb_context) return skip; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3517 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3518 | SyncOpEndRenderPass sync_op(cmd, *this, pSubpassEndInfo, cmd_name); |
| 3519 | skip |= sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3520 | return skip; |
| 3521 | } |
| 3522 | |
| 3523 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 3524 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3525 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3526 | return skip; |
| 3527 | } |
| 3528 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3529 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3530 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3531 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3532 | return skip; |
| 3533 | } |
| 3534 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3535 | const static char *kEndRenderPass2KhrName = "vkEndRenderPass2KHR"; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3536 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3537 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3538 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3539 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2, kEndRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3540 | return skip; |
| 3541 | } |
| 3542 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3543 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, |
| 3544 | const char *cmd_name) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3545 | // Resolve the all subpass contexts to the command buffer contexts |
| 3546 | auto cb_context = GetAccessContext(commandBuffer); |
| 3547 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3548 | if (!cb_context) return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3549 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3550 | SyncOpEndRenderPass sync_op(cmd, *this, pSubpassEndInfo, cmd_name); |
| 3551 | sync_op.Record(cb_context); |
| 3552 | return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3553 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3554 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 3555 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 3556 | // updates to a resource which do not conflict at the byte level. |
| 3557 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 3558 | // TODO: Add programatic control over suppression heuristics |
| 3559 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 3560 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 3561 | } |
| 3562 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3563 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3564 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3565 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3569 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3570 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3574 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2, kEndRenderPass2KhrName); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3575 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3576 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3577 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3578 | template <typename BufferImageCopyRegionType> |
| 3579 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3580 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3581 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3582 | bool skip = false; |
| 3583 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3584 | assert(cb_access_context); |
| 3585 | if (!cb_access_context) return skip; |
| 3586 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3587 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3588 | const char *func_name = is_2khr ? "vkCmdCopyBufferToImage2KHR()" : "vkCmdCopyBufferToImage()"; |
| 3589 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3590 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3591 | assert(context); |
| 3592 | if (!context) return skip; |
| 3593 | |
| 3594 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3595 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3596 | |
| 3597 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3598 | const auto ©_region = pRegions[region]; |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3599 | HazardResult hazard; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3600 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3601 | if (src_buffer) { |
| 3602 | ResourceAccessRange src_range = |
| 3603 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3604 | hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3605 | if (hazard.hazard) { |
| 3606 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 3607 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3608 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3609 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3610 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3611 | } |
| 3612 | } |
| 3613 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3614 | hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.imageSubresource, |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3615 | copy_region.imageOffset, copy_region.imageExtent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3616 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3617 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3618 | "%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] | 3619 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3620 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3621 | } |
| 3622 | if (skip) break; |
| 3623 | } |
| 3624 | if (skip) break; |
| 3625 | } |
| 3626 | return skip; |
| 3627 | } |
| 3628 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3629 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3630 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3631 | const VkBufferImageCopy *pRegions) const { |
| 3632 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
| 3633 | COPY_COMMAND_VERSION_1); |
| 3634 | } |
| 3635 | |
| 3636 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3637 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 3638 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3639 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3640 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3641 | } |
| 3642 | |
| 3643 | template <typename BufferImageCopyRegionType> |
| 3644 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3645 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3646 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3647 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3648 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3649 | |
| 3650 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3651 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYBUFFERTOIMAGE2KHR : CMD_COPYBUFFERTOIMAGE; |
| 3652 | |
| 3653 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3654 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3655 | assert(context); |
| 3656 | |
| 3657 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3658 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3659 | |
| 3660 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3661 | const auto ©_region = pRegions[region]; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3662 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3663 | if (src_buffer) { |
| 3664 | ResourceAccessRange src_range = |
| 3665 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3666 | 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] | 3667 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3668 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3669 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3670 | } |
| 3671 | } |
| 3672 | } |
| 3673 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3674 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3675 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3676 | const VkBufferImageCopy *pRegions) { |
| 3677 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
| 3678 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3679 | } |
| 3680 | |
| 3681 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3682 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 3683 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 3684 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3685 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3686 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3687 | } |
| 3688 | |
| 3689 | template <typename BufferImageCopyRegionType> |
| 3690 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3691 | VkBuffer dstBuffer, uint32_t regionCount, |
| 3692 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3693 | bool skip = false; |
| 3694 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3695 | assert(cb_access_context); |
| 3696 | if (!cb_access_context) return skip; |
| 3697 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3698 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3699 | const char *func_name = is_2khr ? "vkCmdCopyImageToBuffer2KHR()" : "vkCmdCopyImageToBuffer()"; |
| 3700 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3701 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3702 | assert(context); |
| 3703 | if (!context) return skip; |
| 3704 | |
| 3705 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3706 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 3707 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->MemState()->mem() : VK_NULL_HANDLE; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3708 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3709 | const auto ©_region = pRegions[region]; |
| 3710 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3711 | 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] | 3712 | copy_region.imageOffset, copy_region.imageExtent); |
| 3713 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3714 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3715 | "%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] | 3716 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3717 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3718 | } |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3719 | if (dst_mem) { |
| 3720 | ResourceAccessRange dst_range = |
| 3721 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3722 | hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3723 | if (hazard.hazard) { |
| 3724 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3725 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3726 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3727 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3728 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3729 | } |
| 3730 | } |
| 3731 | if (skip) break; |
| 3732 | } |
| 3733 | return skip; |
| 3734 | } |
| 3735 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3736 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 3737 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 3738 | const VkBufferImageCopy *pRegions) const { |
| 3739 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
| 3740 | COPY_COMMAND_VERSION_1); |
| 3741 | } |
| 3742 | |
| 3743 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3744 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 3745 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3746 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3747 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3748 | } |
| 3749 | |
| 3750 | template <typename BufferImageCopyRegionType> |
| 3751 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3752 | VkBuffer dstBuffer, uint32_t regionCount, const BufferImageCopyRegionType *pRegions, |
| 3753 | CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3754 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3755 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3756 | |
| 3757 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3758 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYIMAGETOBUFFER2KHR : CMD_COPYIMAGETOBUFFER; |
| 3759 | |
| 3760 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3761 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3762 | assert(context); |
| 3763 | |
| 3764 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3765 | auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 3766 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->MemState()->mem() : VK_NULL_HANDLE; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3767 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3768 | |
| 3769 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3770 | const auto ©_region = pRegions[region]; |
| 3771 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3772 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3773 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3774 | if (dst_buffer) { |
| 3775 | ResourceAccessRange dst_range = |
| 3776 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3777 | 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] | 3778 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3779 | } |
| 3780 | } |
| 3781 | } |
| 3782 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3783 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3784 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 3785 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
| 3786 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3787 | } |
| 3788 | |
| 3789 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3790 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 3791 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 3792 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3793 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3794 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3795 | } |
| 3796 | |
| 3797 | template <typename RegionType> |
| 3798 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3799 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3800 | const RegionType *pRegions, VkFilter filter, const char *apiName) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3801 | bool skip = false; |
| 3802 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3803 | assert(cb_access_context); |
| 3804 | if (!cb_access_context) return skip; |
| 3805 | |
| 3806 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3807 | assert(context); |
| 3808 | if (!context) return skip; |
| 3809 | |
| 3810 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3811 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3812 | |
| 3813 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3814 | const auto &blit_region = pRegions[region]; |
| 3815 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3816 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3817 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3818 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3819 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3820 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3821 | 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] | 3822 | 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] | 3823 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3824 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3825 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3826 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3827 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3828 | } |
| 3829 | } |
| 3830 | |
| 3831 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3832 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3833 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3834 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3835 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3836 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3837 | 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] | 3838 | 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] | 3839 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3840 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3841 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3842 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3843 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3844 | } |
| 3845 | if (skip) break; |
| 3846 | } |
| 3847 | } |
| 3848 | |
| 3849 | return skip; |
| 3850 | } |
| 3851 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3852 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3853 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3854 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 3855 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
| 3856 | "vkCmdBlitImage"); |
| 3857 | } |
| 3858 | |
| 3859 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 3860 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 3861 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 3862 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 3863 | pBlitImageInfo->filter, "vkCmdBlitImage2KHR"); |
| 3864 | } |
| 3865 | |
| 3866 | template <typename RegionType> |
| 3867 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3868 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3869 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3870 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3871 | assert(cb_access_context); |
| 3872 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3873 | assert(context); |
| 3874 | |
| 3875 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3876 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3877 | |
| 3878 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3879 | const auto &blit_region = pRegions[region]; |
| 3880 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3881 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3882 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3883 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3884 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3885 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3886 | 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] | 3887 | context->UpdateAccessState(*src_image, SYNC_BLIT_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3888 | blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3889 | } |
| 3890 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3891 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3892 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3893 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3894 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3895 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3896 | 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] | 3897 | context->UpdateAccessState(*dst_image, SYNC_BLIT_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3898 | blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3899 | } |
| 3900 | } |
| 3901 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3902 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3903 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3904 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3905 | const VkImageBlit *pRegions, VkFilter filter) { |
| 3906 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3907 | assert(cb_access_context); |
| 3908 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 3909 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 3910 | pRegions, filter); |
| 3911 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 3912 | } |
| 3913 | |
| 3914 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 3915 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 3916 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3917 | assert(cb_access_context); |
| 3918 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 3919 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 3920 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 3921 | pBlitImageInfo->filter, tag); |
| 3922 | } |
| 3923 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3924 | bool SyncValidator::ValidateIndirectBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 3925 | VkCommandBuffer commandBuffer, const VkDeviceSize struct_size, const VkBuffer buffer, |
| 3926 | const VkDeviceSize offset, const uint32_t drawCount, const uint32_t stride, |
| 3927 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3928 | bool skip = false; |
| 3929 | if (drawCount == 0) return skip; |
| 3930 | |
| 3931 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 3932 | VkDeviceSize size = struct_size; |
| 3933 | if (drawCount == 1 || stride == size) { |
| 3934 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3935 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3936 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3937 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3938 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3939 | "%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] | 3940 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3941 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3942 | } |
| 3943 | } else { |
| 3944 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3945 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3946 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3947 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3948 | skip |= LogError(buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3949 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
| 3950 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3951 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3952 | break; |
| 3953 | } |
| 3954 | } |
| 3955 | } |
| 3956 | return skip; |
| 3957 | } |
| 3958 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3959 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag &tag, const VkDeviceSize struct_size, |
| 3960 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 3961 | uint32_t stride) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3962 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 3963 | VkDeviceSize size = struct_size; |
| 3964 | if (drawCount == 1 || stride == size) { |
| 3965 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3966 | const ResourceAccessRange range = MakeRange(offset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3967 | 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] | 3968 | } else { |
| 3969 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3970 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3971 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, |
| 3972 | tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3973 | } |
| 3974 | } |
| 3975 | } |
| 3976 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3977 | bool SyncValidator::ValidateCountBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 3978 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3979 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3980 | bool skip = false; |
| 3981 | |
| 3982 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3983 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3984 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3985 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3986 | skip |= LogError(count_buf_state->buffer(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3987 | "%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] | 3988 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3989 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3990 | } |
| 3991 | return skip; |
| 3992 | } |
| 3993 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3994 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag &tag, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3995 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3996 | const ResourceAccessRange range = MakeRange(offset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3997 | 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] | 3998 | } |
| 3999 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4000 | 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] | 4001 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4002 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4003 | assert(cb_access_context); |
| 4004 | if (!cb_access_context) return skip; |
| 4005 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4006 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4007 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | 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] | 4011 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4012 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4013 | assert(cb_access_context); |
| 4014 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4015 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4016 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4017 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4018 | |
| 4019 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4020 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4021 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4022 | assert(cb_access_context); |
| 4023 | if (!cb_access_context) return skip; |
| 4024 | |
| 4025 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4026 | assert(context); |
| 4027 | if (!context) return skip; |
| 4028 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4029 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4030 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, |
| 4031 | 1, sizeof(VkDispatchIndirectCommand), "vkCmdDispatchIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4032 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4036 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4037 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4038 | assert(cb_access_context); |
| 4039 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 4040 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4041 | assert(context); |
| 4042 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4043 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 4044 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4048 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4049 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4050 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4051 | assert(cb_access_context); |
| 4052 | if (!cb_access_context) return skip; |
| 4053 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4054 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw"); |
| 4055 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, "vkCmdDraw"); |
| 4056 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDraw"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4057 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4058 | } |
| 4059 | |
| 4060 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4061 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4062 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4063 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4064 | assert(cb_access_context); |
| 4065 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4066 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4067 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4068 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 4069 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4073 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4074 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4075 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4076 | assert(cb_access_context); |
| 4077 | if (!cb_access_context) return skip; |
| 4078 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4079 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed"); |
| 4080 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, "vkCmdDrawIndexed"); |
| 4081 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexed"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4082 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4086 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4087 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4088 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4089 | assert(cb_access_context); |
| 4090 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4091 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4092 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4093 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 4094 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4098 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4099 | bool skip = false; |
| 4100 | if (drawCount == 0) return skip; |
| 4101 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4102 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4103 | assert(cb_access_context); |
| 4104 | if (!cb_access_context) return skip; |
| 4105 | |
| 4106 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4107 | assert(context); |
| 4108 | if (!context) return skip; |
| 4109 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4110 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect"); |
| 4111 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4112 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4113 | drawCount, stride, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4114 | |
| 4115 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4116 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4117 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4118 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4119 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4120 | } |
| 4121 | |
| 4122 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4123 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4124 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4125 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4126 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4127 | assert(cb_access_context); |
| 4128 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 4129 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4130 | assert(context); |
| 4131 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4132 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4133 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4134 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4135 | |
| 4136 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4137 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4138 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4139 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4143 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4144 | bool skip = false; |
| 4145 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4146 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4147 | assert(cb_access_context); |
| 4148 | if (!cb_access_context) return skip; |
| 4149 | |
| 4150 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4151 | assert(context); |
| 4152 | if (!context) return skip; |
| 4153 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4154 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect"); |
| 4155 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexedIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4156 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4157 | offset, drawCount, stride, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4158 | |
| 4159 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4160 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4161 | // 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] | 4162 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4163 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4167 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4168 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4169 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4170 | assert(cb_access_context); |
| 4171 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 4172 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4173 | assert(context); |
| 4174 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4175 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4176 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4177 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4178 | |
| 4179 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4180 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4181 | // 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] | 4182 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4186 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4187 | uint32_t stride, const char *function) const { |
| 4188 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4189 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4190 | assert(cb_access_context); |
| 4191 | if (!cb_access_context) return skip; |
| 4192 | |
| 4193 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4194 | assert(context); |
| 4195 | if (!context) return skip; |
| 4196 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4197 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4198 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4199 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4200 | maxDrawCount, stride, function); |
| 4201 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4202 | |
| 4203 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4204 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4205 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4206 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4207 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4211 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4212 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4213 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4214 | "vkCmdDrawIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4218 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4219 | uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4220 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4221 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4222 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4223 | assert(cb_access_context); |
| 4224 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECTCOUNT); |
| 4225 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4226 | assert(context); |
| 4227 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4228 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4229 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4230 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 4231 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4232 | |
| 4233 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4234 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4235 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4236 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4237 | } |
| 4238 | |
| 4239 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4240 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4241 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4242 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4243 | "vkCmdDrawIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4247 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4248 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4249 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4250 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4251 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4255 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4256 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4257 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4258 | "vkCmdDrawIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4262 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4263 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4264 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4265 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4266 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4267 | } |
| 4268 | |
| 4269 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4270 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4271 | uint32_t stride, const char *function) const { |
| 4272 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4273 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4274 | assert(cb_access_context); |
| 4275 | if (!cb_access_context) return skip; |
| 4276 | |
| 4277 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4278 | assert(context); |
| 4279 | if (!context) return skip; |
| 4280 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4281 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4282 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4283 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4284 | offset, maxDrawCount, stride, function); |
| 4285 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4286 | |
| 4287 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4288 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4289 | // 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] | 4290 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4291 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4295 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4296 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4297 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4298 | "vkCmdDrawIndexedIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4302 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4303 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4304 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4305 | maxDrawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4306 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4307 | assert(cb_access_context); |
| 4308 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 4309 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4310 | assert(context); |
| 4311 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4312 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4313 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4314 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 4315 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4316 | |
| 4317 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4318 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4319 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 4320 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4324 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4325 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4326 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4327 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4328 | "vkCmdDrawIndexedIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4332 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4333 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4334 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4335 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4336 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4337 | } |
| 4338 | |
| 4339 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4340 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4341 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4342 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4343 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4344 | "vkCmdDrawIndexedIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4348 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4349 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4350 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4351 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4352 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4353 | } |
| 4354 | |
| 4355 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4356 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4357 | const VkImageSubresourceRange *pRanges) const { |
| 4358 | bool skip = false; |
| 4359 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4360 | assert(cb_access_context); |
| 4361 | if (!cb_access_context) return skip; |
| 4362 | |
| 4363 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4364 | assert(context); |
| 4365 | if (!context) return skip; |
| 4366 | |
| 4367 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4368 | |
| 4369 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4370 | const auto &range = pRanges[index]; |
| 4371 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4372 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4373 | if (hazard.hazard) { |
| 4374 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4375 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4376 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4377 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4378 | } |
| 4379 | } |
| 4380 | } |
| 4381 | return skip; |
| 4382 | } |
| 4383 | |
| 4384 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4385 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4386 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4387 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4388 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4389 | assert(cb_access_context); |
| 4390 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 4391 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4392 | assert(context); |
| 4393 | |
| 4394 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4395 | |
| 4396 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4397 | const auto &range = pRanges[index]; |
| 4398 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4399 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4400 | } |
| 4401 | } |
| 4402 | } |
| 4403 | |
| 4404 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 4405 | VkImageLayout imageLayout, |
| 4406 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4407 | const VkImageSubresourceRange *pRanges) const { |
| 4408 | bool skip = false; |
| 4409 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4410 | assert(cb_access_context); |
| 4411 | if (!cb_access_context) return skip; |
| 4412 | |
| 4413 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4414 | assert(context); |
| 4415 | if (!context) return skip; |
| 4416 | |
| 4417 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4418 | |
| 4419 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4420 | const auto &range = pRanges[index]; |
| 4421 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4422 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4423 | if (hazard.hazard) { |
| 4424 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4425 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4426 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4427 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4428 | } |
| 4429 | } |
| 4430 | } |
| 4431 | return skip; |
| 4432 | } |
| 4433 | |
| 4434 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4435 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4436 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4437 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4438 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4439 | assert(cb_access_context); |
| 4440 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 4441 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4442 | assert(context); |
| 4443 | |
| 4444 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4445 | |
| 4446 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4447 | const auto &range = pRanges[index]; |
| 4448 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4449 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4450 | } |
| 4451 | } |
| 4452 | } |
| 4453 | |
| 4454 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4455 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 4456 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 4457 | VkQueryResultFlags flags) const { |
| 4458 | bool skip = false; |
| 4459 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4460 | assert(cb_access_context); |
| 4461 | if (!cb_access_context) return skip; |
| 4462 | |
| 4463 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4464 | assert(context); |
| 4465 | if (!context) return skip; |
| 4466 | |
| 4467 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4468 | |
| 4469 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4470 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4471 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4472 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4473 | skip |= |
| 4474 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4475 | "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] | 4476 | 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] | 4477 | } |
| 4478 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4479 | |
| 4480 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4481 | return skip; |
| 4482 | } |
| 4483 | |
| 4484 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 4485 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4486 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4487 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 4488 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4489 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4490 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4491 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4492 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4493 | assert(context); |
| 4494 | |
| 4495 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4496 | |
| 4497 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4498 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4499 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4500 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4501 | |
| 4502 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4503 | } |
| 4504 | |
| 4505 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4506 | VkDeviceSize size, uint32_t data) const { |
| 4507 | bool skip = false; |
| 4508 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4509 | assert(cb_access_context); |
| 4510 | if (!cb_access_context) return skip; |
| 4511 | |
| 4512 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4513 | assert(context); |
| 4514 | if (!context) return skip; |
| 4515 | |
| 4516 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4517 | |
| 4518 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4519 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4520 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4521 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4522 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4523 | "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] | 4524 | 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] | 4525 | } |
| 4526 | } |
| 4527 | return skip; |
| 4528 | } |
| 4529 | |
| 4530 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4531 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4532 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4533 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4534 | assert(cb_access_context); |
| 4535 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 4536 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4537 | assert(context); |
| 4538 | |
| 4539 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4540 | |
| 4541 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4542 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4543 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4544 | } |
| 4545 | } |
| 4546 | |
| 4547 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4548 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4549 | const VkImageResolve *pRegions) const { |
| 4550 | bool skip = false; |
| 4551 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4552 | assert(cb_access_context); |
| 4553 | if (!cb_access_context) return skip; |
| 4554 | |
| 4555 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4556 | assert(context); |
| 4557 | if (!context) return skip; |
| 4558 | |
| 4559 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4560 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4561 | |
| 4562 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4563 | const auto &resolve_region = pRegions[region]; |
| 4564 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4565 | 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] | 4566 | resolve_region.srcOffset, resolve_region.extent); |
| 4567 | if (hazard.hazard) { |
| 4568 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4569 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4570 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4571 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4572 | } |
| 4573 | } |
| 4574 | |
| 4575 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4576 | 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] | 4577 | resolve_region.dstOffset, resolve_region.extent); |
| 4578 | if (hazard.hazard) { |
| 4579 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4580 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4581 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4582 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4583 | } |
| 4584 | if (skip) break; |
| 4585 | } |
| 4586 | } |
| 4587 | |
| 4588 | return skip; |
| 4589 | } |
| 4590 | |
| 4591 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4592 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4593 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4594 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4595 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4596 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4597 | assert(cb_access_context); |
| 4598 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 4599 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4600 | assert(context); |
| 4601 | |
| 4602 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4603 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4604 | |
| 4605 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4606 | const auto &resolve_region = pRegions[region]; |
| 4607 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4608 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4609 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4610 | } |
| 4611 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4612 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4613 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4614 | } |
| 4615 | } |
| 4616 | } |
| 4617 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4618 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4619 | const VkResolveImageInfo2KHR *pResolveImageInfo) const { |
| 4620 | bool skip = false; |
| 4621 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4622 | assert(cb_access_context); |
| 4623 | if (!cb_access_context) return skip; |
| 4624 | |
| 4625 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4626 | assert(context); |
| 4627 | if (!context) return skip; |
| 4628 | |
| 4629 | const auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4630 | const auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4631 | |
| 4632 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4633 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4634 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4635 | 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] | 4636 | resolve_region.srcOffset, resolve_region.extent); |
| 4637 | if (hazard.hazard) { |
| 4638 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 4639 | "vkCmdResolveImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 4640 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4641 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4646 | 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] | 4647 | resolve_region.dstOffset, resolve_region.extent); |
| 4648 | if (hazard.hazard) { |
| 4649 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 4650 | "vkCmdResolveImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 4651 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4652 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4653 | } |
| 4654 | if (skip) break; |
| 4655 | } |
| 4656 | } |
| 4657 | |
| 4658 | return skip; |
| 4659 | } |
| 4660 | |
| 4661 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4662 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 4663 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 4664 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4665 | assert(cb_access_context); |
| 4666 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE2KHR); |
| 4667 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4668 | assert(context); |
| 4669 | |
| 4670 | auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4671 | auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4672 | |
| 4673 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4674 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4675 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4676 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4677 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4678 | } |
| 4679 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4680 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4681 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4682 | } |
| 4683 | } |
| 4684 | } |
| 4685 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4686 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4687 | VkDeviceSize dataSize, const void *pData) const { |
| 4688 | bool skip = false; |
| 4689 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4690 | assert(cb_access_context); |
| 4691 | if (!cb_access_context) return skip; |
| 4692 | |
| 4693 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4694 | assert(context); |
| 4695 | if (!context) return skip; |
| 4696 | |
| 4697 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4698 | |
| 4699 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4700 | // VK_WHOLE_SIZE not allowed |
| 4701 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4702 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4703 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4704 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4705 | "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] | 4706 | 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] | 4707 | } |
| 4708 | } |
| 4709 | return skip; |
| 4710 | } |
| 4711 | |
| 4712 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4713 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4714 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4715 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4716 | assert(cb_access_context); |
| 4717 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 4718 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4719 | assert(context); |
| 4720 | |
| 4721 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4722 | |
| 4723 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4724 | // VK_WHOLE_SIZE not allowed |
| 4725 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4726 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4727 | } |
| 4728 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4729 | |
| 4730 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4731 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 4732 | bool skip = false; |
| 4733 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4734 | assert(cb_access_context); |
| 4735 | if (!cb_access_context) return skip; |
| 4736 | |
| 4737 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4738 | assert(context); |
| 4739 | if (!context) return skip; |
| 4740 | |
| 4741 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4742 | |
| 4743 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4744 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4745 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4746 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4747 | skip |= |
| 4748 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4749 | "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] | 4750 | 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] | 4751 | } |
| 4752 | } |
| 4753 | return skip; |
| 4754 | } |
| 4755 | |
| 4756 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4757 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4758 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4759 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4760 | assert(cb_access_context); |
| 4761 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 4762 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4763 | assert(context); |
| 4764 | |
| 4765 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4766 | |
| 4767 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4768 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4769 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4770 | } |
| 4771 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4772 | |
| 4773 | bool SyncValidator::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
| 4774 | bool skip = false; |
| 4775 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4776 | assert(cb_context); |
| 4777 | if (!cb_context) return skip; |
| 4778 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4779 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 4780 | return set_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | void SyncValidator::PostCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 4784 | StateTracker::PostCallRecordCmdSetEvent(commandBuffer, event, stageMask); |
| 4785 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4786 | assert(cb_context); |
| 4787 | if (!cb_context) return; |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4788 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4789 | set_event_op.Record(cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4790 | } |
| 4791 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4792 | bool SyncValidator::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4793 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 4794 | bool skip = false; |
| 4795 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4796 | assert(cb_context); |
| 4797 | if (!cb_context || !pDependencyInfo) return skip; |
| 4798 | |
| 4799 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 4800 | return set_event_op.Validate(*cb_context); |
| 4801 | } |
| 4802 | |
| 4803 | void SyncValidator::PostCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4804 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 4805 | StateTracker::PostCallRecordCmdSetEvent2KHR(commandBuffer, event, pDependencyInfo); |
| 4806 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4807 | assert(cb_context); |
| 4808 | if (!cb_context || !pDependencyInfo) return; |
| 4809 | |
| 4810 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 4811 | set_event_op.Record(cb_context); |
| 4812 | } |
| 4813 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4814 | bool SyncValidator::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4815 | VkPipelineStageFlags stageMask) const { |
| 4816 | bool skip = false; |
| 4817 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4818 | assert(cb_context); |
| 4819 | if (!cb_context) return skip; |
| 4820 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4821 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 4822 | return reset_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | void SyncValidator::PostCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 4826 | StateTracker::PostCallRecordCmdResetEvent(commandBuffer, event, stageMask); |
| 4827 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4828 | assert(cb_context); |
| 4829 | if (!cb_context) return; |
| 4830 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4831 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4832 | reset_event_op.Record(cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4833 | } |
| 4834 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4835 | bool SyncValidator::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4836 | VkPipelineStageFlags2KHR stageMask) const { |
| 4837 | bool skip = false; |
| 4838 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4839 | assert(cb_context); |
| 4840 | if (!cb_context) return skip; |
| 4841 | |
| 4842 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4843 | return reset_event_op.Validate(*cb_context); |
| 4844 | } |
| 4845 | |
| 4846 | void SyncValidator::PostCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4847 | VkPipelineStageFlags2KHR stageMask) { |
| 4848 | StateTracker::PostCallRecordCmdResetEvent2KHR(commandBuffer, event, stageMask); |
| 4849 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4850 | assert(cb_context); |
| 4851 | if (!cb_context) return; |
| 4852 | |
| 4853 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4854 | reset_event_op.Record(cb_context); |
| 4855 | } |
| 4856 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4857 | bool SyncValidator::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4858 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4859 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4860 | uint32_t bufferMemoryBarrierCount, |
| 4861 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4862 | uint32_t imageMemoryBarrierCount, |
| 4863 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 4864 | bool skip = false; |
| 4865 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4866 | assert(cb_context); |
| 4867 | if (!cb_context) return skip; |
| 4868 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4869 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 4870 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 4871 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 4872 | return wait_events_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | void SyncValidator::PostCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4876 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4877 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4878 | uint32_t bufferMemoryBarrierCount, |
| 4879 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4880 | uint32_t imageMemoryBarrierCount, |
| 4881 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 4882 | StateTracker::PostCallRecordCmdWaitEvents(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
| 4883 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 4884 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 4885 | |
| 4886 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4887 | assert(cb_context); |
| 4888 | if (!cb_context) return; |
| 4889 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4890 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 4891 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 4892 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
| 4893 | return wait_events_op.Record(cb_context); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4894 | } |
| 4895 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4896 | bool SyncValidator::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4897 | const VkDependencyInfoKHR *pDependencyInfos) const { |
| 4898 | bool skip = false; |
| 4899 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4900 | assert(cb_context); |
| 4901 | if (!cb_context) return skip; |
| 4902 | |
| 4903 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 4904 | skip |= wait_events_op.Validate(*cb_context); |
| 4905 | return skip; |
| 4906 | } |
| 4907 | |
| 4908 | void SyncValidator::PostCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4909 | const VkDependencyInfoKHR *pDependencyInfos) { |
| 4910 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 4911 | |
| 4912 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4913 | assert(cb_context); |
| 4914 | if (!cb_context) return; |
| 4915 | |
| 4916 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 4917 | wait_events_op.Record(cb_context); |
| 4918 | } |
| 4919 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4920 | void SyncEventState::ResetFirstScope() { |
| 4921 | for (const auto address_type : kAddressTypes) { |
| 4922 | first_scope[static_cast<size_t>(address_type)].clear(); |
| 4923 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 4924 | scope = SyncExecScope(); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | // 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] | 4928 | SyncEventState::IgnoreReason SyncEventState::IsIgnoredByWait(CMD_TYPE cmd, VkPipelineStageFlags2KHR srcStageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4929 | IgnoreReason reason = NotIgnored; |
| 4930 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4931 | if ((CMD_WAITEVENTS2KHR == cmd) && (CMD_SETEVENT == last_command)) { |
| 4932 | reason = SetVsWait2; |
| 4933 | } else if ((last_command == CMD_RESETEVENT || last_command == CMD_RESETEVENT2KHR) && !HasBarrier(0U, 0U)) { |
| 4934 | reason = (last_command == CMD_RESETEVENT) ? ResetWaitRace : Reset2WaitRace; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4935 | } else if (unsynchronized_set) { |
| 4936 | reason = SetRace; |
| 4937 | } else { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4938 | const VkPipelineStageFlags2KHR missing_bits = scope.mask_param & ~srcStageMask; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4939 | if (missing_bits) reason = MissingStageBits; |
| 4940 | } |
| 4941 | |
| 4942 | return reason; |
| 4943 | } |
| 4944 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4945 | bool SyncEventState::HasBarrier(VkPipelineStageFlags2KHR stageMask, VkPipelineStageFlags2KHR exec_scope_arg) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4946 | bool has_barrier = (last_command == CMD_NONE) || (stageMask & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) || |
| 4947 | (barriers & exec_scope_arg) || (barriers & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 4948 | return has_barrier; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4949 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 4950 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4951 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 4952 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4953 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 4954 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 4955 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 4956 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4957 | : SyncOpBase(cmd), barriers_(1) { |
| 4958 | auto &barrier_set = barriers_[0]; |
| 4959 | barrier_set.dependency_flags = dependencyFlags; |
| 4960 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, srcStageMask); |
| 4961 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, dstStageMask); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 4962 | // 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] | 4963 | barrier_set.MakeMemoryBarriers(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, memoryBarrierCount, |
| 4964 | pMemoryBarriers); |
| 4965 | barrier_set.MakeBufferMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 4966 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
| 4967 | barrier_set.MakeImageMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 4968 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 4969 | } |
| 4970 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4971 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t event_count, |
| 4972 | const VkDependencyInfoKHR *dep_infos) |
| 4973 | : SyncOpBase(cmd), barriers_(event_count) { |
| 4974 | for (uint32_t i = 0; i < event_count; i++) { |
| 4975 | const auto &dep_info = dep_infos[i]; |
| 4976 | auto &barrier_set = barriers_[i]; |
| 4977 | barrier_set.dependency_flags = dep_info.dependencyFlags; |
| 4978 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 4979 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, stage_masks.src); |
| 4980 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, stage_masks.dst); |
| 4981 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
| 4982 | barrier_set.MakeMemoryBarriers(queue_flags, dep_info.dependencyFlags, dep_info.memoryBarrierCount, |
| 4983 | dep_info.pMemoryBarriers); |
| 4984 | barrier_set.MakeBufferMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.bufferMemoryBarrierCount, |
| 4985 | dep_info.pBufferMemoryBarriers); |
| 4986 | barrier_set.MakeImageMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.imageMemoryBarrierCount, |
| 4987 | dep_info.pImageMemoryBarriers); |
| 4988 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4989 | } |
| 4990 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4991 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 4992 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4993 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 4994 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 4995 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 4996 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4997 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 4998 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers) {} |
| 4999 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5000 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5001 | const VkDependencyInfoKHR &dep_info) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5002 | : SyncOpBarriers(cmd, sync_state, queue_flags, 1, &dep_info) {} |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5003 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5004 | bool SyncOpPipelineBarrier::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5005 | bool skip = false; |
| 5006 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5007 | assert(context); |
| 5008 | if (!context) return skip; |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5009 | assert(barriers_.size() == 1); // PipelineBarriers only support a single barrier set. |
| 5010 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5011 | // Validate Image Layout transitions |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5012 | const auto &barrier_set = barriers_[0]; |
| 5013 | for (const auto &image_barrier : barrier_set.image_memory_barriers) { |
| 5014 | if (image_barrier.new_layout == image_barrier.old_layout) continue; // Only interested in layout transitions at this point. |
| 5015 | const auto *image_state = image_barrier.image.get(); |
| 5016 | if (!image_state) continue; |
| 5017 | const auto hazard = context->DetectImageBarrierHazard(image_barrier); |
| 5018 | if (hazard.hazard) { |
| 5019 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 5020 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5021 | const auto image_handle = image_state->image(); |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5022 | skip |= sync_state.LogError(image_handle, string_SyncHazardVUID(hazard.hazard), |
| 5023 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5024 | string_SyncHazard(hazard.hazard), image_barrier.index, |
| 5025 | sync_state.report_data->FormatHandle(image_handle).c_str(), |
| 5026 | cb_context.FormatUsage(hazard).c_str()); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5027 | } |
| 5028 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5029 | return skip; |
| 5030 | } |
| 5031 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5032 | struct SyncOpPipelineBarrierFunctorFactory { |
| 5033 | using BarrierOpFunctor = PipelineBarrierOp; |
| 5034 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5035 | using GlobalBarrierOpFunctor = PipelineBarrierOp; |
| 5036 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5037 | using BufferRange = ResourceAccessRange; |
| 5038 | using ImageRange = subresource_adapter::ImageRangeGenerator; |
| 5039 | using GlobalRange = ResourceAccessRange; |
| 5040 | |
| 5041 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier, bool layout_transition) const { |
| 5042 | return ApplyFunctor(BarrierOpFunctor(barrier, layout_transition)); |
| 5043 | } |
| 5044 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, const ResourceUsageTag &tag) const { |
| 5045 | return GlobalApplyFunctor(true /* resolve */, size_hint, tag); |
| 5046 | } |
| 5047 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier) const { |
| 5048 | return GlobalBarrierOpFunctor(barrier, false); |
| 5049 | } |
| 5050 | |
| 5051 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range) const { |
| 5052 | if (!SimpleBinding(buffer)) return ResourceAccessRange(); |
| 5053 | const auto base_address = ResourceBaseAddress(buffer); |
| 5054 | return (range + base_address); |
| 5055 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5056 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 5057 | if (!SimpleBinding(image)) return subresource_adapter::ImageRangeGenerator(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5058 | |
| 5059 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5060 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5061 | return range_gen; |
| 5062 | } |
| 5063 | GlobalRange MakeGlobalRangeGen(AccessAddressType) const { return kFullRange; } |
| 5064 | }; |
| 5065 | |
| 5066 | template <typename Barriers, typename FunctorFactory> |
| 5067 | void SyncOpBarriers::ApplyBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag &tag, |
| 5068 | AccessContext *context) { |
| 5069 | for (const auto &barrier : barriers) { |
| 5070 | const auto *state = barrier.GetState(); |
| 5071 | if (state) { |
| 5072 | auto *const accesses = &context->GetAccessStateMap(GetAccessAddressType(*state)); |
| 5073 | auto update_action = factory.MakeApplyFunctor(barrier.barrier, barrier.IsLayoutTransition()); |
| 5074 | auto range_gen = factory.MakeRangeGen(*state, barrier.Range()); |
| 5075 | UpdateMemoryAccessState(accesses, update_action, &range_gen); |
| 5076 | } |
| 5077 | } |
| 5078 | } |
| 5079 | |
| 5080 | template <typename Barriers, typename FunctorFactory> |
| 5081 | void SyncOpBarriers::ApplyGlobalBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag &tag, |
| 5082 | AccessContext *access_context) { |
| 5083 | auto barriers_functor = factory.MakeGlobalApplyFunctor(barriers.size(), tag); |
| 5084 | for (const auto &barrier : barriers) { |
| 5085 | barriers_functor.EmplaceBack(factory.MakeGlobalBarrierOpFunctor(barrier)); |
| 5086 | } |
| 5087 | for (const auto address_type : kAddressTypes) { |
| 5088 | auto range_gen = factory.MakeGlobalRangeGen(address_type); |
| 5089 | UpdateMemoryAccessState(&(access_context->GetAccessStateMap(address_type)), barriers_functor, &range_gen); |
| 5090 | } |
| 5091 | } |
| 5092 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5093 | void SyncOpPipelineBarrier::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5094 | SyncOpPipelineBarrierFunctorFactory factory; |
| 5095 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5096 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5097 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5098 | // Pipeline barriers only have a single barrier set, unlike WaitEvents2 |
| 5099 | assert(barriers_.size() == 1); |
| 5100 | const auto &barrier_set = barriers_[0]; |
| 5101 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5102 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5103 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
| 5104 | |
| 5105 | if (barrier_set.single_exec_scope) { |
| 5106 | cb_context->ApplyGlobalBarriersToEvents(barrier_set.src_exec_scope, barrier_set.dst_exec_scope); |
| 5107 | } else { |
| 5108 | for (const auto &barrier : barrier_set.memory_barriers) { |
| 5109 | cb_context->ApplyGlobalBarriersToEvents(barrier.src_exec_scope, barrier.dst_exec_scope); |
| 5110 | } |
| 5111 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5112 | } |
| 5113 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5114 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(const SyncExecScope &src, const SyncExecScope &dst, |
| 5115 | VkDependencyFlags dependency_flags, uint32_t memory_barrier_count, |
| 5116 | const VkMemoryBarrier *barriers) { |
| 5117 | memory_barriers.reserve(std::max<uint32_t>(1, memory_barrier_count)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5118 | 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] | 5119 | const auto &barrier = barriers[barrier_index]; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5120 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5121 | memory_barriers.emplace_back(sync_barrier); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5122 | } |
| 5123 | if (0 == memory_barrier_count) { |
| 5124 | // If there are no global memory barriers, force an exec barrier |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5125 | memory_barriers.emplace_back(SyncBarrier(src, dst)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5126 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5127 | single_exec_scope = true; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5128 | } |
| 5129 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5130 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5131 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5132 | uint32_t barrier_count, const VkBufferMemoryBarrier *barriers) { |
| 5133 | buffer_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5134 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5135 | const auto &barrier = barriers[index]; |
| 5136 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5137 | if (buffer) { |
| 5138 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5139 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5140 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5141 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5142 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5143 | buffer_memory_barriers.emplace_back(); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5144 | } |
| 5145 | } |
| 5146 | } |
| 5147 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5148 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(VkQueueFlags queue_flags, VkDependencyFlags dependency_flags, |
| 5149 | uint32_t memory_barrier_count, const VkMemoryBarrier2KHR *barriers) { |
| 5150 | memory_barriers.reserve(memory_barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5151 | 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] | 5152 | const auto &barrier = barriers[barrier_index]; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5153 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5154 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5155 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5156 | memory_barriers.emplace_back(sync_barrier); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5157 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5158 | single_exec_scope = false; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5161 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5162 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5163 | const VkBufferMemoryBarrier2KHR *barriers) { |
| 5164 | buffer_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5165 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5166 | const auto &barrier = barriers[index]; |
| 5167 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5168 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5169 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5170 | if (buffer) { |
| 5171 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5172 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5173 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5174 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5175 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5176 | buffer_memory_barriers.emplace_back(); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5177 | } |
| 5178 | } |
| 5179 | } |
| 5180 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5181 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5182 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5183 | uint32_t barrier_count, const VkImageMemoryBarrier *barriers) { |
| 5184 | image_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5185 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5186 | const auto &barrier = barriers[index]; |
| 5187 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5188 | if (image) { |
| 5189 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5190 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5191 | 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] | 5192 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5193 | image_memory_barriers.emplace_back(); |
| 5194 | 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] | 5195 | } |
| 5196 | } |
| 5197 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5198 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5199 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5200 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5201 | const VkImageMemoryBarrier2KHR *barriers) { |
| 5202 | image_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5203 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5204 | const auto &barrier = barriers[index]; |
| 5205 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5206 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5207 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5208 | if (image) { |
| 5209 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5210 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5211 | 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] | 5212 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5213 | image_memory_barriers.emplace_back(); |
| 5214 | 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] | 5215 | } |
| 5216 | } |
| 5217 | } |
| 5218 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5219 | 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] | 5220 | const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5221 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5222 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5223 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5224 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, VkDependencyFlags(0U), memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5225 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 5226 | pImageMemoryBarriers) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5227 | MakeEventsList(sync_state, eventCount, pEvents); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5228 | } |
| 5229 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5230 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t eventCount, |
| 5231 | const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfo) |
| 5232 | : SyncOpBarriers(cmd, sync_state, queue_flags, eventCount, pDependencyInfo) { |
| 5233 | MakeEventsList(sync_state, eventCount, pEvents); |
| 5234 | assert(events_.size() == barriers_.size()); // Just so nobody gets clever and decides to cull the event or barrier arrays |
| 5235 | } |
| 5236 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5237 | bool SyncOpWaitEvents::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5238 | const char *const ignored = "Wait operation is ignored for this event."; |
| 5239 | bool skip = false; |
| 5240 | const auto &sync_state = cb_context.GetSyncState(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5241 | const auto command_buffer_handle = cb_context.GetCBState().commandBuffer(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5242 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5243 | for (size_t barrier_set_index = 0; barrier_set_index < barriers_.size(); barrier_set_index++) { |
| 5244 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5245 | if (barrier_set.single_exec_scope) { |
| 5246 | if (barrier_set.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5247 | const std::string vuid = std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 5248 | skip = sync_state.LogInfo(command_buffer_handle, vuid, |
| 5249 | "%s, srcStageMask includes %s, unsupported by synchronization validation.", CmdName(), |
| 5250 | string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT)); |
| 5251 | } else { |
| 5252 | const auto &barriers = barrier_set.memory_barriers; |
| 5253 | for (size_t barrier_index = 0; barrier_index < barriers.size(); barrier_index++) { |
| 5254 | const auto &barrier = barriers[barrier_index]; |
| 5255 | if (barrier.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5256 | const std::string vuid = |
| 5257 | std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 5258 | skip = |
| 5259 | sync_state.LogInfo(command_buffer_handle, vuid, |
| 5260 | "%s, srcStageMask %s of %s %zu, %s %zu, unsupported by synchronization validation.", |
| 5261 | CmdName(), string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT), |
| 5262 | "pDependencyInfo", barrier_set_index, "pMemoryBarriers", barrier_index); |
| 5263 | } |
| 5264 | } |
| 5265 | } |
| 5266 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5267 | } |
| 5268 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5269 | VkPipelineStageFlags2KHR event_stage_masks = 0U; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5270 | VkPipelineStageFlags2KHR barrier_mask_params = 0U; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5271 | bool events_not_found = false; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5272 | const auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5273 | assert(events_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5274 | size_t barrier_set_index = 0; |
| 5275 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 5276 | for (size_t event_index = 0; event_index < events_.size(); event_index++) |
| 5277 | for (const auto &event : events_) { |
| 5278 | const auto *sync_event = events_context->Get(event.get()); |
| 5279 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5280 | if (!sync_event) { |
| 5281 | // NOTE PHASE2: This is where we'll need queue submit time validation to come back and check the srcStageMask bits |
| 5282 | // or solve this with replay creating the SyncEventState in the queue context... also this will be a |
| 5283 | // new validation error... wait without previously submitted set event... |
| 5284 | events_not_found = true; // Demote "extra_stage_bits" error to warning, to avoid false positives at *record time* |
| 5285 | barrier_set_index += barrier_set_incr; |
| 5286 | continue; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5287 | } |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5288 | const auto event_handle = sync_event->event->event(); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5289 | // TODO add "destroyed" checks |
| 5290 | |
| 5291 | barrier_mask_params |= barrier_set.src_exec_scope.mask_param; |
| 5292 | const auto &src_exec_scope = barrier_set.src_exec_scope; |
| 5293 | event_stage_masks |= sync_event->scope.mask_param; |
| 5294 | const auto ignore_reason = sync_event->IsIgnoredByWait(cmd_, src_exec_scope.mask_param); |
| 5295 | if (ignore_reason) { |
| 5296 | switch (ignore_reason) { |
| 5297 | case SyncEventState::ResetWaitRace: |
| 5298 | case SyncEventState::Reset2WaitRace: { |
| 5299 | // Four permuations of Reset and Wait calls... |
| 5300 | const char *vuid = |
| 5301 | (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent-event-03834" : "VUID-vkCmdResetEvent-event-03835"; |
| 5302 | if (ignore_reason == SyncEventState::Reset2WaitRace) { |
| 5303 | vuid = |
Jeremy Gebben | 476f5e2 | 2021-03-01 15:27:20 -0700 | [diff] [blame] | 5304 | (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent2KHR-event-03831" : "VUID-vkCmdResetEvent2KHR-event-03832"; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5305 | } |
| 5306 | const char *const message = |
| 5307 | "%s: %s %s operation following %s without intervening execution barrier, may cause race condition. %s"; |
| 5308 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5309 | sync_state.report_data->FormatHandle(event_handle).c_str(), CmdName(), |
| 5310 | CommandTypeString(sync_event->last_command), ignored); |
| 5311 | break; |
| 5312 | } |
| 5313 | case SyncEventState::SetRace: { |
| 5314 | // Issue error message that Wait is waiting on an signal subject to race condition, and is thus ignored for |
| 5315 | // this event |
| 5316 | const char *const vuid = "SYNC-vkCmdWaitEvents-unsynchronized-setops"; |
| 5317 | const char *const message = |
| 5318 | "%s: %s Unsychronized %s calls result in race conditions w.r.t. event signalling, %s %s"; |
| 5319 | const char *const reason = "First synchronization scope is undefined."; |
| 5320 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5321 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5322 | CommandTypeString(sync_event->last_command), reason, ignored); |
| 5323 | break; |
| 5324 | } |
| 5325 | case SyncEventState::MissingStageBits: { |
| 5326 | const auto missing_bits = sync_event->scope.mask_param & ~src_exec_scope.mask_param; |
| 5327 | // Issue error message that event waited for is not in wait events scope |
| 5328 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 5329 | const char *const message = |
| 5330 | "%s: %s stageMask %" PRIx64 " includes bits not present in srcStageMask 0x%" PRIx64 |
| 5331 | ". Bits missing from srcStageMask %s. %s"; |
| 5332 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5333 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5334 | sync_event->scope.mask_param, src_exec_scope.mask_param, |
| 5335 | sync_utils::StringPipelineStageFlags(missing_bits).c_str(), ignored); |
| 5336 | break; |
| 5337 | } |
| 5338 | case SyncEventState::SetVsWait2: { |
| 5339 | skip |= sync_state.LogError(event_handle, "VUID-vkCmdWaitEvents2KHR-pEvents-03837", |
| 5340 | "%s: Follows set of %s by %s. Disallowed.", CmdName(), |
| 5341 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5342 | CommandTypeString(sync_event->last_command)); |
| 5343 | break; |
| 5344 | } |
| 5345 | default: |
| 5346 | assert(ignore_reason == SyncEventState::NotIgnored); |
| 5347 | } |
| 5348 | } else if (barrier_set.image_memory_barriers.size()) { |
| 5349 | const auto &image_memory_barriers = barrier_set.image_memory_barriers; |
| 5350 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5351 | assert(context); |
| 5352 | for (const auto &image_memory_barrier : image_memory_barriers) { |
| 5353 | if (image_memory_barrier.old_layout == image_memory_barrier.new_layout) continue; |
| 5354 | const auto *image_state = image_memory_barrier.image.get(); |
| 5355 | if (!image_state) continue; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5356 | const auto &subresource_range = image_memory_barrier.range; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5357 | const auto &src_access_scope = image_memory_barrier.barrier.src_access_scope; |
| 5358 | const auto hazard = |
| 5359 | context->DetectImageBarrierHazard(*image_state, sync_event->scope.exec_scope, src_access_scope, |
| 5360 | subresource_range, *sync_event, AccessContext::DetectOptions::kDetectAll); |
| 5361 | if (hazard.hazard) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5362 | skip |= sync_state.LogError(image_state->image(), string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5363 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5364 | string_SyncHazard(hazard.hazard), image_memory_barrier.index, |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5365 | sync_state.report_data->FormatHandle(image_state->image()).c_str(), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5366 | cb_context.FormatUsage(hazard).c_str()); |
| 5367 | break; |
| 5368 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5369 | } |
| 5370 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5371 | // TODO: Add infrastructure for checking pDependencyInfo's vs. CmdSetEvent2 VUID - vkCmdWaitEvents2KHR - pEvents - |
| 5372 | // 03839 |
| 5373 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5374 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5375 | |
| 5376 | // 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] | 5377 | 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] | 5378 | if (extra_stage_bits) { |
| 5379 | // 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] | 5380 | // NOTE: This isn't exactly the right VUID for WaitEvents2, but it's as close as we currently have support for |
| 5381 | const char *const vuid = |
| 5382 | (CMD_WAITEVENTS == cmd_) ? "VUID-vkCmdWaitEvents-srcStageMask-01158" : "VUID-vkCmdWaitEvents2KHR-pEvents-03838"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5383 | const char *const message = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5384 | "%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] | 5385 | if (events_not_found) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5386 | 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] | 5387 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5388 | " vkCmdSetEvent may be in previously submitted command buffer."); |
| 5389 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5390 | 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] | 5391 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), ""); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5392 | } |
| 5393 | } |
| 5394 | return skip; |
| 5395 | } |
| 5396 | |
| 5397 | struct SyncOpWaitEventsFunctorFactory { |
| 5398 | using BarrierOpFunctor = WaitEventBarrierOp; |
| 5399 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5400 | using GlobalBarrierOpFunctor = WaitEventBarrierOp; |
| 5401 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5402 | using BufferRange = EventSimpleRangeGenerator; |
| 5403 | using ImageRange = EventImageRangeGenerator; |
| 5404 | using GlobalRange = EventSimpleRangeGenerator; |
| 5405 | |
| 5406 | // Need to restrict to only valid exec and access scope for this event |
| 5407 | // Pass by value is intentional to get a copy we can change without modifying the passed barrier |
| 5408 | SyncBarrier RestrictToEvent(SyncBarrier barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 5409 | 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] | 5410 | barrier.src_access_scope = sync_event->scope.valid_accesses & barrier.src_access_scope; |
| 5411 | return barrier; |
| 5412 | } |
| 5413 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier_arg, bool layout_transition) const { |
| 5414 | auto barrier = RestrictToEvent(barrier_arg); |
| 5415 | return ApplyFunctor(BarrierOpFunctor(sync_event->first_scope_tag, barrier, layout_transition)); |
| 5416 | } |
| 5417 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, const ResourceUsageTag &tag) const { |
| 5418 | return GlobalApplyFunctor(false /* don't resolve */, size_hint, tag); |
| 5419 | } |
| 5420 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier_arg) const { |
| 5421 | auto barrier = RestrictToEvent(barrier_arg); |
| 5422 | return GlobalBarrierOpFunctor(sync_event->first_scope_tag, barrier, false); |
| 5423 | } |
| 5424 | |
| 5425 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range_arg) const { |
| 5426 | const AccessAddressType address_type = GetAccessAddressType(buffer); |
| 5427 | const auto base_address = ResourceBaseAddress(buffer); |
| 5428 | ResourceAccessRange range = SimpleBinding(buffer) ? (range_arg + base_address) : ResourceAccessRange(); |
| 5429 | EventSimpleRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), range); |
| 5430 | return filtered_range_gen; |
| 5431 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5432 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5433 | if (!SimpleBinding(image)) return ImageRange(); |
| 5434 | const auto address_type = GetAccessAddressType(image); |
| 5435 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5436 | subresource_adapter::ImageRangeGenerator image_range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5437 | EventImageRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), image_range_gen); |
| 5438 | |
| 5439 | return filtered_range_gen; |
| 5440 | } |
| 5441 | GlobalRange MakeGlobalRangeGen(AccessAddressType address_type) const { |
| 5442 | return EventSimpleRangeGenerator(sync_event->FirstScope(address_type), kFullRange); |
| 5443 | } |
| 5444 | SyncOpWaitEventsFunctorFactory(SyncEventState *sync_event_) : sync_event(sync_event_) { assert(sync_event); } |
| 5445 | SyncEventState *sync_event; |
| 5446 | }; |
| 5447 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5448 | void SyncOpWaitEvents::Record(CommandBufferAccessContext *cb_context) const { |
| 5449 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5450 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5451 | assert(access_context); |
| 5452 | if (!access_context) return; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5453 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5454 | assert(events_context); |
| 5455 | if (!events_context) return; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5456 | |
| 5457 | // Unlike PipelineBarrier, WaitEvent is *not* limited to accesses within the current subpass (if any) and thus needs to import |
| 5458 | // all accesses. Can instead import for all first_scopes, or a union of them, if this becomes a performance/memory issue, |
| 5459 | // but with no idea of the performance of the union, nor of whether it even matters... take the simplest approach here, |
| 5460 | access_context->ResolvePreviousAccesses(); |
| 5461 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5462 | // TODO... this needs change the SyncEventContext it's using depending on whether this is replay... the recorded |
| 5463 | // 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] | 5464 | size_t barrier_set_index = 0; |
| 5465 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 5466 | assert(barriers_.size() == 1 || (barriers_.size() == events_.size())); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5467 | for (auto &event_shared : events_) { |
| 5468 | if (!event_shared.get()) continue; |
| 5469 | auto *sync_event = events_context->GetFromShared(event_shared); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5470 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5471 | sync_event->last_command = cmd_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5472 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5473 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5474 | const auto &dst = barrier_set.dst_exec_scope; |
| 5475 | if (!sync_event->IsIgnoredByWait(cmd_, barrier_set.src_exec_scope.mask_param)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5476 | // These apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 5477 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 5478 | // of the barriers is maintained. |
| 5479 | SyncOpWaitEventsFunctorFactory factory(sync_event); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5480 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5481 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5482 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5483 | |
| 5484 | // Apply the global barrier to the event itself (for race condition tracking) |
| 5485 | // Events don't happen at a stage, so we need to store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 5486 | sync_event->barriers = dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 5487 | sync_event->barriers |= dst.exec_scope; |
| 5488 | } else { |
| 5489 | // We ignored this wait, so we don't have any effective synchronization barriers for it. |
| 5490 | sync_event->barriers = 0U; |
| 5491 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5492 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | // Apply the pending barriers |
| 5496 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
| 5497 | access_context->ApplyToContext(apply_pending_action); |
| 5498 | } |
| 5499 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5500 | bool SyncValidator::PreCallValidateCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 5501 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 5502 | bool skip = false; |
| 5503 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5504 | assert(cb_access_context); |
| 5505 | if (!cb_access_context) return skip; |
| 5506 | |
| 5507 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5508 | assert(context); |
| 5509 | if (!context) return skip; |
| 5510 | |
| 5511 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5512 | |
| 5513 | if (dst_buffer) { |
| 5514 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 5515 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
| 5516 | if (hazard.hazard) { |
| 5517 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5518 | "vkCmdWriteBufferMarkerAMD2: Hazard %s for dstBuffer %s. Access info %s.", |
| 5519 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), |
| 5520 | string_UsageTag(hazard.tag).c_str()); |
| 5521 | } |
| 5522 | } |
| 5523 | return skip; |
| 5524 | } |
| 5525 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5526 | 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] | 5527 | events_.reserve(event_count); |
| 5528 | for (uint32_t event_index = 0; event_index < event_count; event_index++) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5529 | events_.emplace_back(sync_state.GetShared<EVENT_STATE>(events[event_index])); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5530 | } |
| 5531 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5532 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5533 | 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] | 5534 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5535 | : SyncOpBase(cmd), |
| 5536 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
| 5537 | exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5538 | |
| 5539 | bool SyncOpResetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5540 | auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5541 | assert(events_context); |
| 5542 | bool skip = false; |
| 5543 | if (!events_context) return skip; |
| 5544 | |
| 5545 | const auto &sync_state = cb_context.GetSyncState(); |
| 5546 | const auto *sync_event = events_context->Get(event_); |
| 5547 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5548 | |
| 5549 | const char *const set_wait = |
| 5550 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 5551 | "hazards."; |
| 5552 | const char *message = set_wait; // Only one message this call. |
| 5553 | if (!sync_event->HasBarrier(exec_scope_.mask_param, exec_scope_.exec_scope)) { |
| 5554 | const char *vuid = nullptr; |
| 5555 | switch (sync_event->last_command) { |
| 5556 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5557 | case CMD_SETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5558 | // Needs a barrier between set and reset |
| 5559 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-set"; |
| 5560 | break; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5561 | case CMD_WAITEVENTS: |
| 5562 | case CMD_WAITEVENTS2KHR: { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5563 | // Needs to be in the barriers chain (either because of a barrier, or because of dstStageMask |
| 5564 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-wait"; |
| 5565 | break; |
| 5566 | } |
| 5567 | default: |
| 5568 | // The only other valid last command that wasn't one. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5569 | assert((sync_event->last_command == CMD_NONE) || (sync_event->last_command == CMD_RESETEVENT) || |
| 5570 | (sync_event->last_command == CMD_RESETEVENT2KHR)); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5571 | break; |
| 5572 | } |
| 5573 | if (vuid) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5574 | skip |= sync_state.LogError(event_->event(), vuid, message, CmdName(), |
| 5575 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5576 | CommandTypeString(sync_event->last_command)); |
| 5577 | } |
| 5578 | } |
| 5579 | return skip; |
| 5580 | } |
| 5581 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5582 | void SyncOpResetEvent::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5583 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5584 | assert(events_context); |
| 5585 | if (!events_context) return; |
| 5586 | |
| 5587 | auto *sync_event = events_context->GetFromShared(event_); |
| 5588 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5589 | |
| 5590 | // Update the event state |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5591 | sync_event->last_command = cmd_; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5592 | sync_event->unsynchronized_set = CMD_NONE; |
| 5593 | sync_event->ResetFirstScope(); |
| 5594 | sync_event->barriers = 0U; |
| 5595 | } |
| 5596 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5597 | 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] | 5598 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5599 | : SyncOpBase(cmd), |
| 5600 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5601 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)), |
| 5602 | dep_info_() {} |
| 5603 | |
| 5604 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
| 5605 | const VkDependencyInfoKHR &dep_info) |
| 5606 | : SyncOpBase(cmd), |
| 5607 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
| 5608 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, sync_utils::GetGlobalStageMasks(dep_info).src)), |
| 5609 | dep_info_(new safe_VkDependencyInfoKHR(&dep_info)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5610 | |
| 5611 | bool SyncOpSetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5612 | // 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] | 5613 | bool skip = false; |
| 5614 | |
| 5615 | const auto &sync_state = cb_context.GetSyncState(); |
| 5616 | auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5617 | assert(events_context); |
| 5618 | if (!events_context) return skip; |
| 5619 | |
| 5620 | const auto *sync_event = events_context->Get(event_); |
| 5621 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5622 | |
| 5623 | const char *const reset_set = |
| 5624 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 5625 | "hazards."; |
| 5626 | const char *const wait = |
| 5627 | "%s: %s %s operation following %s without intervening vkCmdResetEvent, may result in data hazard and is ignored."; |
| 5628 | |
| 5629 | 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] | 5630 | const char *vuid_stem = nullptr; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5631 | const char *message = nullptr; |
| 5632 | switch (sync_event->last_command) { |
| 5633 | case CMD_RESETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5634 | case CMD_RESETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5635 | // Needs a barrier between reset and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5636 | vuid_stem = "-missingbarrier-reset"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5637 | message = reset_set; |
| 5638 | break; |
| 5639 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5640 | case CMD_SETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5641 | // Needs a barrier between set and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5642 | vuid_stem = "-missingbarrier-set"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5643 | message = reset_set; |
| 5644 | break; |
| 5645 | case CMD_WAITEVENTS: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5646 | case CMD_WAITEVENTS2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5647 | // Needs a barrier or is in second execution scope |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5648 | vuid_stem = "-missingbarrier-wait"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5649 | message = wait; |
| 5650 | break; |
| 5651 | default: |
| 5652 | // The only other valid last command that wasn't one. |
| 5653 | assert(sync_event->last_command == CMD_NONE); |
| 5654 | break; |
| 5655 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5656 | if (vuid_stem) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5657 | assert(nullptr != message); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5658 | std::string vuid("SYNC-"); |
| 5659 | vuid.append(CmdName()).append(vuid_stem); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 5660 | skip |= sync_state.LogError(event_->event(), vuid.c_str(), message, CmdName(), |
| 5661 | sync_state.report_data->FormatHandle(event_->event()).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5662 | CommandTypeString(sync_event->last_command)); |
| 5663 | } |
| 5664 | } |
| 5665 | |
| 5666 | return skip; |
| 5667 | } |
| 5668 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5669 | void SyncOpSetEvent::Record(CommandBufferAccessContext *cb_context) const { |
| 5670 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5671 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5672 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5673 | assert(events_context); |
| 5674 | if (!events_context) return; |
| 5675 | |
| 5676 | auto *sync_event = events_context->GetFromShared(event_); |
| 5677 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5678 | |
| 5679 | // NOTE: We're going to simply record the sync scope here, as anything else would be implementation defined/undefined |
| 5680 | // and we're issuing errors re: missing barriers between event commands, which if the user fixes would fix |
| 5681 | // any issues caused by naive scope setting here. |
| 5682 | |
| 5683 | // What happens with two SetEvent is that one cannot know what group of operations will be waited for. |
| 5684 | // Given: |
| 5685 | // Stuff1; SetEvent; Stuff2; SetEvent; WaitEvents; |
| 5686 | // WaitEvents cannot know which of Stuff1, Stuff2, or both has completed execution. |
| 5687 | |
| 5688 | if (!sync_event->HasBarrier(src_exec_scope_.mask_param, src_exec_scope_.exec_scope)) { |
| 5689 | sync_event->unsynchronized_set = sync_event->last_command; |
| 5690 | sync_event->ResetFirstScope(); |
| 5691 | } else if (sync_event->scope.exec_scope == 0) { |
| 5692 | // We only set the scope if there isn't one |
| 5693 | sync_event->scope = src_exec_scope_; |
| 5694 | |
| 5695 | auto set_scope = [&sync_event](AccessAddressType address_type, const ResourceAccessRangeMap::value_type &access) { |
| 5696 | auto &scope_map = sync_event->first_scope[static_cast<size_t>(address_type)]; |
| 5697 | if (access.second.InSourceScopeOrChain(sync_event->scope.exec_scope, sync_event->scope.valid_accesses)) { |
| 5698 | scope_map.insert(scope_map.end(), std::make_pair(access.first, true)); |
| 5699 | } |
| 5700 | }; |
| 5701 | access_context->ForAll(set_scope); |
| 5702 | sync_event->unsynchronized_set = CMD_NONE; |
| 5703 | sync_event->first_scope_tag = tag; |
| 5704 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5705 | // TODO: Store dep_info_ shared ptr in sync_state for WaitEvents2 validation |
| 5706 | sync_event->last_command = cmd_; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5707 | sync_event->barriers = 0U; |
| 5708 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 5709 | |
| 5710 | SyncOpBeginRenderPass::SyncOpBeginRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, |
| 5711 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 5712 | const VkSubpassBeginInfo *pSubpassBeginInfo, const char *cmd_name) |
| 5713 | : SyncOpBase(cmd, cmd_name) { |
| 5714 | if (pRenderPassBegin) { |
| 5715 | rp_state_ = sync_state.GetShared<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
| 5716 | renderpass_begin_info_ = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
| 5717 | const auto *fb_state = sync_state.Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
| 5718 | if (fb_state) { |
| 5719 | shared_attachments_ = sync_state.GetSharedAttachmentViews(*renderpass_begin_info_.ptr(), *fb_state); |
| 5720 | // TODO: Revisit this when all attachment validation is through SyncOps to see if we can discard the plain pointer copy |
| 5721 | // Note that this a safe to presist as long as shared_attachments is not cleared |
| 5722 | attachments_.reserve(shared_attachments_.size()); |
sfricke-samsung | 01c9ae9 | 2021-02-09 22:30:52 -0800 | [diff] [blame] | 5723 | for (const auto &attachment : shared_attachments_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 5724 | attachments_.emplace_back(attachment.get()); |
| 5725 | } |
| 5726 | } |
| 5727 | if (pSubpassBeginInfo) { |
| 5728 | subpass_begin_info_ = safe_VkSubpassBeginInfo(pSubpassBeginInfo); |
| 5729 | } |
| 5730 | } |
| 5731 | } |
| 5732 | |
| 5733 | bool SyncOpBeginRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5734 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 5735 | bool skip = false; |
| 5736 | |
| 5737 | assert(rp_state_.get()); |
| 5738 | if (nullptr == rp_state_.get()) return skip; |
| 5739 | auto &rp_state = *rp_state_.get(); |
| 5740 | |
| 5741 | const uint32_t subpass = 0; |
| 5742 | |
| 5743 | // Construct the state we can use to validate against... (since validation is const and RecordCmdBeginRenderPass |
| 5744 | // hasn't happened yet) |
| 5745 | const std::vector<AccessContext> empty_context_vector; |
| 5746 | AccessContext temp_context(subpass, cb_context.GetQueueFlags(), rp_state.subpass_dependencies, empty_context_vector, |
| 5747 | cb_context.GetCurrentAccessContext()); |
| 5748 | |
| 5749 | // Validate attachment operations |
| 5750 | if (attachments_.size() == 0) return skip; |
| 5751 | const auto &render_area = renderpass_begin_info_.renderArea; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 5752 | |
| 5753 | // Since the isn't a valid RenderPassAccessContext until Record, needs to create the view/generator list... we could limit this |
| 5754 | // by predicating on whether subpass 0 uses the attachment if it is too expensive to create the full list redundantly here. |
| 5755 | // More broadly we could look at thread specific state shared between Validate and Record as is done for other heavyweight |
| 5756 | // operations (though it's currently a messy approach) |
| 5757 | AttachmentViewGenVector view_gens = RenderPassAccessContext::CreateAttachmentViewGen(render_area, attachments_); |
| 5758 | 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] | 5759 | |
| 5760 | // Validate load operations if there were no layout transition hazards |
| 5761 | if (!skip) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 5762 | temp_context.RecordLayoutTransitions(rp_state, subpass, view_gens, kCurrentCommandTag); |
| 5763 | 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] | 5764 | } |
| 5765 | |
| 5766 | return skip; |
| 5767 | } |
| 5768 | |
| 5769 | void SyncOpBeginRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
| 5770 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5771 | assert(rp_state_.get()); |
| 5772 | if (nullptr == rp_state_.get()) return; |
| 5773 | const auto tag = cb_context->NextCommandTag(cmd_); |
| 5774 | cb_context->RecordBeginRenderPass(*rp_state_.get(), renderpass_begin_info_.renderArea, attachments_, tag); |
| 5775 | } |
| 5776 | |
| 5777 | SyncOpNextSubpass::SyncOpNextSubpass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 5778 | const VkSubpassEndInfo *pSubpassEndInfo, const char *name_override) |
| 5779 | : SyncOpBase(cmd, name_override) { |
| 5780 | if (pSubpassBeginInfo) { |
| 5781 | subpass_begin_info_.initialize(pSubpassBeginInfo); |
| 5782 | } |
| 5783 | if (pSubpassEndInfo) { |
| 5784 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 5785 | } |
| 5786 | } |
| 5787 | |
| 5788 | bool SyncOpNextSubpass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5789 | bool skip = false; |
| 5790 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 5791 | if (!renderpass_context) return skip; |
| 5792 | |
| 5793 | skip |= renderpass_context->ValidateNextSubpass(cb_context.GetExecutionContext(), CmdName()); |
| 5794 | return skip; |
| 5795 | } |
| 5796 | |
| 5797 | void SyncOpNextSubpass::Record(CommandBufferAccessContext *cb_context) const { |
| 5798 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5799 | cb_context->RecordNextSubpass(cmd_); |
| 5800 | } |
| 5801 | |
| 5802 | SyncOpEndRenderPass::SyncOpEndRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassEndInfo *pSubpassEndInfo, |
| 5803 | const char *name_override) |
| 5804 | : SyncOpBase(cmd, name_override) { |
| 5805 | if (pSubpassEndInfo) { |
| 5806 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 5807 | } |
| 5808 | } |
| 5809 | |
| 5810 | bool SyncOpEndRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5811 | bool skip = false; |
| 5812 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 5813 | |
| 5814 | if (!renderpass_context) return skip; |
| 5815 | skip |= renderpass_context->ValidateEndRenderPass(cb_context.GetExecutionContext(), CmdName()); |
| 5816 | return skip; |
| 5817 | } |
| 5818 | |
| 5819 | void SyncOpEndRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
| 5820 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5821 | cb_context->RecordEndRenderPass(cmd_); |
| 5822 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5823 | |
| 5824 | void SyncValidator::PreCallRecordCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 5825 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
| 5826 | StateTracker::PreCallRecordCmdWriteBufferMarker2AMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
| 5827 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5828 | assert(cb_access_context); |
| 5829 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 5830 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5831 | assert(context); |
| 5832 | |
| 5833 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5834 | |
| 5835 | if (dst_buffer) { |
| 5836 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 5837 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
| 5838 | } |
| 5839 | } |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 5840 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 5841 | AttachmentViewGen::AttachmentViewGen(const IMAGE_VIEW_STATE *view, const VkOffset3D &offset, const VkExtent3D &extent) |
| 5842 | : view_(view), view_mask_(), gen_store_() { |
| 5843 | if (!view_ || !view_->image_state || !SimpleBinding(*view_->image_state)) return; |
| 5844 | const IMAGE_STATE &image_state = *view_->image_state.get(); |
| 5845 | const auto base_address = ResourceBaseAddress(image_state); |
| 5846 | const auto *encoder = image_state.fragment_encoder.get(); |
| 5847 | if (!encoder) return; |
| 5848 | const VkOffset3D zero_offset = {0, 0, 0}; |
| 5849 | const VkExtent3D &image_extent = image_state.createInfo.extent; |
| 5850 | // Intentional copy |
| 5851 | VkImageSubresourceRange subres_range = view_->normalized_subresource_range; |
| 5852 | view_mask_ = subres_range.aspectMask; |
| 5853 | gen_store_[Gen::kViewSubresource].emplace(*encoder, subres_range, zero_offset, image_extent, base_address); |
| 5854 | gen_store_[Gen::kRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 5855 | |
| 5856 | const auto depth = view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT; |
| 5857 | if (depth && (depth != view_mask_)) { |
| 5858 | subres_range.aspectMask = depth; |
| 5859 | gen_store_[Gen::kDepthOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 5860 | } |
| 5861 | const auto stencil = view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT; |
| 5862 | if (stencil && (stencil != view_mask_)) { |
| 5863 | subres_range.aspectMask = stencil; |
| 5864 | gen_store_[Gen::kStencilOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 5865 | } |
| 5866 | } |
| 5867 | |
| 5868 | const ImageRangeGen *AttachmentViewGen::GetRangeGen(AttachmentViewGen::Gen gen_type) const { |
| 5869 | const ImageRangeGen *got = nullptr; |
| 5870 | switch (gen_type) { |
| 5871 | case kViewSubresource: |
| 5872 | got = &gen_store_[kViewSubresource]; |
| 5873 | break; |
| 5874 | case kRenderArea: |
| 5875 | got = &gen_store_[kRenderArea]; |
| 5876 | break; |
| 5877 | case kDepthOnlyRenderArea: |
| 5878 | got = |
| 5879 | (view_mask_ == VK_IMAGE_ASPECT_DEPTH_BIT) ? &gen_store_[Gen::kRenderArea] : &gen_store_[Gen::kDepthOnlyRenderArea]; |
| 5880 | break; |
| 5881 | case kStencilOnlyRenderArea: |
| 5882 | got = (view_mask_ == VK_IMAGE_ASPECT_STENCIL_BIT) ? &gen_store_[Gen::kRenderArea] |
| 5883 | : &gen_store_[Gen::kStencilOnlyRenderArea]; |
| 5884 | break; |
| 5885 | default: |
| 5886 | assert(got); |
| 5887 | } |
| 5888 | return got; |
| 5889 | } |
| 5890 | |
| 5891 | AttachmentViewGen::Gen AttachmentViewGen::GetDepthStencilRenderAreaGenType(bool depth_op, bool stencil_op) const { |
| 5892 | assert(IsValid()); |
| 5893 | assert(view_mask_ & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); |
| 5894 | if (depth_op) { |
| 5895 | assert(view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 5896 | if (stencil_op) { |
| 5897 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 5898 | return kRenderArea; |
| 5899 | } |
| 5900 | return kDepthOnlyRenderArea; |
| 5901 | } |
| 5902 | if (stencil_op) { |
| 5903 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 5904 | return kStencilOnlyRenderArea; |
| 5905 | } |
| 5906 | |
| 5907 | assert(depth_op || stencil_op); |
| 5908 | return kRenderArea; |
| 5909 | } |
| 5910 | |
| 5911 | AccessAddressType AttachmentViewGen::GetAddressType() const { return AccessContext::ImageAddressType(*view_->image_state); } |