John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2019-2021 The Khronos Group Inc. |
| 2 | * Copyright (c) 2019-2021 Valve Corporation |
| 3 | * Copyright (c) 2019-2021 LunarG, Inc. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | * Author: John Zulauf <jzulauf@lunarg.com> |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 18 | * Author: Locke Lin <locke@lunarg.com> |
| 19 | * Author: Jeremy Gebben <jeremyg@lunarg.com> |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <limits> |
| 23 | #include <vector> |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 24 | #include <memory> |
| 25 | #include <bitset> |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 26 | #include "synchronization_validation.h" |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 27 | #include "sync_utils.h" |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 28 | |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 29 | static bool SimpleBinding(const BINDABLE &bindable) { return !bindable.sparse && bindable.binding.mem_state; } |
| 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) { |
| 229 | return bindable.binding.offset + bindable.binding.mem_state->fake_base_address; |
| 230 | } |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 231 | static VkDeviceSize ResourceBaseAddress(const IMAGE_STATE &image_state) { |
| 232 | VkDeviceSize base_address; |
| 233 | if (image_state.is_swapchain_image || (VK_NULL_HANDLE != image_state.bind_swapchain)) { |
| 234 | base_address = image_state.swapchain_fake_address; |
| 235 | } else { |
| 236 | base_address = ResourceBaseAddress(static_cast<const BINDABLE &>(image_state)); |
| 237 | } |
| 238 | return base_address; |
| 239 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 240 | |
locke-lunarg | 3c03800 | 2020-04-30 23:08:08 -0600 | [diff] [blame] | 241 | inline VkDeviceSize GetRealWholeSize(VkDeviceSize offset, VkDeviceSize size, VkDeviceSize whole_size) { |
| 242 | if (size == VK_WHOLE_SIZE) { |
| 243 | return (whole_size - offset); |
| 244 | } |
| 245 | return size; |
| 246 | } |
| 247 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 248 | static inline VkDeviceSize GetBufferWholeSize(const BUFFER_STATE &buf_state, VkDeviceSize offset, VkDeviceSize size) { |
| 249 | return GetRealWholeSize(offset, size, buf_state.createInfo.size); |
| 250 | } |
| 251 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 252 | template <typename T> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 253 | static ResourceAccessRange MakeRange(const T &has_offset_and_size) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 254 | return ResourceAccessRange(has_offset_and_size.offset, (has_offset_and_size.offset + has_offset_and_size.size)); |
| 255 | } |
| 256 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 257 | static ResourceAccessRange MakeRange(VkDeviceSize start, VkDeviceSize size) { return ResourceAccessRange(start, (start + size)); } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 258 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 259 | static inline ResourceAccessRange MakeRange(const BUFFER_STATE &buffer, VkDeviceSize offset, VkDeviceSize size) { |
| 260 | return MakeRange(offset, GetBufferWholeSize(buffer, offset, size)); |
| 261 | } |
| 262 | |
| 263 | static inline ResourceAccessRange MakeRange(const BUFFER_VIEW_STATE &buf_view_state) { |
| 264 | return MakeRange(*buf_view_state.buffer_state.get(), buf_view_state.create_info.offset, buf_view_state.create_info.range); |
| 265 | } |
| 266 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 267 | // Range generators for to allow event scope filtration to be limited to the top of the resource access traversal pipeline |
| 268 | // |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 269 | // Note: there is no "begin/end" or reset facility. These are each written as "one time through" generators. |
| 270 | // |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 271 | // Usage: |
| 272 | // Constructor() -- initializes the generator to point to the begin of the space declared. |
| 273 | // * -- the current range of the generator empty signfies end |
| 274 | // ++ -- advance to the next non-empty range (or end) |
| 275 | |
| 276 | // A wrapper for a single range with the same semantics as the actual generators below |
| 277 | template <typename KeyType> |
| 278 | class SingleRangeGenerator { |
| 279 | public: |
| 280 | SingleRangeGenerator(const KeyType &range) : current_(range) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 281 | const KeyType &operator*() const { return current_; } |
| 282 | const KeyType *operator->() const { return ¤t_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 283 | SingleRangeGenerator &operator++() { |
| 284 | current_ = KeyType(); // just one real range |
| 285 | return *this; |
| 286 | } |
| 287 | |
| 288 | bool operator==(const SingleRangeGenerator &other) const { return current_ == other.current_; } |
| 289 | |
| 290 | private: |
| 291 | SingleRangeGenerator() = default; |
| 292 | const KeyType range_; |
| 293 | KeyType current_; |
| 294 | }; |
| 295 | |
| 296 | // Generate the ranges that are the intersection of range and the entries in the FilterMap |
| 297 | template <typename FilterMap, typename KeyType = typename FilterMap::key_type> |
| 298 | class FilteredRangeGenerator { |
| 299 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 300 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 301 | FilteredRangeGenerator() : range_(), filter_(nullptr), filter_pos_(), current_() { |
| 302 | // Default construction for KeyType *must* be empty range |
| 303 | assert(current_.empty()); |
| 304 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 305 | FilteredRangeGenerator(const FilterMap &filter, const KeyType &range) |
| 306 | : range_(range), filter_(&filter), filter_pos_(), current_() { |
| 307 | SeekBegin(); |
| 308 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 309 | FilteredRangeGenerator(const FilteredRangeGenerator &from) = default; |
| 310 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 311 | const KeyType &operator*() const { return current_; } |
| 312 | const KeyType *operator->() const { return ¤t_; } |
| 313 | FilteredRangeGenerator &operator++() { |
| 314 | ++filter_pos_; |
| 315 | UpdateCurrent(); |
| 316 | return *this; |
| 317 | } |
| 318 | |
| 319 | bool operator==(const FilteredRangeGenerator &other) const { return current_ == other.current_; } |
| 320 | |
| 321 | private: |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 322 | void UpdateCurrent() { |
| 323 | if (filter_pos_ != filter_->cend()) { |
| 324 | current_ = range_ & filter_pos_->first; |
| 325 | } else { |
| 326 | current_ = KeyType(); |
| 327 | } |
| 328 | } |
| 329 | void SeekBegin() { |
| 330 | filter_pos_ = filter_->lower_bound(range_); |
| 331 | UpdateCurrent(); |
| 332 | } |
| 333 | const KeyType range_; |
| 334 | const FilterMap *filter_; |
| 335 | typename FilterMap::const_iterator filter_pos_; |
| 336 | KeyType current_; |
| 337 | }; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 338 | using SingleAccessRangeGenerator = SingleRangeGenerator<ResourceAccessRange>; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 339 | using EventSimpleRangeGenerator = FilteredRangeGenerator<SyncEventState::ScopeMap>; |
| 340 | |
| 341 | // Templated to allow for different Range generators or map sources... |
| 342 | |
| 343 | // 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] | 344 | template <typename FilterMap, typename RangeGen, typename KeyType = typename FilterMap::key_type> |
| 345 | class FilteredGeneratorGenerator { |
| 346 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 347 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 348 | FilteredGeneratorGenerator() : filter_(nullptr), gen_(), filter_pos_(), current_() { |
| 349 | // Default construction for KeyType *must* be empty range |
| 350 | assert(current_.empty()); |
| 351 | } |
| 352 | 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] | 353 | SeekBegin(); |
| 354 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 355 | FilteredGeneratorGenerator(const FilteredGeneratorGenerator &from) = default; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 356 | const KeyType &operator*() const { return current_; } |
| 357 | const KeyType *operator->() const { return ¤t_; } |
| 358 | FilteredGeneratorGenerator &operator++() { |
| 359 | KeyType gen_range = GenRange(); |
| 360 | KeyType filter_range = FilterRange(); |
| 361 | current_ = KeyType(); |
| 362 | while (gen_range.non_empty() && filter_range.non_empty() && current_.empty()) { |
| 363 | if (gen_range.end > filter_range.end) { |
| 364 | // if the generated range is beyond the filter_range, advance the filter range |
| 365 | filter_range = AdvanceFilter(); |
| 366 | } else { |
| 367 | gen_range = AdvanceGen(); |
| 368 | } |
| 369 | current_ = gen_range & filter_range; |
| 370 | } |
| 371 | return *this; |
| 372 | } |
| 373 | |
| 374 | bool operator==(const FilteredGeneratorGenerator &other) const { return current_ == other.current_; } |
| 375 | |
| 376 | private: |
| 377 | KeyType AdvanceFilter() { |
| 378 | ++filter_pos_; |
| 379 | auto filter_range = FilterRange(); |
| 380 | if (filter_range.valid()) { |
| 381 | FastForwardGen(filter_range); |
| 382 | } |
| 383 | return filter_range; |
| 384 | } |
| 385 | KeyType AdvanceGen() { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 386 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 387 | auto gen_range = GenRange(); |
| 388 | if (gen_range.valid()) { |
| 389 | FastForwardFilter(gen_range); |
| 390 | } |
| 391 | return gen_range; |
| 392 | } |
| 393 | |
| 394 | KeyType FilterRange() const { return (filter_pos_ != filter_->cend()) ? filter_pos_->first : KeyType(); } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 395 | KeyType GenRange() const { return *gen_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 396 | |
| 397 | KeyType FastForwardFilter(const KeyType &range) { |
| 398 | auto filter_range = FilterRange(); |
| 399 | int retry_count = 0; |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 400 | const static int kRetryLimit = 2; // TODO -- determine whether this limit is optimal |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 401 | while (!filter_range.empty() && (filter_range.end <= range.begin)) { |
| 402 | if (retry_count < kRetryLimit) { |
| 403 | ++filter_pos_; |
| 404 | filter_range = FilterRange(); |
| 405 | retry_count++; |
| 406 | } else { |
| 407 | // Okay we've tried walking, do a seek. |
| 408 | filter_pos_ = filter_->lower_bound(range); |
| 409 | break; |
| 410 | } |
| 411 | } |
| 412 | return FilterRange(); |
| 413 | } |
| 414 | |
| 415 | // TODO: Consider adding "seek" (or an absolute bound "get" to range generators to make this walk |
| 416 | // faster. |
| 417 | KeyType FastForwardGen(const KeyType &range) { |
| 418 | auto gen_range = GenRange(); |
| 419 | while (!gen_range.empty() && (gen_range.end <= range.begin)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 420 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 421 | gen_range = GenRange(); |
| 422 | } |
| 423 | return gen_range; |
| 424 | } |
| 425 | |
| 426 | void SeekBegin() { |
| 427 | auto gen_range = GenRange(); |
| 428 | if (gen_range.empty()) { |
| 429 | current_ = KeyType(); |
| 430 | filter_pos_ = filter_->cend(); |
| 431 | } else { |
| 432 | filter_pos_ = filter_->lower_bound(gen_range); |
| 433 | current_ = gen_range & FilterRange(); |
| 434 | } |
| 435 | } |
| 436 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 437 | const FilterMap *filter_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 438 | RangeGen gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 439 | typename FilterMap::const_iterator filter_pos_; |
| 440 | KeyType current_; |
| 441 | }; |
| 442 | |
| 443 | using EventImageRangeGenerator = FilteredGeneratorGenerator<SyncEventState::ScopeMap, subresource_adapter::ImageRangeGenerator>; |
| 444 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 445 | 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] | 446 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 447 | ResourceAccessRange GetBufferRange(VkDeviceSize offset, VkDeviceSize buf_whole_size, uint32_t first_index, uint32_t count, |
| 448 | VkDeviceSize stride) { |
| 449 | VkDeviceSize range_start = offset + first_index * stride; |
| 450 | VkDeviceSize range_size = 0; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 451 | if (count == UINT32_MAX) { |
| 452 | range_size = buf_whole_size - range_start; |
| 453 | } else { |
| 454 | range_size = count * stride; |
| 455 | } |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 456 | return MakeRange(range_start, range_size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 457 | } |
| 458 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 459 | SyncStageAccessIndex GetSyncStageAccessIndexsByDescriptorSet(VkDescriptorType descriptor_type, const interface_var &descriptor_data, |
| 460 | VkShaderStageFlagBits stage_flag) { |
| 461 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 462 | assert(stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT); |
| 463 | return SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ; |
| 464 | } |
| 465 | auto stage_access = syncStageAccessMaskByShaderStage.find(stage_flag); |
| 466 | if (stage_access == syncStageAccessMaskByShaderStage.end()) { |
| 467 | assert(0); |
| 468 | } |
| 469 | if (descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) { |
| 470 | return stage_access->second.uniform_read; |
| 471 | } |
| 472 | |
| 473 | // If the desriptorSet is writable, we don't need to care SHADER_READ. SHADER_WRITE is enough. |
| 474 | // Because if write hazard happens, read hazard might or might not happen. |
| 475 | // But if write hazard doesn't happen, read hazard is impossible to happen. |
| 476 | if (descriptor_data.is_writable) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 477 | return stage_access->second.storage_write; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 478 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 479 | // TODO: sampled_read |
| 480 | return stage_access->second.storage_read; |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 481 | } |
| 482 | |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 483 | bool IsImageLayoutDepthWritable(VkImageLayout image_layout) { |
| 484 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 485 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL || |
| 486 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) |
| 487 | ? true |
| 488 | : false; |
| 489 | } |
| 490 | |
| 491 | bool IsImageLayoutStencilWritable(VkImageLayout image_layout) { |
| 492 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 493 | image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL || |
| 494 | image_layout == VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL) |
| 495 | ? true |
| 496 | : false; |
| 497 | } |
| 498 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 499 | // 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] | 500 | template <typename Action> |
| 501 | static void ApplyOverImageRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &subresource_range_arg, |
| 502 | Action &action) { |
| 503 | // At this point the "apply over range" logic only supports a single memory binding |
| 504 | if (!SimpleBinding(image_state)) return; |
| 505 | auto subresource_range = NormalizeSubresourceRange(image_state.createInfo, subresource_range_arg); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 506 | const auto base_address = ResourceBaseAddress(image_state); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 507 | subresource_adapter::ImageRangeGenerator range_gen(*image_state.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
| 508 | image_state.createInfo.extent, base_address); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 509 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 510 | action(*range_gen); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 514 | // Tranverse the attachment resolves for this a specific subpass, and do action() to them. |
| 515 | // Used by both validation and record operations |
| 516 | // |
| 517 | // The signature for Action() reflect the needs of both uses. |
| 518 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 519 | void ResolveOperation(Action &action, const RENDER_PASS_STATE &rp_state, const AttachmentViewGenVector &attachment_views, |
| 520 | uint32_t subpass) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 521 | const auto &rp_ci = rp_state.createInfo; |
| 522 | const auto *attachment_ci = rp_ci.pAttachments; |
| 523 | const auto &subpass_ci = rp_ci.pSubpasses[subpass]; |
| 524 | |
| 525 | // Color resolves -- require an inuse color attachment and a matching inuse resolve attachment |
| 526 | const auto *color_attachments = subpass_ci.pColorAttachments; |
| 527 | const auto *color_resolve = subpass_ci.pResolveAttachments; |
| 528 | if (color_resolve && color_attachments) { |
| 529 | for (uint32_t i = 0; i < subpass_ci.colorAttachmentCount; i++) { |
| 530 | const auto &color_attach = color_attachments[i].attachment; |
| 531 | const auto &resolve_attach = subpass_ci.pResolveAttachments[i].attachment; |
| 532 | if ((color_attach != VK_ATTACHMENT_UNUSED) && (resolve_attach != VK_ATTACHMENT_UNUSED)) { |
| 533 | action("color", "resolve read", color_attach, resolve_attach, attachment_views[color_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 534 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, |
| 535 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 536 | action("color", "resolve write", color_attach, resolve_attach, attachment_views[resolve_attach], |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 537 | AttachmentViewGen::Gen::kRenderArea, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 538 | SyncOrdering::kColorAttachment); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | // Depth stencil resolve only if the extension is present |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 544 | const auto ds_resolve = LvlFindInChain<VkSubpassDescriptionDepthStencilResolve>(subpass_ci.pNext); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 545 | if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment && |
| 546 | (ds_resolve->pDepthStencilResolveAttachment->attachment != VK_ATTACHMENT_UNUSED) && subpass_ci.pDepthStencilAttachment && |
| 547 | (subpass_ci.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) { |
| 548 | const auto src_at = subpass_ci.pDepthStencilAttachment->attachment; |
| 549 | const auto src_ci = attachment_ci[src_at]; |
| 550 | // The formats are required to match so we can pick either |
| 551 | const bool resolve_depth = (ds_resolve->depthResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasDepth(src_ci.format); |
| 552 | const bool resolve_stencil = (ds_resolve->stencilResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasStencil(src_ci.format); |
| 553 | const auto dst_at = ds_resolve->pDepthStencilResolveAttachment->attachment; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 554 | |
| 555 | // Figure out which aspects are actually touched during resolve operations |
| 556 | const char *aspect_string = nullptr; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 557 | AttachmentViewGen::Gen gen_type = AttachmentViewGen::Gen::kRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 558 | if (resolve_depth && resolve_stencil) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 559 | aspect_string = "depth/stencil"; |
| 560 | } else if (resolve_depth) { |
| 561 | // Validate depth only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 562 | gen_type = AttachmentViewGen::Gen::kDepthOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 563 | aspect_string = "depth"; |
| 564 | } else if (resolve_stencil) { |
| 565 | // Validate all stencil only |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 566 | gen_type = AttachmentViewGen::Gen::kStencilOnlyRenderArea; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 567 | aspect_string = "stencil"; |
| 568 | } |
| 569 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 570 | if (aspect_string) { |
| 571 | action(aspect_string, "resolve read", src_at, dst_at, attachment_views[src_at], gen_type, |
| 572 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, SyncOrdering::kRaster); |
| 573 | action(aspect_string, "resolve write", src_at, dst_at, attachment_views[dst_at], gen_type, |
| 574 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | // Action for validating resolve operations |
| 580 | class ValidateResolveAction { |
| 581 | public: |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 582 | ValidateResolveAction(VkRenderPass render_pass, uint32_t subpass, const AccessContext &context, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 583 | const CommandExecutionContext &ex_context, const char *func_name) |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 584 | : render_pass_(render_pass), |
| 585 | subpass_(subpass), |
| 586 | context_(context), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 587 | ex_context_(ex_context), |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 588 | func_name_(func_name), |
| 589 | skip_(false) {} |
| 590 | 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] | 591 | const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, |
| 592 | SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 593 | HazardResult hazard; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 594 | hazard = context_.DetectHazard(view_gen, gen_type, current_usage, ordering_rule); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 595 | if (hazard.hazard) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 596 | skip_ |= |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 597 | ex_context_.GetSyncState().LogError(render_pass_, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 598 | "%s: Hazard %s in subpass %" PRIu32 "during %s %s, from attachment %" PRIu32 |
| 599 | " to resolve attachment %" PRIu32 ". Access info %s.", |
| 600 | func_name_, string_SyncHazard(hazard.hazard), subpass_, aspect_name, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 601 | attachment_name, src_at, dst_at, ex_context_.FormatUsage(hazard).c_str()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | // Providing a mechanism for the constructing caller to get the result of the validation |
| 605 | bool GetSkip() const { return skip_; } |
| 606 | |
| 607 | private: |
| 608 | VkRenderPass render_pass_; |
| 609 | const uint32_t subpass_; |
| 610 | const AccessContext &context_; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 611 | const CommandExecutionContext &ex_context_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 612 | const char *func_name_; |
| 613 | bool skip_; |
| 614 | }; |
| 615 | |
| 616 | // Update action for resolve operations |
| 617 | class UpdateStateResolveAction { |
| 618 | public: |
| 619 | UpdateStateResolveAction(AccessContext &context, const ResourceUsageTag &tag) : context_(context), tag_(tag) {} |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 620 | void operator()(const char *, const char *, uint32_t, uint32_t, const AttachmentViewGen &view_gen, |
| 621 | AttachmentViewGen::Gen gen_type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 622 | // Ignores validation only arguments... |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 623 | context_.UpdateAccessState(view_gen, gen_type, current_usage, ordering_rule, tag_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | private: |
| 627 | AccessContext &context_; |
| 628 | const ResourceUsageTag &tag_; |
| 629 | }; |
| 630 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 631 | void HazardResult::Set(const ResourceAccessState *access_state_, SyncStageAccessIndex usage_index_, SyncHazard hazard_, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 632 | const SyncStageAccessFlags &prior_, const ResourceUsageTag &tag_) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 633 | access_state = std::unique_ptr<const ResourceAccessState>(new ResourceAccessState(*access_state_)); |
| 634 | usage_index = usage_index_; |
| 635 | hazard = hazard_; |
| 636 | prior_access = prior_; |
| 637 | tag = tag_; |
| 638 | } |
| 639 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 640 | AccessContext::AccessContext(uint32_t subpass, VkQueueFlags queue_flags, |
| 641 | const std::vector<SubpassDependencyGraphNode> &dependencies, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 642 | const std::vector<AccessContext> &contexts, const AccessContext *external_context) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 643 | Reset(); |
| 644 | const auto &subpass_dep = dependencies[subpass]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 645 | bool has_barrier_from_external = subpass_dep.barrier_from_external.size() > 0U; |
| 646 | prev_.reserve(subpass_dep.prev.size() + (has_barrier_from_external ? 1U : 0U)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 647 | 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] | 648 | for (const auto &prev_dep : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 649 | const auto prev_pass = prev_dep.first->pass; |
| 650 | const auto &prev_barriers = prev_dep.second; |
| 651 | assert(prev_dep.second.size()); |
| 652 | prev_.emplace_back(&contexts[prev_pass], queue_flags, prev_barriers); |
| 653 | prev_by_subpass_[prev_pass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 654 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 655 | |
| 656 | async_.reserve(subpass_dep.async.size()); |
| 657 | for (const auto async_subpass : subpass_dep.async) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 658 | async_.emplace_back(&contexts[async_subpass]); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 659 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 660 | if (has_barrier_from_external) { |
| 661 | // Store the barrier from external with the reat, but save pointer for "by subpass" lookups. |
| 662 | prev_.emplace_back(external_context, queue_flags, subpass_dep.barrier_from_external); |
| 663 | src_external_ = &prev_.back(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 664 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 665 | if (subpass_dep.barrier_to_external.size()) { |
| 666 | dst_external_ = TrackBack(this, queue_flags, subpass_dep.barrier_to_external); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 667 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 668 | } |
| 669 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 670 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 671 | HazardResult AccessContext::DetectPreviousHazard(AccessAddressType type, const Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 672 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 673 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 674 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 675 | |
| 676 | HazardResult hazard; |
| 677 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 678 | hazard = detector.Detect(prev); |
| 679 | } |
| 680 | return hazard; |
| 681 | } |
| 682 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 683 | template <typename Action> |
| 684 | void AccessContext::ForAll(Action &&action) { |
| 685 | for (const auto address_type : kAddressTypes) { |
| 686 | auto &accesses = GetAccessStateMap(address_type); |
| 687 | for (const auto &access : accesses) { |
| 688 | action(address_type, access); |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 693 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 694 | // the DAG of the contexts (for example subpasses) |
| 695 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 696 | HazardResult AccessContext::DetectHazard(AccessAddressType type, const Detector &detector, const ResourceAccessRange &range, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 697 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 698 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 699 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 700 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 701 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 702 | // so we'll check these first |
| 703 | for (const auto &async_context : async_) { |
| 704 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 705 | if (hazard.hazard) return hazard; |
| 706 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 707 | } |
| 708 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 709 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 710 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 711 | const auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame^] | 712 | const auto the_end = accesses.cend(); // End is not invalidated |
| 713 | auto pos = accesses.lower_bound(range); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 714 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 715 | |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame^] | 716 | while (pos != the_end && pos->first.begin < range.end) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 717 | // Cover any leading gap, or gap between entries |
| 718 | if (detect_prev) { |
| 719 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 720 | // Cover any leading gap, or gap between entries |
| 721 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 722 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 723 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 724 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 725 | if (hazard.hazard) return hazard; |
| 726 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 727 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 728 | gap.begin = pos->first.end; |
| 729 | } |
| 730 | |
| 731 | hazard = detector.Detect(pos); |
| 732 | if (hazard.hazard) return hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame^] | 733 | ++pos; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | if (detect_prev) { |
| 737 | // Detect in the trailing empty as needed |
| 738 | gap.end = range.end; |
| 739 | if (gap.non_empty()) { |
| 740 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 741 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | return hazard; |
| 745 | } |
| 746 | |
| 747 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 748 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 749 | HazardResult AccessContext::DetectAsyncHazard(AccessAddressType type, const Detector &detector, |
| 750 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 751 | auto &accesses = GetAccessStateMap(type); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame^] | 752 | auto pos = accesses.lower_bound(range); |
| 753 | const auto the_end = accesses.end(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 754 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 755 | HazardResult hazard; |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame^] | 756 | while (pos != the_end && pos->first.begin < range.end) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 757 | hazard = detector.DetectAsync(pos, start_tag_); |
John Zulauf | 3cafbf7 | 2021-03-26 16:55:19 -0600 | [diff] [blame^] | 758 | if (hazard.hazard) break; |
| 759 | ++pos; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 760 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 761 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 762 | return hazard; |
| 763 | } |
| 764 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 765 | struct ApplySubpassTransitionBarriersAction { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 766 | explicit ApplySubpassTransitionBarriersAction(const std::vector<SyncBarrier> &barriers_) : barriers(barriers_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 767 | void operator()(ResourceAccessState *access) const { |
| 768 | assert(access); |
| 769 | access->ApplyBarriers(barriers, true); |
| 770 | } |
| 771 | const std::vector<SyncBarrier> &barriers; |
| 772 | }; |
| 773 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 774 | struct ApplyTrackbackStackAction { |
| 775 | explicit ApplyTrackbackStackAction(const std::vector<SyncBarrier> &barriers_, |
| 776 | const ResourceAccessStateFunction *previous_barrier_ = nullptr) |
| 777 | : barriers(barriers_), previous_barrier(previous_barrier_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 778 | void operator()(ResourceAccessState *access) const { |
| 779 | assert(access); |
| 780 | assert(!access->HasPendingState()); |
| 781 | access->ApplyBarriers(barriers, false); |
| 782 | access->ApplyPendingBarriers(kCurrentCommandTag); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 783 | if (previous_barrier) { |
| 784 | assert(bool(*previous_barrier)); |
| 785 | (*previous_barrier)(access); |
| 786 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 787 | } |
| 788 | const std::vector<SyncBarrier> &barriers; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 789 | const ResourceAccessStateFunction *previous_barrier; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 790 | }; |
| 791 | |
| 792 | // Splits a single map entry into piece matching the entries in [first, last) the total range over [first, last) must be |
| 793 | // contained with entry. Entry must be an iterator pointing to dest, first and last must be iterators pointing to a |
| 794 | // *different* map from dest. |
| 795 | // Returns the position past the last resolved range -- the entry covering the remainder of entry->first not included in the |
| 796 | // range [first, last) |
| 797 | template <typename BarrierAction> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 798 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 799 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 800 | BarrierAction &barrier_action) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 801 | auto at = entry; |
| 802 | for (auto pos = first; pos != last; ++pos) { |
| 803 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 804 | assert(at->first.includes(pos->first)); |
| 805 | assert(at != dest->end()); |
| 806 | // Trim up at to the same size as the entry to resolve |
| 807 | at = sparse_container::split(at, *dest, pos->first); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 808 | auto access = pos->second; // intentional copy |
| 809 | barrier_action(&access); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 810 | at->second.Resolve(access); |
| 811 | ++at; // Go to the remaining unused section of entry |
| 812 | } |
| 813 | } |
| 814 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 815 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 816 | SyncBarrier merged = {}; |
| 817 | for (const auto &barrier : barriers) { |
| 818 | merged.Merge(barrier); |
| 819 | } |
| 820 | return merged; |
| 821 | } |
| 822 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 823 | template <typename BarrierAction> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 824 | void AccessContext::ResolveAccessRange(AccessAddressType type, const ResourceAccessRange &range, BarrierAction &barrier_action, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 825 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 826 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 827 | if (!range.non_empty()) return; |
| 828 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 829 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 830 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 831 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 832 | if (current->pos_B->valid) { |
| 833 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 834 | auto access = src_pos->second; // intentional copy |
| 835 | barrier_action(&access); |
| 836 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 837 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 838 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 839 | trimmed->second.Resolve(access); |
| 840 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 841 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 842 | 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] | 843 | 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] | 844 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 845 | } else { |
| 846 | // we have to descend to fill this gap |
| 847 | if (recur_to_infill) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 848 | ResourceAccessRange recurrence_range = current_range; |
| 849 | // The current context is empty for the current range, so recur to fill the gap. |
| 850 | // Since we will be recurring back up the DAG, expand the gap descent to cover the full range for which B |
| 851 | // is not valid, to minimize that recurrence |
| 852 | if (current->pos_B.at_end()) { |
| 853 | // Do the remainder here.... |
| 854 | recurrence_range.end = range.end; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 855 | } else { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 856 | // Recur only over the range until B becomes valid (within the limits of range). |
| 857 | 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] | 858 | } |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 859 | ResolvePreviousAccessStack(type, recurrence_range, resolve_map, infill_state, barrier_action); |
| 860 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 861 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 862 | // iterator of the outer while. |
| 863 | |
| 864 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 865 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 866 | // we stepped on the dest map |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 867 | 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] | 868 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 869 | current.seek(seek_to); |
| 870 | } else if (!current->pos_A->valid && infill_state) { |
| 871 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 872 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 873 | 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] | 874 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 875 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 876 | ++current; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 877 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 878 | |
| 879 | // Infill if range goes passed both the current and resolve map prior contents |
| 880 | if (recur_to_infill && (current->range.end < range.end)) { |
| 881 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 882 | ResolvePreviousAccessStack<BarrierAction>(type, trailing_fill_range, resolve_map, infill_state, barrier_action); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 883 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 884 | } |
| 885 | |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 886 | template <typename BarrierAction> |
| 887 | void AccessContext::ResolvePreviousAccessStack(AccessAddressType type, const ResourceAccessRange &range, |
| 888 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 889 | const BarrierAction &previous_barrier) const { |
| 890 | ResourceAccessStateFunction stacked_barrier(std::ref(previous_barrier)); |
| 891 | ResolvePreviousAccess(type, range, descent_map, infill_state, &stacked_barrier); |
| 892 | } |
| 893 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 894 | void AccessContext::ResolvePreviousAccess(AccessAddressType type, const ResourceAccessRange &range, |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 895 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state, |
| 896 | const ResourceAccessStateFunction *previous_barrier) const { |
| 897 | if (prev_.size() == 0) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 898 | if (range.non_empty() && infill_state) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 899 | // Fill the empty poritions of descent_map with the default_state with the barrier function applied (iff present) |
| 900 | ResourceAccessState state_copy; |
| 901 | if (previous_barrier) { |
| 902 | assert(bool(*previous_barrier)); |
| 903 | state_copy = *infill_state; |
| 904 | (*previous_barrier)(&state_copy); |
| 905 | infill_state = &state_copy; |
| 906 | } |
| 907 | sparse_container::update_range_value(*descent_map, range, *infill_state, |
| 908 | sparse_container::value_precedence::prefer_dest); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 909 | } |
| 910 | } else { |
| 911 | // Look for something to fill the gap further along. |
| 912 | for (const auto &prev_dep : prev_) { |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 913 | const ApplyTrackbackStackAction barrier_action(prev_dep.barriers, previous_barrier); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 914 | prev_dep.context->ResolveAccessRange(type, range, barrier_action, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 915 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 916 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 917 | } |
| 918 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 919 | // Non-lazy import of all accesses, WaitEvents needs this. |
| 920 | void AccessContext::ResolvePreviousAccesses() { |
| 921 | ResourceAccessState default_state; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 922 | if (!prev_.size()) return; // If no previous contexts, nothing to do |
| 923 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 924 | for (const auto address_type : kAddressTypes) { |
| 925 | ResolvePreviousAccess(address_type, kFullRange, &GetAccessStateMap(address_type), &default_state); |
| 926 | } |
| 927 | } |
| 928 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 929 | AccessAddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
| 930 | return (image.fragment_encoder->IsLinearImage()) ? AccessAddressType::kLinear : AccessAddressType::kIdealized; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 931 | } |
| 932 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 933 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
| 934 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 935 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE; |
| 936 | return stage_access; |
| 937 | } |
| 938 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
| 939 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 940 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE; |
| 941 | return stage_access; |
| 942 | } |
| 943 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 944 | // Caller must manage returned pointer |
| 945 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 946 | uint32_t subpass, const AttachmentViewGenVector &attachment_views) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 947 | auto *proxy = new AccessContext(context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 948 | proxy->UpdateAttachmentResolveAccess(rp_state, attachment_views, subpass, kCurrentCommandTag); |
| 949 | proxy->UpdateAttachmentStoreAccess(rp_state, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 950 | return proxy; |
| 951 | } |
| 952 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 953 | template <typename BarrierAction> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 954 | void AccessContext::ResolveAccessRange(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 955 | BarrierAction &barrier_action, ResourceAccessRangeMap *descent_map, |
| 956 | const ResourceAccessState *infill_state) const { |
| 957 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 958 | if (!attachment_gen) return; |
| 959 | |
| 960 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 961 | const AccessAddressType address_type = view_gen.GetAddressType(); |
| 962 | for (; range_gen->non_empty(); ++range_gen) { |
| 963 | ResolveAccessRange(address_type, *range_gen, barrier_action, descent_map, infill_state); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 964 | } |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 965 | } |
| 966 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 967 | // 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] | 968 | 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] | 969 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 970 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 971 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 972 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 973 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 974 | // those affects have not been recorded yet. |
| 975 | // |
| 976 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 977 | // to apply and only copy then, if this proves a hot spot. |
| 978 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 979 | TrackBack proxy_track_back; |
| 980 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 981 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 982 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 983 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 984 | |
| 985 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 986 | assert(track_back); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 987 | if (prev_needs_proxy) { |
| 988 | if (!proxy_for_prev) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 989 | proxy_for_prev.reset( |
| 990 | CreateStoreResolveProxyContext(*track_back->context, rp_state, transition.prev_pass, attachment_views)); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 991 | proxy_track_back = *track_back; |
| 992 | proxy_track_back.context = proxy_for_prev.get(); |
| 993 | } |
| 994 | track_back = &proxy_track_back; |
| 995 | } |
| 996 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 997 | if (hazard.hazard) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 998 | skip |= ex_context.GetSyncState().LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 999 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1000 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 1001 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 1002 | string_VkImageLayout(transition.old_layout), |
| 1003 | string_VkImageLayout(transition.new_layout), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1004 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | return skip; |
| 1008 | } |
| 1009 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1010 | 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] | 1011 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1012 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1013 | bool skip = false; |
| 1014 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1015 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1016 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1017 | if (subpass == rp_state.attachment_first_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1018 | const auto &view_gen = attachment_views[i]; |
| 1019 | if (!view_gen.IsValid()) continue; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1020 | const auto &ci = attachment_ci[i]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1021 | |
| 1022 | // Need check in the following way |
| 1023 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 1024 | // vs. transition |
| 1025 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 1026 | // for each aspect loaded. |
| 1027 | |
| 1028 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1029 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1030 | const bool is_color = !(has_depth || has_stencil); |
| 1031 | |
| 1032 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1033 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1034 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1035 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1036 | const char *aspect = nullptr; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1037 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1038 | bool checked_stencil = false; |
| 1039 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1040 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, load_index, SyncOrdering::kColorAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1041 | aspect = "color"; |
| 1042 | } else { |
| 1043 | if (has_depth) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1044 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, load_index, |
| 1045 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1046 | aspect = "depth"; |
| 1047 | } |
| 1048 | if (!hazard.hazard && has_stencil) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1049 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, stencil_load_index, |
| 1050 | SyncOrdering::kDepthStencilAttachment); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1051 | aspect = "stencil"; |
| 1052 | checked_stencil = true; |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | if (hazard.hazard) { |
| 1057 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1058 | const auto &sync_state = ex_context.GetSyncState(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1059 | if (hazard.tag == kCurrentCommandTag) { |
| 1060 | // Hazard vs. ILT |
| 1061 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 1062 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1063 | " aspect %s during load with loadOp %s.", |
| 1064 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string); |
| 1065 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1066 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 1067 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1068 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1069 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1070 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | return skip; |
| 1076 | } |
| 1077 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1078 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 1079 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 1080 | // store is part of the same Next/End operation. |
| 1081 | // The latter is handled in layout transistion validation directly |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1082 | 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] | 1083 | const VkRect2D &render_area, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1084 | const AttachmentViewGenVector &attachment_views, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1085 | bool skip = false; |
| 1086 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1087 | |
| 1088 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1089 | if (subpass == rp_state.attachment_last_subpass[i]) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1090 | const AttachmentViewGen &view_gen = attachment_views[i]; |
| 1091 | if (!view_gen.IsValid()) continue; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1092 | const auto &ci = attachment_ci[i]; |
| 1093 | |
| 1094 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1095 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 1096 | // sake, we treat DONT_CARE as writing. |
| 1097 | const bool has_depth = FormatHasDepth(ci.format); |
| 1098 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1099 | const bool is_color = !(has_depth || has_stencil); |
| 1100 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1101 | if (!has_stencil && !store_op_stores) continue; |
| 1102 | |
| 1103 | HazardResult hazard; |
| 1104 | const char *aspect = nullptr; |
| 1105 | bool checked_stencil = false; |
| 1106 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1107 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1108 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1109 | aspect = "color"; |
| 1110 | } else { |
| 1111 | 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] | 1112 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1113 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1114 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1115 | aspect = "depth"; |
| 1116 | } |
| 1117 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1118 | hazard = DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1119 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1120 | aspect = "stencil"; |
| 1121 | checked_stencil = true; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | if (hazard.hazard) { |
| 1126 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 1127 | const char *const store_op_string = string_VkAttachmentStoreOp(checked_stencil ? ci.stencilStoreOp : ci.storeOp); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1128 | skip |= ex_context.GetSyncState().LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1129 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1130 | " %s aspect during store with %s %s. Access info %s", |
| 1131 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1132 | op_type_string, store_op_string, ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | } |
| 1136 | return skip; |
| 1137 | } |
| 1138 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1139 | 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] | 1140 | const VkRect2D &render_area, const AttachmentViewGenVector &attachment_views, |
| 1141 | const char *func_name, uint32_t subpass) const { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 1142 | ValidateResolveAction validate_action(rp_state.renderPass, subpass, *this, ex_context, func_name); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1143 | ResolveOperation(validate_action, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1144 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1145 | } |
| 1146 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1147 | class HazardDetector { |
| 1148 | SyncStageAccessIndex usage_index_; |
| 1149 | |
| 1150 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1151 | 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] | 1152 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1153 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1154 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1155 | explicit HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1156 | }; |
| 1157 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1158 | class HazardDetectorWithOrdering { |
| 1159 | const SyncStageAccessIndex usage_index_; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1160 | const SyncOrdering ordering_rule_; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1161 | |
| 1162 | public: |
| 1163 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1164 | return pos->second.DetectHazard(usage_index_, ordering_rule_); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1165 | } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1166 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1167 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1168 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1169 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, SyncOrdering ordering) : usage_index_(usage), ordering_rule_(ordering) {} |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1170 | }; |
| 1171 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1172 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1173 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1174 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1175 | const auto base_address = ResourceBaseAddress(buffer); |
| 1176 | HazardDetector detector(usage_index); |
| 1177 | return DetectHazard(AccessAddressType::kLinear, detector, (range + base_address), DetectOptions::kDetectAll); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 1178 | } |
| 1179 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1180 | template <typename Detector> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1181 | HazardResult AccessContext::DetectHazard(Detector &detector, const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1182 | DetectOptions options) const { |
| 1183 | const auto *attachment_gen = view_gen.GetRangeGen(gen_type); |
| 1184 | if (!attachment_gen) return HazardResult(); |
| 1185 | |
| 1186 | subresource_adapter::ImageRangeGenerator range_gen(*attachment_gen); |
| 1187 | const auto address_type = view_gen.GetAddressType(); |
| 1188 | for (; range_gen->non_empty(); ++range_gen) { |
| 1189 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1190 | if (hazard.hazard) return hazard; |
| 1191 | } |
| 1192 | |
| 1193 | return HazardResult(); |
| 1194 | } |
| 1195 | |
| 1196 | template <typename Detector> |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1197 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1198 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1199 | const VkExtent3D &extent, DetectOptions options) const { |
| 1200 | if (!SimpleBinding(image)) return HazardResult(); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1201 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1202 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1203 | base_address); |
| 1204 | const auto address_type = ImageAddressType(image); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1205 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1206 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1207 | if (hazard.hazard) return hazard; |
| 1208 | } |
| 1209 | return HazardResult(); |
| 1210 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1211 | template <typename Detector> |
| 1212 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1213 | const VkImageSubresourceRange &subresource_range, DetectOptions options) const { |
| 1214 | if (!SimpleBinding(image)) return HazardResult(); |
| 1215 | const auto base_address = ResourceBaseAddress(image); |
| 1216 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
| 1217 | const auto address_type = ImageAddressType(image); |
| 1218 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1219 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
| 1220 | if (hazard.hazard) return hazard; |
| 1221 | } |
| 1222 | return HazardResult(); |
| 1223 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1224 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1225 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1226 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1227 | const VkExtent3D &extent) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1228 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1229 | subresource.layerCount}; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1230 | HazardDetector detector(current_usage); |
| 1231 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1235 | const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1236 | HazardDetector detector(current_usage); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1237 | return DetectHazard(detector, image, subresource_range, DetectOptions::kDetectAll); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1238 | } |
| 1239 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1240 | HazardResult AccessContext::DetectHazard(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1241 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule) const { |
| 1242 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
| 1243 | return DetectHazard(detector, view_gen, gen_type, DetectOptions::kDetectAll); |
| 1244 | } |
| 1245 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1246 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1247 | const VkImageSubresourceRange &subresource_range, SyncOrdering ordering_rule, |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1248 | const VkOffset3D &offset, const VkExtent3D &extent) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1249 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1250 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1251 | } |
| 1252 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1253 | class BarrierHazardDetector { |
| 1254 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1255 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1256 | SyncStageAccessFlags src_access_scope) |
| 1257 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1258 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1259 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1260 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1261 | } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1262 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1263 | // 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] | 1264 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | private: |
| 1268 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1269 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1270 | SyncStageAccessFlags src_access_scope_; |
| 1271 | }; |
| 1272 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1273 | class EventBarrierHazardDetector { |
| 1274 | public: |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1275 | EventBarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1276 | SyncStageAccessFlags src_access_scope, const SyncEventState::ScopeMap &event_scope, |
| 1277 | const ResourceUsageTag &scope_tag) |
| 1278 | : usage_index_(usage_index), |
| 1279 | src_exec_scope_(src_exec_scope), |
| 1280 | src_access_scope_(src_access_scope), |
| 1281 | event_scope_(event_scope), |
| 1282 | scope_pos_(event_scope.cbegin()), |
| 1283 | scope_end_(event_scope.cend()), |
| 1284 | scope_tag_(scope_tag) {} |
| 1285 | |
| 1286 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1287 | // TODO NOTE: This is almost the slowest way to do this... need to intelligently walk this... |
| 1288 | // Need to find a more efficient sync, since we know pos->first is strictly increasing call to call |
| 1289 | // NOTE: "cached_lower_bound_impl" with upgrades could do this. |
| 1290 | if (scope_pos_ == scope_end_) return HazardResult(); |
| 1291 | if (!scope_pos_->first.intersects(pos->first)) { |
| 1292 | event_scope_.lower_bound(pos->first); |
| 1293 | if ((scope_pos_ == scope_end_) || !scope_pos_->first.intersects(pos->first)) return HazardResult(); |
| 1294 | } |
| 1295 | |
| 1296 | // Some portion of this pos is in the event_scope, so check for a barrier hazard |
| 1297 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_, scope_tag_); |
| 1298 | } |
| 1299 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1300 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1301 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
| 1302 | } |
| 1303 | |
| 1304 | private: |
| 1305 | SyncStageAccessIndex usage_index_; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1306 | VkPipelineStageFlags2KHR src_exec_scope_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1307 | SyncStageAccessFlags src_access_scope_; |
| 1308 | const SyncEventState::ScopeMap &event_scope_; |
| 1309 | SyncEventState::ScopeMap::const_iterator scope_pos_; |
| 1310 | SyncEventState::ScopeMap::const_iterator scope_end_; |
| 1311 | const ResourceUsageTag &scope_tag_; |
| 1312 | }; |
| 1313 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1314 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1315 | const SyncStageAccessFlags &src_access_scope, |
| 1316 | const VkImageSubresourceRange &subresource_range, |
| 1317 | const SyncEventState &sync_event, DetectOptions options) const { |
| 1318 | // It's not particularly DRY to get the address type in this function as well as lower down, but we have to select the |
| 1319 | // first access scope map to use, and there's no easy way to plumb it in below. |
| 1320 | const auto address_type = ImageAddressType(image); |
| 1321 | const auto &event_scope = sync_event.FirstScope(address_type); |
| 1322 | |
| 1323 | EventBarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope, |
| 1324 | event_scope, sync_event.first_scope_tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1325 | return DetectHazard(detector, image, subresource_range, options); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1328 | HazardResult AccessContext::DetectImageBarrierHazard(const AttachmentViewGen &view_gen, const SyncBarrier &barrier, |
| 1329 | DetectOptions options) const { |
| 1330 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, barrier.src_exec_scope.exec_scope, |
| 1331 | barrier.src_access_scope); |
| 1332 | return DetectHazard(detector, view_gen, AttachmentViewGen::Gen::kViewSubresource, options); |
| 1333 | } |
| 1334 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1335 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1336 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1337 | const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1338 | const DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1339 | 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] | 1340 | return DetectHazard(detector, image, subresource_range, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1343 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1344 | const SyncStageAccessFlags &src_stage_accesses, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1345 | const VkImageMemoryBarrier &barrier) const { |
| 1346 | auto subresource_range = NormalizeSubresourceRange(image.createInfo, barrier.subresourceRange); |
| 1347 | const auto src_access_scope = SyncStageAccess::AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 1348 | return DetectImageBarrierHazard(image, src_exec_scope, src_access_scope, subresource_range, kDetectAll); |
| 1349 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1350 | HazardResult AccessContext::DetectImageBarrierHazard(const SyncImageMemoryBarrier &image_barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 1351 | 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] | 1352 | image_barrier.barrier.src_access_scope, image_barrier.range, kDetectAll); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1353 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1354 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1355 | template <typename Flags, typename Map> |
| 1356 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1357 | SyncStageAccessFlags scope = 0; |
| 1358 | for (const auto &bit_scope : map) { |
| 1359 | if (flag_mask < bit_scope.first) break; |
| 1360 | |
| 1361 | if (flag_mask & bit_scope.first) { |
| 1362 | scope |= bit_scope.second; |
| 1363 | } |
| 1364 | } |
| 1365 | return scope; |
| 1366 | } |
| 1367 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1368 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags2KHR stages) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1369 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1370 | } |
| 1371 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1372 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags2KHR accesses) { |
| 1373 | return AccessScopeImpl(sync_utils::ExpandAccessFlags(accesses), syncStageAccessMaskByAccessBit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1374 | } |
| 1375 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1376 | // Getting from stage mask and access mask to stage/access masks is something we need to be good at... |
| 1377 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags2KHR stages, VkAccessFlags2KHR accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1378 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1379 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1380 | // 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] | 1381 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1382 | } |
| 1383 | |
| 1384 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1385 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1386 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1387 | // that do incrementalupdates |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1388 | assert(accesses); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1389 | auto pos = accesses->lower_bound(range); |
| 1390 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1391 | // The range is empty, fill it with a default value. |
| 1392 | pos = action.Infill(accesses, pos, range); |
| 1393 | } else if (range.begin < pos->first.begin) { |
| 1394 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1395 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1396 | } else if (pos->first.begin < range.begin) { |
| 1397 | // Trim the beginning if needed |
| 1398 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1399 | ++pos; |
| 1400 | } |
| 1401 | |
| 1402 | const auto the_end = accesses->end(); |
| 1403 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1404 | if (pos->first.end > range.end) { |
| 1405 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1406 | } |
| 1407 | |
| 1408 | pos = action(accesses, pos); |
| 1409 | if (pos == the_end) break; |
| 1410 | |
| 1411 | auto next = pos; |
| 1412 | ++next; |
| 1413 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1414 | // Need to infill if next is disjoint |
| 1415 | 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] | 1416 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1417 | next = action.Infill(accesses, next, new_range); |
| 1418 | } |
| 1419 | pos = next; |
| 1420 | } |
| 1421 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1422 | |
| 1423 | // Give a comparable interface for range generators and ranges |
| 1424 | template <typename Action> |
| 1425 | inline void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, ResourceAccessRange *range) { |
| 1426 | assert(range); |
| 1427 | UpdateMemoryAccessState(accesses, *range, action); |
| 1428 | } |
| 1429 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1430 | template <typename Action, typename RangeGen> |
| 1431 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, RangeGen *range_gen_arg) { |
| 1432 | assert(range_gen_arg); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1433 | 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] | 1434 | for (; range_gen->non_empty(); ++range_gen) { |
| 1435 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1436 | } |
| 1437 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1438 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1439 | template <typename Action, typename RangeGen> |
| 1440 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, const RangeGen &range_gen_prebuilt) { |
| 1441 | RangeGen range_gen(range_gen_prebuilt); // RangeGenerators can be expensive to create from scratch... initialize from built |
| 1442 | for (; range_gen->non_empty(); ++range_gen) { |
| 1443 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1444 | } |
| 1445 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1446 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1447 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1448 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1449 | // this is only called on gaps, and never returns a gap. |
| 1450 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1451 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1452 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1453 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1454 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1455 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1456 | auto &access_state = pos->second; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1457 | access_state.Update(usage, ordering_rule, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1458 | return pos; |
| 1459 | } |
| 1460 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1461 | UpdateMemoryAccessStateFunctor(AccessAddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1462 | SyncOrdering ordering_rule_, const ResourceUsageTag &tag_) |
| 1463 | : type(type_), context(context_), usage(usage_), ordering_rule(ordering_rule_), tag(tag_) {} |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1464 | const AccessAddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1465 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1466 | const SyncStageAccessIndex usage; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1467 | const SyncOrdering ordering_rule; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1468 | const ResourceUsageTag &tag; |
| 1469 | }; |
| 1470 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1471 | // The barrier operation for pipeline and subpass dependencies` |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1472 | struct PipelineBarrierOp { |
| 1473 | SyncBarrier barrier; |
| 1474 | bool layout_transition; |
| 1475 | PipelineBarrierOp(const SyncBarrier &barrier_, bool layout_transition_) |
| 1476 | : barrier(barrier_), layout_transition(layout_transition_) {} |
| 1477 | PipelineBarrierOp() = default; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1478 | PipelineBarrierOp(const PipelineBarrierOp &) = default; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1479 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(barrier, layout_transition); } |
| 1480 | }; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1481 | // The barrier operation for wait events |
| 1482 | struct WaitEventBarrierOp { |
| 1483 | const ResourceUsageTag *scope_tag; |
| 1484 | SyncBarrier barrier; |
| 1485 | bool layout_transition; |
| 1486 | WaitEventBarrierOp(const ResourceUsageTag &scope_tag_, const SyncBarrier &barrier_, bool layout_transition_) |
| 1487 | : scope_tag(&scope_tag_), barrier(barrier_), layout_transition(layout_transition_) {} |
| 1488 | WaitEventBarrierOp() = default; |
| 1489 | void operator()(ResourceAccessState *access_state) const { |
| 1490 | assert(scope_tag); // Not valid to have a non-scope op executed, default construct included for std::vector support |
| 1491 | access_state->ApplyBarrier(*scope_tag, barrier, layout_transition); |
| 1492 | } |
| 1493 | }; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1494 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1495 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1496 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1497 | // of a collection is known/present. |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1498 | template <typename BarrierOp> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1499 | class ApplyBarrierOpsFunctor { |
| 1500 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1501 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1502 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1503 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1504 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1505 | auto &access_state = pos->second; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1506 | for (const auto &op : barrier_ops_) { |
| 1507 | op(&access_state); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1508 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1509 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1510 | if (resolve_) { |
| 1511 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1512 | // another walk |
| 1513 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1514 | } |
| 1515 | return pos; |
| 1516 | } |
| 1517 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1518 | // 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] | 1519 | ApplyBarrierOpsFunctor(bool resolve, size_t size_hint, const ResourceUsageTag &tag) |
| 1520 | : resolve_(resolve), barrier_ops_(), tag_(tag) { |
| 1521 | barrier_ops_.reserve(size_hint); |
| 1522 | } |
| 1523 | void EmplaceBack(const BarrierOp &op) { barrier_ops_.emplace_back(op); } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1524 | |
| 1525 | private: |
| 1526 | bool resolve_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1527 | std::vector<BarrierOp> barrier_ops_; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1528 | const ResourceUsageTag &tag_; |
| 1529 | }; |
| 1530 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1531 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1532 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1533 | template <typename BarrierOp> |
| 1534 | class ApplyBarrierFunctor { |
| 1535 | public: |
| 1536 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1537 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
| 1538 | |
| 1539 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
| 1540 | auto &access_state = pos->second; |
| 1541 | barrier_op_(&access_state); |
| 1542 | return pos; |
| 1543 | } |
| 1544 | |
| 1545 | ApplyBarrierFunctor(const BarrierOp &barrier_op) : barrier_op_(barrier_op) {} |
| 1546 | |
| 1547 | private: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1548 | BarrierOp barrier_op_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1549 | }; |
| 1550 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1551 | // This functor resolves the pendinging state. |
| 1552 | class ResolvePendingBarrierFunctor { |
| 1553 | public: |
| 1554 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1555 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
| 1556 | |
| 1557 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
| 1558 | auto &access_state = pos->second; |
| 1559 | access_state.ApplyPendingBarriers(tag_); |
| 1560 | return pos; |
| 1561 | } |
| 1562 | |
| 1563 | ResolvePendingBarrierFunctor(const ResourceUsageTag &tag) : tag_(tag) {} |
| 1564 | |
| 1565 | private: |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1566 | const ResourceUsageTag &tag_; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1567 | }; |
| 1568 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1569 | void AccessContext::UpdateAccessState(AccessAddressType type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
| 1570 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
| 1571 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1572 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1573 | } |
| 1574 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1575 | 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] | 1576 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1577 | if (!SimpleBinding(buffer)) return; |
| 1578 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1579 | UpdateAccessState(AccessAddressType::kLinear, current_usage, ordering_rule, range + base_address, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1580 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1581 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1582 | 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] | 1583 | const VkImageSubresourceRange &subresource_range, const ResourceUsageTag &tag) { |
| 1584 | if (!SimpleBinding(image)) return; |
| 1585 | const auto base_address = ResourceBaseAddress(image); |
| 1586 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, base_address); |
| 1587 | const auto address_type = ImageAddressType(image); |
| 1588 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1589 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
| 1590 | } |
| 1591 | 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] | 1592 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1593 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1594 | if (!SimpleBinding(image)) return; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1595 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1596 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1597 | base_address); |
| 1598 | const auto address_type = ImageAddressType(image); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1599 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1600 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, &range_gen); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1601 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1602 | |
| 1603 | void AccessContext::UpdateAccessState(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, |
| 1604 | SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, const ResourceUsageTag &tag) { |
| 1605 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1606 | if (!gen) return; |
| 1607 | subresource_adapter::ImageRangeGenerator range_gen(*gen); |
| 1608 | const auto address_type = view_gen.GetAddressType(); |
| 1609 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
| 1610 | ApplyUpdateAction(address_type, action, &range_gen); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1611 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1612 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1613 | 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] | 1614 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1615 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1616 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1617 | subresource.layerCount}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1618 | UpdateAccessState(image, current_usage, ordering_rule, subresource_range, offset, extent, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1619 | } |
| 1620 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1621 | template <typename Action, typename RangeGen> |
| 1622 | void AccessContext::ApplyUpdateAction(AccessAddressType address_type, const Action &action, RangeGen *range_gen_arg) { |
| 1623 | assert(range_gen_arg); // Old Google C++ styleguide require non-const object pass by * not &, but this isn't an optional arg. |
| 1624 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), action, range_gen_arg); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | template <typename Action> |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1628 | void AccessContext::ApplyUpdateAction(const AttachmentViewGen &view_gen, AttachmentViewGen::Gen gen_type, const Action &action) { |
| 1629 | const ImageRangeGen *gen = view_gen.GetRangeGen(gen_type); |
| 1630 | if (!gen) return; |
| 1631 | UpdateMemoryAccessState(&GetAccessStateMap(view_gen.GetAddressType()), action, *gen); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1632 | } |
| 1633 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1634 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, |
| 1635 | const AttachmentViewGenVector &attachment_views, uint32_t subpass, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1636 | const ResourceUsageTag &tag) { |
| 1637 | UpdateStateResolveAction update(*this, tag); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1638 | ResolveOperation(update, rp_state, attachment_views, subpass); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1639 | } |
| 1640 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1641 | void AccessContext::UpdateAttachmentStoreAccess(const RENDER_PASS_STATE &rp_state, const AttachmentViewGenVector &attachment_views, |
| 1642 | uint32_t subpass, const ResourceUsageTag &tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1643 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1644 | |
| 1645 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1646 | if (rp_state.attachment_last_subpass[i] == subpass) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1647 | const auto &view_gen = attachment_views[i]; |
| 1648 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1649 | |
| 1650 | const auto &ci = attachment_ci[i]; |
| 1651 | const bool has_depth = FormatHasDepth(ci.format); |
| 1652 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1653 | const bool is_color = !(has_depth || has_stencil); |
| 1654 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1655 | |
| 1656 | if (is_color && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1657 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 1658 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1659 | } else { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1660 | if (has_depth && store_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1661 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 1662 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1663 | } |
| 1664 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1665 | if (has_stencil && stencil_op_stores) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1666 | UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 1667 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1668 | } |
| 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1674 | template <typename Action> |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1675 | void AccessContext::ApplyToContext(const Action &barrier_action) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1676 | // 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] | 1677 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1678 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), kFullRange, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1683 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1684 | auto &context = contexts[subpass_index]; |
John Zulauf | 22aefed | 2021-03-11 18:14:35 -0700 | [diff] [blame] | 1685 | ApplyTrackbackStackAction barrier_action(context.GetDstExternalTrackBack().barriers); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1686 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1687 | context.ResolveAccessRange(address_type, kFullRange, barrier_action, &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1688 | } |
| 1689 | } |
| 1690 | } |
| 1691 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1692 | // Suitable only for *subpass* access contexts |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1693 | HazardResult AccessContext::DetectSubpassTransitionHazard(const TrackBack &track_back, const AttachmentViewGen &attach_view) const { |
| 1694 | if (!attach_view.IsValid()) return HazardResult(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1695 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1696 | // 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] | 1697 | assert(track_back.context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1698 | |
| 1699 | // 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] | 1700 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1701 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1702 | HazardResult hazard = track_back.context->DetectImageBarrierHazard(attach_view, merged_barrier, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1703 | if (!hazard.hazard) { |
| 1704 | // The Async hazard check is against the current context's async set. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1705 | hazard = DetectImageBarrierHazard(attach_view, merged_barrier, kDetectAsync); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1706 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1707 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1708 | return hazard; |
| 1709 | } |
| 1710 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1711 | void AccessContext::RecordLayoutTransitions(const RENDER_PASS_STATE &rp_state, uint32_t subpass, |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1712 | const AttachmentViewGenVector &attachment_views, const ResourceUsageTag &tag) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1713 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1714 | const ResourceAccessState empty_infill; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1715 | for (const auto &transition : transitions) { |
| 1716 | const auto prev_pass = transition.prev_pass; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1717 | const auto &view_gen = attachment_views[transition.attachment]; |
| 1718 | if (!view_gen.IsValid()) continue; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1719 | |
| 1720 | const auto *trackback = GetTrackBackFromSubpass(prev_pass); |
| 1721 | assert(trackback); |
| 1722 | |
| 1723 | // Import the attachments into the current context |
| 1724 | const auto *prev_context = trackback->context; |
| 1725 | assert(prev_context); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1726 | const auto address_type = view_gen.GetAddressType(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1727 | auto &target_map = GetAccessStateMap(address_type); |
| 1728 | ApplySubpassTransitionBarriersAction barrier_action(trackback->barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 1729 | prev_context->ResolveAccessRange(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action, &target_map, |
| 1730 | &empty_infill); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1731 | } |
| 1732 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1733 | // If there were no transitions skip this global map walk |
| 1734 | if (transitions.size()) { |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1735 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1736 | ApplyToContext(apply_pending_action); |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1737 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1738 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1739 | |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 1740 | void CommandBufferAccessContext::ApplyGlobalBarriersToEvents(const SyncExecScope &src, const SyncExecScope &dst) { |
| 1741 | 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] | 1742 | |
| 1743 | auto *events_context = GetCurrentEventsContext(); |
| 1744 | assert(events_context); |
| 1745 | for (auto &event_pair : *events_context) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1746 | assert(event_pair.second); // Shouldn't be storing empty |
| 1747 | auto &sync_event = *event_pair.second; |
| 1748 | // 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] | 1749 | if ((sync_event.barriers & src.exec_scope) || all_commands_bit) { |
| 1750 | sync_event.barriers |= dst.exec_scope; |
| 1751 | sync_event.barriers |= dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1752 | } |
| 1753 | } |
| 1754 | } |
| 1755 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1756 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1757 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1758 | const char *func_name) const { |
| 1759 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1760 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1761 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1762 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pipe, &per_sets); |
| 1763 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1764 | return skip; |
| 1765 | } |
| 1766 | |
| 1767 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1768 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1769 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1770 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1771 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1772 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1773 | for (const auto &stage_state : pipe->stage_state) { |
| 1774 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->graphicsPipelineCI.pRasterizationState && |
| 1775 | pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1776 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1777 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1778 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1779 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1780 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1781 | set_binding.first.second); |
| 1782 | const auto descriptor_type = binding_it.GetType(); |
| 1783 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1784 | auto array_idx = 0; |
| 1785 | |
| 1786 | if (binding_it.IsVariableDescriptorCount()) { |
| 1787 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1788 | } |
| 1789 | SyncStageAccessIndex sync_index = |
| 1790 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1791 | |
| 1792 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1793 | uint32_t index = i - index_range.start; |
| 1794 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1795 | switch (descriptor->GetClass()) { |
| 1796 | case DescriptorClass::ImageSampler: |
| 1797 | case DescriptorClass::Image: { |
| 1798 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1799 | VkImageLayout image_layout; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1800 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1801 | const auto image_sampler_descriptor = static_cast<const ImageSamplerDescriptor *>(descriptor); |
| 1802 | img_view_state = image_sampler_descriptor->GetImageViewState(); |
| 1803 | image_layout = image_sampler_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1804 | } else { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1805 | const auto image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 1806 | img_view_state = image_descriptor->GetImageViewState(); |
| 1807 | image_layout = image_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1808 | } |
| 1809 | if (!img_view_state) continue; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1810 | HazardResult hazard; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1811 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1812 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1813 | |
| 1814 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1815 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1816 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1817 | // Input attachments are subject to raster ordering rules |
| 1818 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1819 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1820 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1821 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1822 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1823 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1824 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1825 | skip |= sync_state_->LogError( |
| 1826 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1827 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 1828 | ", index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1829 | func_name, string_SyncHazard(hazard.hazard), |
| 1830 | sync_state_->report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1831 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1832 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1833 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1834 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1835 | set_binding.first.second, index, FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1836 | } |
| 1837 | break; |
| 1838 | } |
| 1839 | case DescriptorClass::TexelBuffer: { |
| 1840 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1841 | if (!buf_view_state) continue; |
| 1842 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1843 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1844 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1845 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1846 | skip |= sync_state_->LogError( |
| 1847 | buf_view_state->buffer_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1848 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1849 | func_name, string_SyncHazard(hazard.hazard), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1850 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view).c_str(), |
| 1851 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1852 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1853 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1854 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1855 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1856 | } |
| 1857 | break; |
| 1858 | } |
| 1859 | case DescriptorClass::GeneralBuffer: { |
| 1860 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1861 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1862 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1863 | const ResourceAccessRange range = |
| 1864 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1865 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 1866 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1867 | skip |= sync_state_->LogError( |
| 1868 | buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1869 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1870 | func_name, string_SyncHazard(hazard.hazard), |
| 1871 | sync_state_->report_data->FormatHandle(buf_state->buffer).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1872 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1873 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1874 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1875 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1876 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1877 | } |
| 1878 | break; |
| 1879 | } |
| 1880 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1881 | default: |
| 1882 | break; |
| 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | } |
| 1887 | return skip; |
| 1888 | } |
| 1889 | |
| 1890 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1891 | const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1892 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1893 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1894 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pipe, &per_sets); |
| 1895 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1896 | return; |
| 1897 | } |
| 1898 | |
| 1899 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1900 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1901 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1902 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1903 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1904 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1905 | for (const auto &stage_state : pipe->stage_state) { |
| 1906 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->graphicsPipelineCI.pRasterizationState && |
| 1907 | pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1908 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1909 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1910 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1911 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1912 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1913 | set_binding.first.second); |
| 1914 | const auto descriptor_type = binding_it.GetType(); |
| 1915 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1916 | auto array_idx = 0; |
| 1917 | |
| 1918 | if (binding_it.IsVariableDescriptorCount()) { |
| 1919 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1920 | } |
| 1921 | SyncStageAccessIndex sync_index = |
| 1922 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1923 | |
| 1924 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1925 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1926 | switch (descriptor->GetClass()) { |
| 1927 | case DescriptorClass::ImageSampler: |
| 1928 | case DescriptorClass::Image: { |
| 1929 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
| 1930 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
| 1931 | img_view_state = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetImageViewState(); |
| 1932 | } else { |
| 1933 | img_view_state = static_cast<const ImageDescriptor *>(descriptor)->GetImageViewState(); |
| 1934 | } |
| 1935 | if (!img_view_state) continue; |
| 1936 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1937 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1938 | const VkExtent3D extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1939 | const VkOffset3D offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1940 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kRaster, |
| 1941 | img_view_state->normalized_subresource_range, offset, extent, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1942 | } else { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 1943 | current_context_->UpdateAccessState(*img_state, sync_index, SyncOrdering::kNonAttachment, |
| 1944 | img_view_state->normalized_subresource_range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1945 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1946 | break; |
| 1947 | } |
| 1948 | case DescriptorClass::TexelBuffer: { |
| 1949 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1950 | if (!buf_view_state) continue; |
| 1951 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1952 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1953 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1954 | break; |
| 1955 | } |
| 1956 | case DescriptorClass::GeneralBuffer: { |
| 1957 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1958 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1959 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1960 | const ResourceAccessRange range = |
| 1961 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1962 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1963 | break; |
| 1964 | } |
| 1965 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1966 | default: |
| 1967 | break; |
| 1968 | } |
| 1969 | } |
| 1970 | } |
| 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const char *func_name) const { |
| 1975 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1976 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1977 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1978 | return skip; |
| 1979 | } |
| 1980 | |
| 1981 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 1982 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1983 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1984 | |
| 1985 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1986 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1987 | if (binding_description.binding < binding_buffers_size) { |
| 1988 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 1989 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->destroyed) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1990 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 1991 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1992 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 1993 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 1994 | 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] | 1995 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1996 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1997 | buf_state->buffer, string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for vertex %s in %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1998 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(buf_state->buffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1999 | 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] | 2000 | } |
| 2001 | } |
| 2002 | } |
| 2003 | return skip; |
| 2004 | } |
| 2005 | |
| 2006 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2007 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2008 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2009 | return; |
| 2010 | } |
| 2011 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2012 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2013 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2014 | |
| 2015 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2016 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2017 | if (binding_description.binding < binding_buffers_size) { |
| 2018 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2019 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->destroyed) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2020 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2021 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2022 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2023 | vertexCount, binding_description.stride); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2024 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_ATTRIBUTE_INPUT_VERTEX_ATTRIBUTE_READ, |
| 2025 | SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2026 | } |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const char *func_name) const { |
| 2031 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2032 | 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] | 2033 | return skip; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2034 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2035 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2036 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2037 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2038 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2039 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2040 | 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] | 2041 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2042 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2043 | index_buf_state->buffer, string_SyncHazardVUID(hazard.hazard), "%s: Hazard %s for index %s in %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2044 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(index_buf_state->buffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2045 | 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] | 2046 | } |
| 2047 | |
| 2048 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2049 | // We will detect more accurate range in the future. |
| 2050 | skip |= ValidateDrawVertex(UINT32_MAX, 0, func_name); |
| 2051 | return skip; |
| 2052 | } |
| 2053 | |
| 2054 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag &tag) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2055 | 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] | 2056 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2057 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2058 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2059 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2060 | firstIndex, indexCount, index_size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2061 | 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] | 2062 | |
| 2063 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2064 | // We will detect more accurate range in the future. |
| 2065 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 2066 | } |
| 2067 | |
| 2068 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(const char *func_name) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2069 | bool skip = false; |
| 2070 | if (!current_renderpass_context_) return skip; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2071 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(GetExecutionContext(), *cb_state_.get(), func_name); |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2072 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2076 | if (current_renderpass_context_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2077 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), tag); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2078 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2079 | } |
| 2080 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2081 | void CommandBufferAccessContext::RecordBeginRenderPass(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2082 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2083 | const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2084 | // Create an access context the current renderpass. |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2085 | 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] | 2086 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2087 | current_renderpass_context_->RecordBeginRenderPass(tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2088 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2089 | } |
| 2090 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2091 | void CommandBufferAccessContext::RecordNextSubpass(CMD_TYPE command) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2092 | assert(current_renderpass_context_); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2093 | auto prev_tag = NextCommandTag(command); |
| 2094 | auto next_tag = NextSubcommandTag(command); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2095 | current_renderpass_context_->RecordNextSubpass(prev_tag, next_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2096 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
| 2097 | } |
| 2098 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2099 | void CommandBufferAccessContext::RecordEndRenderPass(CMD_TYPE command) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2100 | assert(current_renderpass_context_); |
| 2101 | if (!current_renderpass_context_) return; |
| 2102 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2103 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, NextCommandTag(command)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2104 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2105 | current_renderpass_context_ = nullptr; |
| 2106 | } |
| 2107 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2108 | void CommandBufferAccessContext::RecordDestroyEvent(VkEvent event) { |
| 2109 | // Erase is okay with the key not being |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2110 | const auto *event_state = sync_state_->Get<EVENT_STATE>(event); |
| 2111 | if (event_state) { |
| 2112 | GetCurrentEventsContext()->Destroy(event_state); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2113 | } |
| 2114 | } |
| 2115 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2116 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const CommandExecutionContext &ex_context, const CMD_BUFFER_STATE &cmd, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2117 | const char *func_name) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2118 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2119 | const auto &sync_state = ex_context.GetSyncState(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2120 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2121 | if (!pipe || |
| 2122 | (pipe->graphicsPipelineCI.pRasterizationState && pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2123 | return skip; |
| 2124 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2125 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2126 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2127 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2128 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2129 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2130 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2131 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2132 | if (location >= subpass.colorAttachmentCount || |
| 2133 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2134 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2135 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2136 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2137 | if (!view_gen.IsValid()) continue; |
| 2138 | HazardResult hazard = |
| 2139 | current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2140 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2141 | if (hazard.hazard) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2142 | const VkImageView view_handle = view_gen.GetViewState()->image_view; |
| 2143 | skip |= sync_state.LogError(view_handle, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2144 | "%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] | 2145 | func_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2146 | sync_state.report_data->FormatHandle(view_handle).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2147 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2148 | location, ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2149 | } |
| 2150 | } |
| 2151 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2152 | |
| 2153 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2154 | // 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] | 2155 | const uint32_t depth_stencil_attachment = |
| 2156 | GetSubpassDepthStencilAttachmentIndex(pipe->graphicsPipelineCI.pDepthStencilState, subpass.pDepthStencilAttachment); |
| 2157 | |
| 2158 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2159 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2160 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2161 | bool depth_write = false, stencil_write = false; |
| 2162 | |
| 2163 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2164 | if (!FormatIsStencilOnly(view_state.create_info.format) && pipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2165 | pipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2166 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2167 | depth_write = true; |
| 2168 | } |
| 2169 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2170 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2171 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2172 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2173 | if (!FormatIsDepthOnly(view_state.create_info.format) && pipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2174 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2175 | stencil_write = true; |
| 2176 | } |
| 2177 | |
| 2178 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2179 | if (depth_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2180 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2181 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2182 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2183 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2184 | skip |= sync_state.LogError( |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2185 | view_state.image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2186 | "%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] | 2187 | func_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2188 | sync_state.report_data->FormatHandle(view_state.image_view).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2189 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2190 | ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2191 | } |
| 2192 | } |
| 2193 | if (stencil_write) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2194 | HazardResult hazard = current_context.DetectHazard(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2195 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2196 | SyncOrdering::kDepthStencilAttachment); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2197 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2198 | skip |= sync_state.LogError( |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2199 | view_state.image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2200 | "%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] | 2201 | func_name, string_SyncHazard(hazard.hazard), |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2202 | sync_state.report_data->FormatHandle(view_state.image_view).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2203 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2204 | ex_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2205 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2206 | } |
| 2207 | } |
| 2208 | return skip; |
| 2209 | } |
| 2210 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2211 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd, const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2212 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2213 | if (!pipe || |
| 2214 | (pipe->graphicsPipelineCI.pRasterizationState && pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2215 | return; |
| 2216 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2217 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2218 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2219 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2220 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2221 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2222 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2223 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2224 | if (location >= subpass.colorAttachmentCount || |
| 2225 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2226 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2227 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2228 | const AttachmentViewGen &view_gen = attachment_views_[subpass.pColorAttachments[location].attachment]; |
| 2229 | current_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, |
| 2230 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment, |
| 2231 | tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2232 | } |
| 2233 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2234 | |
| 2235 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2236 | // 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] | 2237 | const uint32_t depth_stencil_attachment = |
| 2238 | GetSubpassDepthStencilAttachmentIndex(pipe->graphicsPipelineCI.pDepthStencilState, subpass.pDepthStencilAttachment); |
| 2239 | if ((depth_stencil_attachment != VK_ATTACHMENT_UNUSED) && attachment_views_[depth_stencil_attachment].IsValid()) { |
| 2240 | const AttachmentViewGen &view_gen = attachment_views_[depth_stencil_attachment]; |
| 2241 | const IMAGE_VIEW_STATE &view_state = *view_gen.GetViewState(); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2242 | bool depth_write = false, stencil_write = false; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2243 | const bool has_depth = 0 != (view_state.normalized_subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 2244 | 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] | 2245 | |
| 2246 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2247 | if (has_depth && !FormatIsStencilOnly(view_state.create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2248 | pipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 2249 | pipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2250 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2251 | depth_write = true; |
| 2252 | } |
| 2253 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2254 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2255 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2256 | // PHASE1 TODO: These validation should be in core_checks. |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2257 | if (has_stencil && !FormatIsDepthOnly(view_state.create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2258 | pipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2259 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2260 | stencil_write = true; |
| 2261 | } |
| 2262 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2263 | if (depth_write || stencil_write) { |
| 2264 | const auto ds_gentype = view_gen.GetDepthStencilRenderAreaGenType(depth_write, stencil_write); |
| 2265 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2266 | current_context.UpdateAccessState(view_gen, ds_gentype, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2267 | SyncOrdering::kDepthStencilAttachment, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2268 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2269 | } |
| 2270 | } |
| 2271 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2272 | bool RenderPassAccessContext::ValidateNextSubpass(const CommandExecutionContext &ex_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2273 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2274 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2275 | 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] | 2276 | current_subpass_); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2277 | 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] | 2278 | func_name); |
| 2279 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2280 | const auto next_subpass = current_subpass_ + 1; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2281 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2282 | skip |= |
| 2283 | 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] | 2284 | if (!skip) { |
| 2285 | // To avoid complex (and buggy) duplication of the affect of layout transitions on load operations, we'll record them |
| 2286 | // on a copy of the (empty) next context. |
| 2287 | // Note: The resource access map should be empty so hopefully this copy isn't too horrible from a perf POV. |
| 2288 | AccessContext temp_context(next_context); |
| 2289 | temp_context.RecordLayoutTransitions(*rp_state_, next_subpass, attachment_views_, kCurrentCommandTag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2290 | skip |= |
| 2291 | 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] | 2292 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2293 | return skip; |
| 2294 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2295 | bool RenderPassAccessContext::ValidateEndRenderPass(const CommandExecutionContext &ex_context, const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2296 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2297 | bool skip = false; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2298 | 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] | 2299 | current_subpass_); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2300 | skip |= CurrentContext().ValidateStoreOperation(ex_context, *rp_state_, render_area_, current_subpass_, |
| 2301 | |
| 2302 | attachment_views_, func_name); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2303 | skip |= ValidateFinalSubpassLayoutTransitions(ex_context, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2304 | return skip; |
| 2305 | } |
| 2306 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2307 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy() const { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2308 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, attachment_views_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2309 | } |
| 2310 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2311 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const CommandExecutionContext &ex_context, |
| 2312 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2313 | bool skip = false; |
| 2314 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2315 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2316 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2317 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2318 | // to apply and only copy then, if this proves a hot spot. |
| 2319 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2320 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2321 | // Validate the "finalLayout" transitions to external |
| 2322 | // Get them from where there we're hidding in the extra entry. |
| 2323 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2324 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2325 | const auto &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2326 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
| 2327 | 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] | 2328 | auto *context = trackback.context; |
| 2329 | |
| 2330 | if (transition.prev_pass == current_subpass_) { |
| 2331 | if (!proxy_for_current) { |
| 2332 | // 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] | 2333 | proxy_for_current.reset(CreateStoreResolveProxy()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2334 | } |
| 2335 | context = proxy_for_current.get(); |
| 2336 | } |
| 2337 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2338 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2339 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2340 | auto hazard = context->DetectImageBarrierHazard(view_gen, merged_barrier, AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2341 | if (hazard.hazard) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2342 | skip |= ex_context.GetSyncState().LogError( |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2343 | rp_state_->renderPass, string_SyncHazardVUID(hazard.hazard), |
| 2344 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
| 2345 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 2346 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2347 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2348 | ex_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | return skip; |
| 2352 | } |
| 2353 | |
| 2354 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag &tag) { |
| 2355 | // Add layout transitions... |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2356 | subpass_contexts_[current_subpass_].RecordLayoutTransitions(*rp_state_, current_subpass_, attachment_views_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2357 | } |
| 2358 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2359 | void RenderPassAccessContext::RecordLoadOperations(const ResourceUsageTag &tag) { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2360 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2361 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2362 | |
| 2363 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2364 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2365 | const AttachmentViewGen &view_gen = attachment_views_[i]; |
| 2366 | if (!view_gen.IsValid()) continue; // UNUSED |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2367 | |
| 2368 | const auto &ci = attachment_ci[i]; |
| 2369 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2370 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2371 | const bool is_color = !(has_depth || has_stencil); |
| 2372 | |
| 2373 | if (is_color) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2374 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kRenderArea, ColorLoadUsage(ci.loadOp), |
| 2375 | SyncOrdering::kColorAttachment, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2376 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2377 | if (has_depth) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2378 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kDepthOnlyRenderArea, |
| 2379 | DepthStencilLoadUsage(ci.loadOp), SyncOrdering::kDepthStencilAttachment, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2380 | } |
| 2381 | if (has_stencil) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2382 | subpass_context.UpdateAccessState(view_gen, AttachmentViewGen::Gen::kStencilOnlyRenderArea, |
| 2383 | DepthStencilLoadUsage(ci.stencilLoadOp), |
| 2384 | SyncOrdering::kDepthStencilAttachment, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2390 | AttachmentViewGenVector RenderPassAccessContext::CreateAttachmentViewGen( |
| 2391 | const VkRect2D &render_area, const std::vector<const IMAGE_VIEW_STATE *> &attachment_views) { |
| 2392 | AttachmentViewGenVector view_gens; |
| 2393 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2394 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2395 | view_gens.reserve(attachment_views.size()); |
| 2396 | for (const auto *view : attachment_views) { |
| 2397 | view_gens.emplace_back(view, offset, extent); |
| 2398 | } |
| 2399 | return view_gens; |
| 2400 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2401 | RenderPassAccessContext::RenderPassAccessContext(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 2402 | VkQueueFlags queue_flags, |
| 2403 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 2404 | const AccessContext *external_context) |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2405 | : 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] | 2406 | // 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] | 2407 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2408 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2409 | 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] | 2410 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2411 | attachment_views_ = CreateAttachmentViewGen(render_area, attachment_views); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2412 | } |
| 2413 | void RenderPassAccessContext::RecordBeginRenderPass(const ResourceUsageTag &tag) { |
| 2414 | assert(0 == current_subpass_); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2415 | subpass_contexts_[current_subpass_].SetStartTag(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2416 | RecordLayoutTransitions(tag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2417 | RecordLoadOperations(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2418 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2419 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2420 | void RenderPassAccessContext::RecordNextSubpass(const ResourceUsageTag &prev_subpass_tag, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2421 | const ResourceUsageTag &next_subpass_tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2422 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2423 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, prev_subpass_tag); |
| 2424 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, prev_subpass_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2425 | |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 2426 | // Move to the next sub-command for the new subpass. The resolve and store are logically part of the previous |
| 2427 | // 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] | 2428 | current_subpass_++; |
| 2429 | assert(current_subpass_ < subpass_contexts_.size()); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2430 | subpass_contexts_[current_subpass_].SetStartTag(next_subpass_tag); |
| 2431 | RecordLayoutTransitions(next_subpass_tag); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2432 | RecordLoadOperations(next_subpass_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2433 | } |
| 2434 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 2435 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const ResourceUsageTag &tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2436 | // Add the resolve and store accesses |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2437 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, attachment_views_, current_subpass_, tag); |
| 2438 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, attachment_views_, current_subpass_, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2439 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2440 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2441 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2442 | |
| 2443 | // Add the "finalLayout" transitions to external |
| 2444 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2445 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2446 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2447 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2448 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2449 | for (const auto &transition : final_transitions) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2450 | const AttachmentViewGen &view_gen = attachment_views_[transition.attachment]; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2451 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | aa97d8b | 2020-07-14 10:58:13 -0600 | [diff] [blame] | 2452 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2453 | ApplyBarrierOpsFunctor<PipelineBarrierOp> barrier_action(true /* resolve */, last_trackback.barriers.size(), tag); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2454 | for (const auto &barrier : last_trackback.barriers) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2455 | barrier_action.EmplaceBack(PipelineBarrierOp(barrier, true)); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2456 | } |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 2457 | external_context->ApplyUpdateAction(view_gen, AttachmentViewGen::Gen::kViewSubresource, barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2458 | } |
| 2459 | } |
| 2460 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2461 | SyncExecScope SyncExecScope::MakeSrc(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2462 | SyncExecScope result; |
| 2463 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2464 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2465 | result.exec_scope = sync_utils::WithEarlierPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2466 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2467 | return result; |
| 2468 | } |
| 2469 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2470 | SyncExecScope SyncExecScope::MakeDst(VkQueueFlags queue_flags, VkPipelineStageFlags2KHR mask_param) { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2471 | SyncExecScope result; |
| 2472 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2473 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2474 | result.exec_scope = sync_utils::WithLaterPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2475 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2476 | return result; |
| 2477 | } |
| 2478 | |
| 2479 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2480 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2481 | src_access_scope = 0; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2482 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2483 | dst_access_scope = 0; |
| 2484 | } |
| 2485 | |
| 2486 | template <typename Barrier> |
| 2487 | SyncBarrier::SyncBarrier(const Barrier &barrier, const SyncExecScope &src, const SyncExecScope &dst) { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2488 | src_exec_scope = src; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2489 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2490 | dst_exec_scope = dst; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2491 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
| 2492 | } |
| 2493 | |
| 2494 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &subpass) { |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2495 | const auto barrier = lvl_find_in_chain<VkMemoryBarrier2KHR>(subpass.pNext); |
| 2496 | if (barrier) { |
| 2497 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier->srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2498 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2499 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier->srcAccessMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2500 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2501 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier->dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2502 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2503 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier->dstAccessMask); |
| 2504 | |
| 2505 | } else { |
| 2506 | auto src = SyncExecScope::MakeSrc(queue_flags, subpass.srcStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2507 | src_exec_scope = src; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2508 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, subpass.srcAccessMask); |
| 2509 | |
| 2510 | auto dst = SyncExecScope::MakeDst(queue_flags, subpass.dstStageMask); |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2511 | dst_exec_scope = dst; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2512 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, subpass.dstAccessMask); |
| 2513 | } |
| 2514 | } |
| 2515 | |
| 2516 | template <typename Barrier> |
| 2517 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const Barrier &barrier) { |
| 2518 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 2519 | src_exec_scope = src.exec_scope; |
| 2520 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
| 2521 | |
| 2522 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2523 | dst_exec_scope = dst.exec_scope; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 2524 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2525 | } |
| 2526 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2527 | // Apply a list of barriers, without resolving pending state, useful for subpass layout transitions |
| 2528 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
| 2529 | for (const auto &barrier : barriers) { |
| 2530 | ApplyBarrier(barrier, layout_transition); |
| 2531 | } |
| 2532 | } |
| 2533 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2534 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2535 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2536 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2537 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, const ResourceUsageTag &tag) { |
| 2538 | 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] | 2539 | assert(pending_write_barriers.none()); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2540 | assert(!pending_write_dep_chain); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2541 | for (const auto &barrier : barriers) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2542 | ApplyBarrier(barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2543 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2544 | ApplyPendingBarriers(tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2545 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2546 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2547 | HazardResult hazard; |
| 2548 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2549 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2550 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2551 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2552 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2553 | } |
| 2554 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2555 | // Write operation: |
| 2556 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2557 | // If reads exists -- test only against them because either: |
| 2558 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2559 | // * 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 |
| 2560 | // the current write happens after the reads, so just test the write against the reades |
| 2561 | // Otherwise test against last_write |
| 2562 | // |
| 2563 | // Look for casus belli for WAR |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2564 | if (last_reads.size()) { |
| 2565 | for (const auto &read_access : last_reads) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2566 | if (IsReadHazard(usage_stage, read_access)) { |
| 2567 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2568 | break; |
| 2569 | } |
| 2570 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2571 | } else if (last_write.any() && IsWriteHazard(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2572 | // Write-After-Write check -- if we have a previous write to test against |
| 2573 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | return hazard; |
| 2577 | } |
| 2578 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2579 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrdering &ordering_rule) const { |
| 2580 | const auto &ordering = GetOrderingRules(ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2581 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 2582 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2583 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2584 | const auto usage_stage = PipelineStageBit(usage_index); |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2585 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
| 2586 | const bool last_write_is_ordered = (last_write & ordering.access_scope).any(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2587 | if (IsRead(usage_bit)) { |
| 2588 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 2589 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 2590 | if (is_raw_hazard) { |
| 2591 | // NOTE: we know last_write is non-zero |
| 2592 | // See if the ordering rules save us from the simple RAW check above |
| 2593 | // First check to see if the current usage is covered by the ordering rules |
| 2594 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 2595 | const bool usage_is_ordered = |
| 2596 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 2597 | if (usage_is_ordered) { |
| 2598 | // Now see of the most recent write (or a subsequent read) are ordered |
| 2599 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(ordering)); |
| 2600 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2601 | } |
| 2602 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2603 | if (is_raw_hazard) { |
| 2604 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 2605 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2606 | } else { |
| 2607 | // Only check for WAW if there are no reads since last_write |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2608 | bool usage_write_is_ordered = (usage_bit & ordering.access_scope).any(); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2609 | if (last_reads.size()) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2610 | // Look for any WAR hazards outside the ordered set of stages |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2611 | VkPipelineStageFlags2KHR ordered_stages = 0; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2612 | if (usage_write_is_ordered) { |
| 2613 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
| 2614 | ordered_stages = GetOrderedStages(ordering); |
| 2615 | } |
| 2616 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 2617 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2618 | for (const auto &read_access : last_reads) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2619 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 2620 | if (IsReadHazard(usage_stage, read_access)) { |
| 2621 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2622 | break; |
| 2623 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2624 | } |
| 2625 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2626 | } else if (!(last_write_is_ordered && usage_write_is_ordered)) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2627 | if (last_write.any() && IsWriteHazard(usage_bit)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2628 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2629 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2630 | } |
| 2631 | } |
| 2632 | return hazard; |
| 2633 | } |
| 2634 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2635 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2636 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index, const ResourceUsageTag &start_tag) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2637 | HazardResult hazard; |
| 2638 | auto usage = FlagBit(usage_index); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2639 | // Async checks need to not go back further than the start of the subpass, as we only want to find hazards between the async |
| 2640 | // subpasses. Anything older than that should have been checked at the start of each subpass, taking into account all of |
| 2641 | // the raster ordering rules. |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2642 | if (IsRead(usage)) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2643 | if (last_write.any() && (write_tag.index >= start_tag.index)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2644 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2645 | } |
| 2646 | } else { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2647 | if (last_write.any() && (write_tag.index >= start_tag.index)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2648 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2649 | } else if (last_reads.size() > 0) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2650 | // 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] | 2651 | for (const auto &read_access : last_reads) { |
| 2652 | if (read_access.tag.index >= start_tag.index) { |
| 2653 | 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] | 2654 | break; |
| 2655 | } |
| 2656 | } |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2657 | } |
| 2658 | } |
| 2659 | return hazard; |
| 2660 | } |
| 2661 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2662 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2663 | const SyncStageAccessFlags &src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2664 | // Only supporting image layout transitions for now |
| 2665 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2666 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2667 | // only test for WAW if there no intervening read operations. |
| 2668 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2669 | if (last_reads.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2670 | // Look at the reads if any |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2671 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2672 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2673 | 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] | 2674 | break; |
| 2675 | } |
| 2676 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2677 | } else if (last_write.any() && IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2678 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2679 | } |
| 2680 | |
| 2681 | return hazard; |
| 2682 | } |
| 2683 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2684 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags2KHR src_exec_scope, |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2685 | const SyncStageAccessFlags &src_access_scope, |
| 2686 | const ResourceUsageTag &event_tag) const { |
| 2687 | // Only supporting image layout transitions for now |
| 2688 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2689 | HazardResult hazard; |
| 2690 | // only test for WAW if there no intervening read operations. |
| 2691 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 2692 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2693 | if (last_reads.size()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2694 | // Look at the reads if any... if reads exist, they are either the resaon the access is in the event |
| 2695 | // first scope, or they are a hazard. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2696 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2697 | if (read_access.tag.IsBefore(event_tag)) { |
| 2698 | // The read is in the events first synchronization scope, so we use a barrier hazard check |
| 2699 | // If the read stage is not in the src sync scope |
| 2700 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 2701 | // then the barrier access is unsafe (R/W after R) |
| 2702 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
| 2703 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2704 | break; |
| 2705 | } |
| 2706 | } else { |
| 2707 | // The read not in the event first sync scope and so is a hazard vs. the layout transition |
| 2708 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2709 | } |
| 2710 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2711 | } else if (last_write.any()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2712 | // if there are no reads, the write is either the reason the access is in the event scope... they are a hazard |
| 2713 | if (write_tag.IsBefore(event_tag)) { |
| 2714 | // The write is in the first sync scope of the event (sync their aren't any reads to be the reason) |
| 2715 | // So do a normal barrier hazard check |
| 2716 | if (IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2717 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2718 | } |
| 2719 | } else { |
| 2720 | // 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] | 2721 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2722 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2723 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2724 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2725 | return hazard; |
| 2726 | } |
| 2727 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2728 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 2729 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 2730 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 2731 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
| 2732 | if (write_tag.IsBefore(other.write_tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2733 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 2734 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2735 | *this = other; |
| 2736 | } else if (!other.write_tag.IsBefore(write_tag)) { |
| 2737 | // This is the *equals* case for write operations, we merged the write barriers and the read state (but without the |
| 2738 | // dependency chaining logic or any stage expansion) |
| 2739 | write_barriers |= other.write_barriers; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2740 | pending_write_barriers |= other.pending_write_barriers; |
| 2741 | pending_layout_transition |= other.pending_layout_transition; |
| 2742 | pending_write_dep_chain |= other.pending_write_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2743 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2744 | // Merge the read states |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2745 | const auto pre_merge_count = last_reads.size(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2746 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2747 | 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] | 2748 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2749 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2750 | // 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] | 2751 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 2752 | // but we should wait on profiling data for that. |
| 2753 | 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] | 2754 | auto &my_read = last_reads[my_read_index]; |
| 2755 | if (other_read.stage == my_read.stage) { |
| 2756 | if (my_read.tag.IsBefore(other_read.tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2757 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2758 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2759 | my_read.tag = other_read.tag; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2760 | my_read.pending_dep_chain = other_read.pending_dep_chain; |
| 2761 | // TODO: Phase 2 -- review the state merge logic to avoid false positive from overwriting the barriers |
| 2762 | // May require tracking more than one access per stage. |
| 2763 | my_read.barriers = other_read.barriers; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2764 | if (my_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2765 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 2766 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2767 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2768 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2769 | } else if (other_read.tag.IsBefore(my_read.tag)) { |
| 2770 | // The read tags match so merge the barriers |
| 2771 | my_read.barriers |= other_read.barriers; |
| 2772 | my_read.pending_dep_chain |= other_read.pending_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2773 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2774 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2775 | break; |
| 2776 | } |
| 2777 | } |
| 2778 | } else { |
| 2779 | // The other read stage doesn't exist in this, so add it. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2780 | last_reads.emplace_back(other_read); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2781 | last_read_stages |= other_read.stage; |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2782 | if (other_read.stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2783 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2784 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2785 | } |
| 2786 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2787 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2788 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 2789 | // ignore it. |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2790 | |
| 2791 | // Merge first access information by making a copy of this first_access and reconstructing with a shuffle |
| 2792 | // of the copy and other into this using the update first logic. |
| 2793 | // NOTE: All sorts of additional cleverness could be put into short circuts. (for example back is write and is before front |
| 2794 | // of the other first_accesses... ) |
| 2795 | if (!(first_accesses_ == other.first_accesses_) && !other.first_accesses_.empty()) { |
| 2796 | FirstAccesses firsts(std::move(first_accesses_)); |
| 2797 | first_accesses_.clear(); |
| 2798 | first_read_stages_ = 0U; |
| 2799 | auto a = firsts.begin(); |
| 2800 | auto a_end = firsts.end(); |
| 2801 | for (auto &b : other.first_accesses_) { |
| 2802 | // TODO: Determine whether "IsBefore" or "IsGloballyBefore" is needed... |
| 2803 | while (a != a_end && a->tag.IsBefore(b.tag)) { |
| 2804 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 2805 | ++a; |
| 2806 | } |
| 2807 | UpdateFirst(b.tag, b.usage_index, b.ordering_rule); |
| 2808 | } |
| 2809 | for (; a != a_end; ++a) { |
| 2810 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 2811 | } |
| 2812 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2813 | } |
| 2814 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2815 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, SyncOrdering ordering_rule, const ResourceUsageTag &tag) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2816 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 2817 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2818 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2819 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 2820 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 2821 | const auto usage_stage = PipelineStageBit(usage_index); |
| 2822 | if (usage_stage & last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2823 | for (auto &read_access : last_reads) { |
| 2824 | if (read_access.stage == usage_stage) { |
| 2825 | read_access.Set(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2826 | break; |
| 2827 | } |
| 2828 | } |
| 2829 | } else { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2830 | last_reads.emplace_back(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2831 | last_read_stages |= usage_stage; |
| 2832 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2833 | |
| 2834 | // 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] | 2835 | if (usage_stage == VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2836 | // TODO Revisit re: multiple reads for a given stage |
| 2837 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2838 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2839 | } else { |
| 2840 | // Assume write |
| 2841 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2842 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2843 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2844 | UpdateFirst(tag, usage_index, ordering_rule); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2845 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2846 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2847 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 2848 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 2849 | // We can overwrite them as *this* write is now after them. |
| 2850 | // |
| 2851 | // 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] | 2852 | void ResourceAccessState::SetWrite(const SyncStageAccessFlags &usage_bit, const ResourceUsageTag &tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2853 | last_reads.clear(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2854 | last_read_stages = 0; |
| 2855 | read_execution_barriers = 0; |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2856 | 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] | 2857 | |
| 2858 | write_barriers = 0; |
| 2859 | write_dependency_chain = 0; |
| 2860 | write_tag = tag; |
| 2861 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2862 | } |
| 2863 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2864 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 2865 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 2866 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 2867 | // replace the current write barriers or add to them, so accumulate to pending as well. |
| 2868 | void ResourceAccessState::ApplyBarrier(const SyncBarrier &barrier, bool layout_transition) { |
| 2869 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 2870 | // applying the memory barriers |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 2871 | // NOTE: We update the write barrier if the write is in the first access scope or if there is a layout |
| 2872 | // transistion, under the theory of "most recent access". If the read/write *isn't* safe |
| 2873 | // vs. this layout transition DetectBarrierHazard should report it. We treat the layout |
| 2874 | // 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] | 2875 | 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] | 2876 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2877 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2878 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2879 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 2880 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2881 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2882 | if (!pending_layout_transition) { |
| 2883 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 2884 | // 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] | 2885 | for (auto &read_access : last_reads) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2886 | // 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] | 2887 | if (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers)) { |
| 2888 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2889 | } |
| 2890 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2891 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2892 | } |
| 2893 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2894 | // Apply the tag scoped memory barrier without updating the existing barriers. The execution barrier |
| 2895 | // changes the "chaining" state, but to keep barriers independent. See discussion above. |
| 2896 | void ResourceAccessState::ApplyBarrier(const ResourceUsageTag &scope_tag, const SyncBarrier &barrier, bool layout_transition) { |
| 2897 | // The scope logic for events is, if we're here, the resource usage was flagged as "in the first execution scope" at |
| 2898 | // the time of the SetEvent, thus all we need check is whether the access is the same one (i.e. before the scope tag |
| 2899 | // in order to know if it's in the excecution scope |
| 2900 | // Notice that the layout transition sets the pending barriers *regardless*, as any lack of src_access_scope to |
| 2901 | // guard against the layout transition should be reported in the detect barrier hazard phase, and we only report |
| 2902 | // errors w.r.t. "most recent" accesses. |
| 2903 | if (layout_transition || ((write_tag.IsBefore(scope_tag)) && (barrier.src_access_scope & last_write).any())) { |
| 2904 | pending_write_barriers |= barrier.dst_access_scope; |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 2905 | pending_write_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2906 | } |
| 2907 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 2908 | pending_layout_transition |= layout_transition; |
| 2909 | |
| 2910 | if (!pending_layout_transition) { |
| 2911 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 2912 | // 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] | 2913 | for (auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2914 | // If this read is the same one we included in the set event and in scope, then apply the execution barrier... |
| 2915 | // NOTE: That's not really correct... this read stage might *not* have been included in the setevent, and the barriers |
| 2916 | // representing the chain might have changed since then (that would be an odd usage), so as a first approximation |
| 2917 | // we'll assume the barriers *haven't* been changed since (if the tag hasn't), and while this could be a false |
| 2918 | // positive in the case of Set; SomeBarrier; Wait; we'll live with it until we can add more state to the first scope |
| 2919 | // capture (the specific write and read stages that *were* in scope at the moment of SetEvents. |
| 2920 | // 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] | 2921 | if (read_access.tag.IsBefore(scope_tag) && |
| 2922 | (barrier.src_exec_scope.exec_scope & (read_access.stage | read_access.barriers))) { |
| 2923 | read_access.pending_dep_chain |= barrier.dst_exec_scope.exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2924 | } |
| 2925 | } |
| 2926 | } |
| 2927 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2928 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag &tag) { |
| 2929 | if (pending_layout_transition) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2930 | // SetWrite clobbers the read count, and thus we don't have to clear the read_state out. |
| 2931 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2932 | UpdateFirst(tag, SYNC_IMAGE_LAYOUT_TRANSITION, SyncOrdering::kNonAttachment); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2933 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2934 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2935 | |
| 2936 | // Apply the accumulate execution barriers (and thus update chaining information) |
| 2937 | // 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] | 2938 | for (auto &read_access : last_reads) { |
| 2939 | read_access.barriers |= read_access.pending_dep_chain; |
| 2940 | read_execution_barriers |= read_access.barriers; |
| 2941 | read_access.pending_dep_chain = 0; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 2945 | write_dependency_chain |= pending_write_dep_chain; |
| 2946 | write_barriers |= pending_write_barriers; |
| 2947 | pending_write_dep_chain = 0; |
| 2948 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2949 | } |
| 2950 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2951 | // 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] | 2952 | VkPipelineStageFlags2KHR ResourceAccessState::GetReadBarriers(const SyncStageAccessFlags &usage_bit) const { |
| 2953 | VkPipelineStageFlags2KHR barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2954 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2955 | for (const auto &read_access : last_reads) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2956 | if ((read_access.access & usage_bit).any()) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2957 | barriers = read_access.barriers; |
| 2958 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2959 | } |
| 2960 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2961 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2962 | return barriers; |
| 2963 | } |
| 2964 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2965 | inline bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlags2KHR usage_stage, const SyncStageAccessFlags &usage) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2966 | assert(IsRead(usage)); |
| 2967 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 2968 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 2969 | // any reads that happen after. |
| 2970 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 2971 | // 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] | 2972 | return last_write.any() && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2973 | } |
| 2974 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2975 | VkPipelineStageFlags2KHR ResourceAccessState::GetOrderedStages(const OrderingBarrier &ordering) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2976 | // 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] | 2977 | VkPipelineStageFlags2KHR ordered_stages = last_read_stages & ordering.exec_scope; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2978 | // Special input attachment handling as always (not encoded in exec_scop) |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2979 | 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] | 2980 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2981 | // 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] | 2982 | ordered_stages |= VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | return ordered_stages; |
| 2986 | } |
| 2987 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2988 | void ResourceAccessState::UpdateFirst(const ResourceUsageTag &tag, SyncStageAccessIndex usage_index, SyncOrdering ordering_rule) { |
| 2989 | // Only record until we record a write. |
| 2990 | if (first_accesses_.empty() || IsRead(first_accesses_.back().usage_index)) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 2991 | const VkPipelineStageFlags2KHR usage_stage = IsRead(usage_index) ? PipelineStageBit(usage_index) : 0U; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2992 | if (0 == (usage_stage & first_read_stages_)) { |
| 2993 | // If this is a read we haven't seen or a write, record. |
| 2994 | first_read_stages_ |= usage_stage; |
| 2995 | first_accesses_.emplace_back(tag, usage_index, ordering_rule); |
| 2996 | } |
| 2997 | } |
| 2998 | } |
| 2999 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3000 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3001 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 3002 | if (access_context) { |
| 3003 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3004 | } |
| 3005 | } |
| 3006 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3007 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 3008 | auto access_found = cb_access_state.find(command_buffer); |
| 3009 | if (access_found != cb_access_state.end()) { |
| 3010 | access_found->second->Reset(); |
| 3011 | cb_access_state.erase(access_found); |
| 3012 | } |
| 3013 | } |
| 3014 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3015 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3016 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 3017 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3018 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3019 | assert(cb_context); |
| 3020 | if (!cb_context) return skip; |
| 3021 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3022 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3023 | // If we have no previous accesses, we have no hazards |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3024 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3025 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3026 | |
| 3027 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3028 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3029 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3030 | 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] | 3031 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3032 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3033 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3034 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3035 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3036 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3037 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3038 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3039 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3040 | 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] | 3041 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3042 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3043 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3044 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3045 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3046 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3047 | } |
| 3048 | } |
| 3049 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3050 | } |
| 3051 | return skip; |
| 3052 | } |
| 3053 | |
| 3054 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3055 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3056 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3057 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3058 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3059 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3060 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3061 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3062 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3063 | |
| 3064 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3065 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3066 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3067 | 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] | 3068 | 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] | 3069 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3070 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3071 | 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] | 3072 | 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] | 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3077 | void SyncValidator::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 3078 | // Clear out events from the command buffer contexts |
| 3079 | for (auto &cb_context : cb_access_state) { |
| 3080 | cb_context.second->RecordDestroyEvent(event); |
| 3081 | } |
| 3082 | } |
| 3083 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3084 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3085 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 3086 | bool skip = false; |
| 3087 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3088 | assert(cb_context); |
| 3089 | if (!cb_context) return skip; |
| 3090 | const auto *context = cb_context->GetCurrentAccessContext(); |
| 3091 | |
| 3092 | // If we have no previous accesses, we have no hazards |
| 3093 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3094 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3095 | |
| 3096 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3097 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3098 | if (src_buffer) { |
| 3099 | 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] | 3100 | auto hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3101 | if (hazard.hazard) { |
| 3102 | // TODO -- add tag information to log msg when useful. |
| 3103 | skip |= LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3104 | "vkCmdCopyBuffer2KHR(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3105 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3106 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3107 | } |
| 3108 | } |
| 3109 | if (dst_buffer && !skip) { |
| 3110 | 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] | 3111 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3112 | if (hazard.hazard) { |
| 3113 | skip |= LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3114 | "vkCmdCopyBuffer2KHR(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3115 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3116 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3117 | } |
| 3118 | } |
| 3119 | if (skip) break; |
| 3120 | } |
| 3121 | return skip; |
| 3122 | } |
| 3123 | |
| 3124 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 3125 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3126 | assert(cb_context); |
| 3127 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER2KHR); |
| 3128 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3129 | |
| 3130 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3131 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3132 | |
| 3133 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3134 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3135 | if (src_buffer) { |
| 3136 | 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] | 3137 | 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] | 3138 | } |
| 3139 | if (dst_buffer) { |
| 3140 | 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] | 3141 | 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] | 3142 | } |
| 3143 | } |
| 3144 | } |
| 3145 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3146 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3147 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3148 | const VkImageCopy *pRegions) const { |
| 3149 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3150 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3151 | assert(cb_access_context); |
| 3152 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3153 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3154 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3155 | assert(context); |
| 3156 | if (!context) return skip; |
| 3157 | |
| 3158 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3159 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3160 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3161 | const auto ©_region = pRegions[region]; |
| 3162 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3163 | 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] | 3164 | copy_region.srcOffset, copy_region.extent); |
| 3165 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3166 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3167 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3168 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3169 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3170 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3174 | VkExtent3D dst_copy_extent = |
| 3175 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3176 | 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] | 3177 | copy_region.dstOffset, dst_copy_extent); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3178 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3179 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3180 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3181 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3182 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3183 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 3184 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3185 | } |
| 3186 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3187 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3188 | return skip; |
| 3189 | } |
| 3190 | |
| 3191 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3192 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3193 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3194 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3195 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3196 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3197 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3198 | assert(context); |
| 3199 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3200 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3201 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3202 | |
| 3203 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3204 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3205 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3206 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3207 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3208 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3209 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3210 | VkExtent3D dst_copy_extent = |
| 3211 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3212 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3213 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3214 | } |
| 3215 | } |
| 3216 | } |
| 3217 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3218 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 3219 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 3220 | bool skip = false; |
| 3221 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3222 | assert(cb_access_context); |
| 3223 | if (!cb_access_context) return skip; |
| 3224 | |
| 3225 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3226 | assert(context); |
| 3227 | if (!context) return skip; |
| 3228 | |
| 3229 | const auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3230 | const auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3231 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3232 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3233 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3234 | 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] | 3235 | copy_region.srcOffset, copy_region.extent); |
| 3236 | if (hazard.hazard) { |
| 3237 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 3238 | "vkCmdCopyImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 3239 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3240 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3241 | } |
| 3242 | } |
| 3243 | |
| 3244 | if (dst_image) { |
| 3245 | VkExtent3D dst_copy_extent = |
| 3246 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3247 | 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] | 3248 | copy_region.dstOffset, dst_copy_extent); |
| 3249 | if (hazard.hazard) { |
| 3250 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 3251 | "vkCmdCopyImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 3252 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3253 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3254 | } |
| 3255 | if (skip) break; |
| 3256 | } |
| 3257 | } |
| 3258 | |
| 3259 | return skip; |
| 3260 | } |
| 3261 | |
| 3262 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 3263 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3264 | assert(cb_access_context); |
| 3265 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE2KHR); |
| 3266 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3267 | assert(context); |
| 3268 | |
| 3269 | auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3270 | auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3271 | |
| 3272 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3273 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3274 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3275 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3276 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3277 | } |
| 3278 | if (dst_image) { |
| 3279 | VkExtent3D dst_copy_extent = |
| 3280 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3281 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3282 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3283 | } |
| 3284 | } |
| 3285 | } |
| 3286 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3287 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3288 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3289 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3290 | uint32_t bufferMemoryBarrierCount, |
| 3291 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3292 | uint32_t imageMemoryBarrierCount, |
| 3293 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 3294 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3295 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3296 | assert(cb_access_context); |
| 3297 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3298 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 3299 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 3300 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 3301 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 3302 | pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 3303 | skip = pipeline_barrier.Validate(*cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3304 | return skip; |
| 3305 | } |
| 3306 | |
| 3307 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3308 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3309 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3310 | uint32_t bufferMemoryBarrierCount, |
| 3311 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3312 | uint32_t imageMemoryBarrierCount, |
| 3313 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3314 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3315 | assert(cb_access_context); |
| 3316 | if (!cb_access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3317 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 3318 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER, *this, cb_access_context->GetQueueFlags(), srcStageMask, |
| 3319 | dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 3320 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 3321 | pImageMemoryBarriers); |
| 3322 | pipeline_barrier.Record(cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3323 | } |
| 3324 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 3325 | bool SyncValidator::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 3326 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 3327 | bool skip = false; |
| 3328 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3329 | assert(cb_access_context); |
| 3330 | if (!cb_access_context) return skip; |
| 3331 | |
| 3332 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3333 | skip = pipeline_barrier.Validate(*cb_access_context); |
| 3334 | return skip; |
| 3335 | } |
| 3336 | |
| 3337 | void SyncValidator::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) { |
| 3338 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3339 | assert(cb_access_context); |
| 3340 | if (!cb_access_context) return; |
| 3341 | |
| 3342 | SyncOpPipelineBarrier pipeline_barrier(CMD_PIPELINEBARRIER2KHR, *this, cb_access_context->GetQueueFlags(), *pDependencyInfo); |
| 3343 | pipeline_barrier.Record(cb_access_context); |
| 3344 | } |
| 3345 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3346 | void SyncValidator::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 3347 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result) { |
| 3348 | // The state tracker sets up the device state |
| 3349 | StateTracker::PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, result); |
| 3350 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3351 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 3352 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3353 | // TODO: Find a good way to do this hooklessly. |
| 3354 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 3355 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, LayerObjectTypeSyncValidation); |
| 3356 | SyncValidator *sync_device_state = static_cast<SyncValidator *>(validation_data); |
| 3357 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3358 | sync_device_state->SetCommandBufferResetCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3359 | sync_device_state->ResetCommandBufferCallback(command_buffer); |
| 3360 | }); |
| 3361 | sync_device_state->SetCommandBufferFreeCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3362 | sync_device_state->FreeCommandBufferCallback(command_buffer); |
| 3363 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3364 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3365 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3366 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3367 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd, const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3368 | bool skip = false; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3369 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3370 | if (cb_context) { |
| 3371 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo, cmd_name); |
| 3372 | skip = sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3373 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3374 | return skip; |
| 3375 | } |
| 3376 | |
| 3377 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3378 | VkSubpassContents contents) const { |
| 3379 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3380 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3381 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3382 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3383 | return skip; |
| 3384 | } |
| 3385 | |
| 3386 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3387 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3388 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3389 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3390 | return skip; |
| 3391 | } |
| 3392 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3393 | static const char *kBeginRenderPass2KhrName = "vkCmdBeginRenderPass2KHR"; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3394 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3395 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3396 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3397 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3398 | skip |= |
| 3399 | ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2, kBeginRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3400 | return skip; |
| 3401 | } |
| 3402 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3403 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 3404 | VkResult result) { |
| 3405 | // The state tracker sets up the command buffer state |
| 3406 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 3407 | |
| 3408 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 3409 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 3410 | assert(cb_access_context); |
| 3411 | cb_access_context->Reset(); |
| 3412 | } |
| 3413 | |
| 3414 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3415 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE cmd, const char *cmd_name) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3416 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3417 | if (cb_context) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3418 | SyncOpBeginRenderPass sync_op(cmd, *this, pRenderPassBegin, pSubpassBeginInfo, cmd_name); |
| 3419 | sync_op.Record(cb_context); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3420 | } |
| 3421 | } |
| 3422 | |
| 3423 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3424 | VkSubpassContents contents) { |
| 3425 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3426 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3427 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3428 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3432 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3433 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3434 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3438 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3439 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3440 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3441 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2, kBeginRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3442 | } |
| 3443 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3444 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3445 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3446 | bool skip = false; |
| 3447 | |
| 3448 | auto cb_context = GetAccessContext(commandBuffer); |
| 3449 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3450 | if (!cb_context) return skip; |
| 3451 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo, cmd_name); |
| 3452 | return sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 3456 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3457 | // Convert to a NextSubpass2 |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3458 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3459 | subpass_begin_info.contents = contents; |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3460 | auto subpass_end_info = LvlInitStruct<VkSubpassEndInfo>(); |
| 3461 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, &subpass_end_info, CMD_NEXTSUBPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3462 | return skip; |
| 3463 | } |
| 3464 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3465 | static const char *kNextSubpass2KhrName = "vkCmdNextSubpass2KHR"; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3466 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3467 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3468 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3469 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2, kNextSubpass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3470 | return skip; |
| 3471 | } |
| 3472 | |
| 3473 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3474 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 3475 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3476 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3477 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3481 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, const char *cmd_name) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3482 | auto cb_context = GetAccessContext(commandBuffer); |
| 3483 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3484 | if (!cb_context) return; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3485 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3486 | SyncOpNextSubpass sync_op(cmd, *this, pSubpassBeginInfo, pSubpassEndInfo, cmd_name); |
| 3487 | sync_op.Record(cb_context); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 3491 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3492 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3493 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3494 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3498 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3499 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3500 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3504 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3505 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3506 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2, kNextSubpass2KhrName); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3507 | } |
| 3508 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3509 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, |
| 3510 | const char *cmd_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3511 | bool skip = false; |
| 3512 | |
| 3513 | auto cb_context = GetAccessContext(commandBuffer); |
| 3514 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3515 | if (!cb_context) return skip; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3516 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3517 | SyncOpEndRenderPass sync_op(cmd, *this, pSubpassEndInfo, cmd_name); |
| 3518 | skip |= sync_op.Validate(*cb_context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3519 | return skip; |
| 3520 | } |
| 3521 | |
| 3522 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 3523 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3524 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3525 | return skip; |
| 3526 | } |
| 3527 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3528 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3529 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3530 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3531 | return skip; |
| 3532 | } |
| 3533 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3534 | const static char *kEndRenderPass2KhrName = "vkEndRenderPass2KHR"; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3535 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3536 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3537 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3538 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2, kEndRenderPass2KhrName); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3539 | return skip; |
| 3540 | } |
| 3541 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3542 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE cmd, |
| 3543 | const char *cmd_name) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3544 | // Resolve the all subpass contexts to the command buffer contexts |
| 3545 | auto cb_context = GetAccessContext(commandBuffer); |
| 3546 | assert(cb_context); |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3547 | if (!cb_context) return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3548 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3549 | SyncOpEndRenderPass sync_op(cmd, *this, pSubpassEndInfo, cmd_name); |
| 3550 | sync_op.Record(cb_context); |
| 3551 | return; |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3552 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3553 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 3554 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 3555 | // updates to a resource which do not conflict at the byte level. |
| 3556 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 3557 | // TODO: Add programatic control over suppression heuristics |
| 3558 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 3559 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 3560 | } |
| 3561 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3562 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3563 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3564 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3568 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3569 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 3573 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2, kEndRenderPass2KhrName); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3574 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3575 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3576 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3577 | template <typename BufferImageCopyRegionType> |
| 3578 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3579 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3580 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3581 | bool skip = false; |
| 3582 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3583 | assert(cb_access_context); |
| 3584 | if (!cb_access_context) return skip; |
| 3585 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3586 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3587 | const char *func_name = is_2khr ? "vkCmdCopyBufferToImage2KHR()" : "vkCmdCopyBufferToImage()"; |
| 3588 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3589 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3590 | assert(context); |
| 3591 | if (!context) return skip; |
| 3592 | |
| 3593 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3594 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3595 | |
| 3596 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3597 | const auto ©_region = pRegions[region]; |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3598 | HazardResult hazard; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3599 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3600 | if (src_buffer) { |
| 3601 | ResourceAccessRange src_range = |
| 3602 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3603 | hazard = context->DetectHazard(*src_buffer, SYNC_COPY_TRANSFER_READ, src_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3604 | if (hazard.hazard) { |
| 3605 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 3606 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3607 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3608 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3609 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3610 | } |
| 3611 | } |
| 3612 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3613 | hazard = context->DetectHazard(*dst_image, SYNC_COPY_TRANSFER_WRITE, copy_region.imageSubresource, |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3614 | copy_region.imageOffset, copy_region.imageExtent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3615 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3616 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3617 | "%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] | 3618 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3619 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3620 | } |
| 3621 | if (skip) break; |
| 3622 | } |
| 3623 | if (skip) break; |
| 3624 | } |
| 3625 | return skip; |
| 3626 | } |
| 3627 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3628 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3629 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3630 | const VkBufferImageCopy *pRegions) const { |
| 3631 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
| 3632 | COPY_COMMAND_VERSION_1); |
| 3633 | } |
| 3634 | |
| 3635 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3636 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 3637 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3638 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3639 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3640 | } |
| 3641 | |
| 3642 | template <typename BufferImageCopyRegionType> |
| 3643 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3644 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3645 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3646 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3647 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3648 | |
| 3649 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3650 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYBUFFERTOIMAGE2KHR : CMD_COPYBUFFERTOIMAGE; |
| 3651 | |
| 3652 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3653 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3654 | assert(context); |
| 3655 | |
| 3656 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3657 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3658 | |
| 3659 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3660 | const auto ©_region = pRegions[region]; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3661 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3662 | if (src_buffer) { |
| 3663 | ResourceAccessRange src_range = |
| 3664 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3665 | 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] | 3666 | } |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3667 | context->UpdateAccessState(*dst_image, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3668 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3669 | } |
| 3670 | } |
| 3671 | } |
| 3672 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3673 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3674 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3675 | const VkBufferImageCopy *pRegions) { |
| 3676 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
| 3677 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3678 | } |
| 3679 | |
| 3680 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3681 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 3682 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 3683 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3684 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3685 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3686 | } |
| 3687 | |
| 3688 | template <typename BufferImageCopyRegionType> |
| 3689 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3690 | VkBuffer dstBuffer, uint32_t regionCount, |
| 3691 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3692 | bool skip = false; |
| 3693 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3694 | assert(cb_access_context); |
| 3695 | if (!cb_access_context) return skip; |
| 3696 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3697 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3698 | const char *func_name = is_2khr ? "vkCmdCopyImageToBuffer2KHR()" : "vkCmdCopyImageToBuffer()"; |
| 3699 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3700 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3701 | assert(context); |
| 3702 | if (!context) return skip; |
| 3703 | |
| 3704 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3705 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3706 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->binding.mem_state->mem : VK_NULL_HANDLE; |
| 3707 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3708 | const auto ©_region = pRegions[region]; |
| 3709 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3710 | 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] | 3711 | copy_region.imageOffset, copy_region.imageExtent); |
| 3712 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3713 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3714 | "%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] | 3715 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3716 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3717 | } |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3718 | if (dst_mem) { |
| 3719 | ResourceAccessRange dst_range = |
| 3720 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3721 | hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, dst_range); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3722 | if (hazard.hazard) { |
| 3723 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3724 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3725 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3726 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3727 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3728 | } |
| 3729 | } |
| 3730 | if (skip) break; |
| 3731 | } |
| 3732 | return skip; |
| 3733 | } |
| 3734 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3735 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 3736 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 3737 | const VkBufferImageCopy *pRegions) const { |
| 3738 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
| 3739 | COPY_COMMAND_VERSION_1); |
| 3740 | } |
| 3741 | |
| 3742 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3743 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 3744 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3745 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3746 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3747 | } |
| 3748 | |
| 3749 | template <typename BufferImageCopyRegionType> |
| 3750 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3751 | VkBuffer dstBuffer, uint32_t regionCount, const BufferImageCopyRegionType *pRegions, |
| 3752 | CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3753 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3754 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3755 | |
| 3756 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3757 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYIMAGETOBUFFER2KHR : CMD_COPYIMAGETOBUFFER; |
| 3758 | |
| 3759 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3760 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3761 | assert(context); |
| 3762 | |
| 3763 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3764 | auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3765 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->binding.mem_state->mem : VK_NULL_HANDLE; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3766 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3767 | |
| 3768 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3769 | const auto ©_region = pRegions[region]; |
| 3770 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3771 | context->UpdateAccessState(*src_image, SYNC_COPY_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3772 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3773 | if (dst_buffer) { |
| 3774 | ResourceAccessRange dst_range = |
| 3775 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 3776 | 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] | 3777 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3778 | } |
| 3779 | } |
| 3780 | } |
| 3781 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3782 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3783 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 3784 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
| 3785 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3786 | } |
| 3787 | |
| 3788 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3789 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 3790 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 3791 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3792 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3793 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3794 | } |
| 3795 | |
| 3796 | template <typename RegionType> |
| 3797 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3798 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3799 | const RegionType *pRegions, VkFilter filter, const char *apiName) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3800 | bool skip = false; |
| 3801 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3802 | assert(cb_access_context); |
| 3803 | if (!cb_access_context) return skip; |
| 3804 | |
| 3805 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3806 | assert(context); |
| 3807 | if (!context) return skip; |
| 3808 | |
| 3809 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3810 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3811 | |
| 3812 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3813 | const auto &blit_region = pRegions[region]; |
| 3814 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3815 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3816 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3817 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3818 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3819 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3820 | 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] | 3821 | 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] | 3822 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3823 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3824 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3825 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3826 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3827 | } |
| 3828 | } |
| 3829 | |
| 3830 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3831 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3832 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3833 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3834 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3835 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3836 | 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] | 3837 | 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] | 3838 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3839 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3840 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3841 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3842 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3843 | } |
| 3844 | if (skip) break; |
| 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | return skip; |
| 3849 | } |
| 3850 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3851 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3852 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3853 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 3854 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
| 3855 | "vkCmdBlitImage"); |
| 3856 | } |
| 3857 | |
| 3858 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 3859 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 3860 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 3861 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 3862 | pBlitImageInfo->filter, "vkCmdBlitImage2KHR"); |
| 3863 | } |
| 3864 | |
| 3865 | template <typename RegionType> |
| 3866 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3867 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3868 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3869 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3870 | assert(cb_access_context); |
| 3871 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3872 | assert(context); |
| 3873 | |
| 3874 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3875 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3876 | |
| 3877 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3878 | const auto &blit_region = pRegions[region]; |
| 3879 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3880 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3881 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3882 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3883 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3884 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3885 | 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] | 3886 | context->UpdateAccessState(*src_image, SYNC_BLIT_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3887 | blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3888 | } |
| 3889 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3890 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3891 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3892 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3893 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3894 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3895 | 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] | 3896 | context->UpdateAccessState(*dst_image, SYNC_BLIT_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3897 | blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3898 | } |
| 3899 | } |
| 3900 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3901 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3902 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3903 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3904 | const VkImageBlit *pRegions, VkFilter filter) { |
| 3905 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3906 | assert(cb_access_context); |
| 3907 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 3908 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 3909 | pRegions, filter); |
| 3910 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 3911 | } |
| 3912 | |
| 3913 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 3914 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 3915 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3916 | assert(cb_access_context); |
| 3917 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 3918 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 3919 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 3920 | pBlitImageInfo->filter, tag); |
| 3921 | } |
| 3922 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3923 | bool SyncValidator::ValidateIndirectBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 3924 | VkCommandBuffer commandBuffer, const VkDeviceSize struct_size, const VkBuffer buffer, |
| 3925 | const VkDeviceSize offset, const uint32_t drawCount, const uint32_t stride, |
| 3926 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3927 | bool skip = false; |
| 3928 | if (drawCount == 0) return skip; |
| 3929 | |
| 3930 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 3931 | VkDeviceSize size = struct_size; |
| 3932 | if (drawCount == 1 || stride == size) { |
| 3933 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3934 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3935 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3936 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3937 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3938 | "%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] | 3939 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3940 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3941 | } |
| 3942 | } else { |
| 3943 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3944 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3945 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3946 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3947 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3948 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
| 3949 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3950 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3951 | break; |
| 3952 | } |
| 3953 | } |
| 3954 | } |
| 3955 | return skip; |
| 3956 | } |
| 3957 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3958 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag &tag, const VkDeviceSize struct_size, |
| 3959 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 3960 | uint32_t stride) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3961 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 3962 | VkDeviceSize size = struct_size; |
| 3963 | if (drawCount == 1 || stride == size) { |
| 3964 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3965 | const ResourceAccessRange range = MakeRange(offset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3966 | 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] | 3967 | } else { |
| 3968 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3969 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3970 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, |
| 3971 | tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3972 | } |
| 3973 | } |
| 3974 | } |
| 3975 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3976 | bool SyncValidator::ValidateCountBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 3977 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3978 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3979 | bool skip = false; |
| 3980 | |
| 3981 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3982 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3983 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3984 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3985 | skip |= LogError(count_buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3986 | "%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] | 3987 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3988 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3989 | } |
| 3990 | return skip; |
| 3991 | } |
| 3992 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3993 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag &tag, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3994 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3995 | const ResourceAccessRange range = MakeRange(offset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3996 | 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] | 3997 | } |
| 3998 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3999 | 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] | 4000 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4001 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4002 | assert(cb_access_context); |
| 4003 | if (!cb_access_context) return skip; |
| 4004 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4005 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4006 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4007 | } |
| 4008 | |
| 4009 | 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] | 4010 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4011 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4012 | assert(cb_access_context); |
| 4013 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4014 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4015 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4016 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4017 | |
| 4018 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4019 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4020 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4021 | assert(cb_access_context); |
| 4022 | if (!cb_access_context) return skip; |
| 4023 | |
| 4024 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4025 | assert(context); |
| 4026 | if (!context) return skip; |
| 4027 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4028 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4029 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, |
| 4030 | 1, sizeof(VkDispatchIndirectCommand), "vkCmdDispatchIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4031 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4035 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4036 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4037 | assert(cb_access_context); |
| 4038 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 4039 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4040 | assert(context); |
| 4041 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4042 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 4043 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4047 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4048 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4049 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4050 | assert(cb_access_context); |
| 4051 | if (!cb_access_context) return skip; |
| 4052 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4053 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw"); |
| 4054 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, "vkCmdDraw"); |
| 4055 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDraw"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4056 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4060 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4061 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4062 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4063 | assert(cb_access_context); |
| 4064 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4065 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4066 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4067 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 4068 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4072 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4073 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4074 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4075 | assert(cb_access_context); |
| 4076 | if (!cb_access_context) return skip; |
| 4077 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4078 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed"); |
| 4079 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, "vkCmdDrawIndexed"); |
| 4080 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexed"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4081 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4085 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4086 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4087 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4088 | assert(cb_access_context); |
| 4089 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4090 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4091 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4092 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 4093 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4097 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4098 | bool skip = false; |
| 4099 | if (drawCount == 0) return skip; |
| 4100 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4101 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4102 | assert(cb_access_context); |
| 4103 | if (!cb_access_context) return skip; |
| 4104 | |
| 4105 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4106 | assert(context); |
| 4107 | if (!context) return skip; |
| 4108 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4109 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect"); |
| 4110 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4111 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4112 | drawCount, stride, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4113 | |
| 4114 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4115 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4116 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4117 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4118 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4119 | } |
| 4120 | |
| 4121 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4122 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4123 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4124 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4125 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4126 | assert(cb_access_context); |
| 4127 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 4128 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4129 | assert(context); |
| 4130 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4131 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4132 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4133 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4134 | |
| 4135 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4136 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4137 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4138 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4142 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4143 | bool skip = false; |
| 4144 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4145 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4146 | assert(cb_access_context); |
| 4147 | if (!cb_access_context) return skip; |
| 4148 | |
| 4149 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4150 | assert(context); |
| 4151 | if (!context) return skip; |
| 4152 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4153 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect"); |
| 4154 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexedIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4155 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4156 | offset, drawCount, stride, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4157 | |
| 4158 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4159 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4160 | // 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] | 4161 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4162 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4166 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4167 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4168 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4169 | assert(cb_access_context); |
| 4170 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 4171 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4172 | assert(context); |
| 4173 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4174 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4175 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4176 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4177 | |
| 4178 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4179 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4180 | // 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] | 4181 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4185 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4186 | uint32_t stride, const char *function) const { |
| 4187 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4188 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4189 | assert(cb_access_context); |
| 4190 | if (!cb_access_context) return skip; |
| 4191 | |
| 4192 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4193 | assert(context); |
| 4194 | if (!context) return skip; |
| 4195 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4196 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4197 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4198 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4199 | maxDrawCount, stride, function); |
| 4200 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4201 | |
| 4202 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4203 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4204 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4205 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4206 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4210 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4211 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4212 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4213 | "vkCmdDrawIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4217 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4218 | uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4219 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4220 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4221 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4222 | assert(cb_access_context); |
| 4223 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECTCOUNT); |
| 4224 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4225 | assert(context); |
| 4226 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4227 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4228 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4229 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 4230 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4231 | |
| 4232 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4233 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4234 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4235 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4236 | } |
| 4237 | |
| 4238 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4239 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4240 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4241 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4242 | "vkCmdDrawIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4243 | } |
| 4244 | |
| 4245 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4246 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4247 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4248 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4249 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4250 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4254 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4255 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4256 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4257 | "vkCmdDrawIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4261 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4262 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4263 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4264 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4265 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4266 | } |
| 4267 | |
| 4268 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4269 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4270 | uint32_t stride, const char *function) const { |
| 4271 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4272 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4273 | assert(cb_access_context); |
| 4274 | if (!cb_access_context) return skip; |
| 4275 | |
| 4276 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4277 | assert(context); |
| 4278 | if (!context) return skip; |
| 4279 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4280 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4281 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4282 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4283 | offset, maxDrawCount, stride, function); |
| 4284 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4285 | |
| 4286 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4287 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4288 | // 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] | 4289 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4290 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4291 | } |
| 4292 | |
| 4293 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4294 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4295 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4296 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4297 | "vkCmdDrawIndexedIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4301 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4302 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4303 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4304 | maxDrawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4305 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4306 | assert(cb_access_context); |
| 4307 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 4308 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4309 | assert(context); |
| 4310 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4311 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4312 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4313 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 4314 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4315 | |
| 4316 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4317 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4318 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 4319 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4323 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4324 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4325 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4326 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4327 | "vkCmdDrawIndexedIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4331 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4332 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4333 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4334 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4335 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4336 | } |
| 4337 | |
| 4338 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4339 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4340 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4341 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4342 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4343 | "vkCmdDrawIndexedIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4347 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4348 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4349 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4350 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4351 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4352 | } |
| 4353 | |
| 4354 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4355 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4356 | const VkImageSubresourceRange *pRanges) const { |
| 4357 | bool skip = false; |
| 4358 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4359 | assert(cb_access_context); |
| 4360 | if (!cb_access_context) return skip; |
| 4361 | |
| 4362 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4363 | assert(context); |
| 4364 | if (!context) return skip; |
| 4365 | |
| 4366 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4367 | |
| 4368 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4369 | const auto &range = pRanges[index]; |
| 4370 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4371 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4372 | if (hazard.hazard) { |
| 4373 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4374 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4375 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4376 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4377 | } |
| 4378 | } |
| 4379 | } |
| 4380 | return skip; |
| 4381 | } |
| 4382 | |
| 4383 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4384 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4385 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4386 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4387 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4388 | assert(cb_access_context); |
| 4389 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 4390 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4391 | assert(context); |
| 4392 | |
| 4393 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4394 | |
| 4395 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4396 | const auto &range = pRanges[index]; |
| 4397 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4398 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4399 | } |
| 4400 | } |
| 4401 | } |
| 4402 | |
| 4403 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 4404 | VkImageLayout imageLayout, |
| 4405 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4406 | const VkImageSubresourceRange *pRanges) const { |
| 4407 | bool skip = false; |
| 4408 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4409 | assert(cb_access_context); |
| 4410 | if (!cb_access_context) return skip; |
| 4411 | |
| 4412 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4413 | assert(context); |
| 4414 | if (!context) return skip; |
| 4415 | |
| 4416 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4417 | |
| 4418 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4419 | const auto &range = pRanges[index]; |
| 4420 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4421 | auto hazard = context->DetectHazard(*image_state, SYNC_CLEAR_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4422 | if (hazard.hazard) { |
| 4423 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4424 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4425 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4426 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4427 | } |
| 4428 | } |
| 4429 | } |
| 4430 | return skip; |
| 4431 | } |
| 4432 | |
| 4433 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4434 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4435 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4436 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4437 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4438 | assert(cb_access_context); |
| 4439 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 4440 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4441 | assert(context); |
| 4442 | |
| 4443 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4444 | |
| 4445 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4446 | const auto &range = pRanges[index]; |
| 4447 | if (image_state) { |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 4448 | context->UpdateAccessState(*image_state, SYNC_CLEAR_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4449 | } |
| 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4454 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 4455 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 4456 | VkQueryResultFlags flags) const { |
| 4457 | bool skip = false; |
| 4458 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4459 | assert(cb_access_context); |
| 4460 | if (!cb_access_context) return skip; |
| 4461 | |
| 4462 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4463 | assert(context); |
| 4464 | if (!context) return skip; |
| 4465 | |
| 4466 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4467 | |
| 4468 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4469 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4470 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4471 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4472 | skip |= |
| 4473 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4474 | "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] | 4475 | 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] | 4476 | } |
| 4477 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4478 | |
| 4479 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4480 | return skip; |
| 4481 | } |
| 4482 | |
| 4483 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 4484 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4485 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4486 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 4487 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4488 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4489 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4490 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4491 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4492 | assert(context); |
| 4493 | |
| 4494 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4495 | |
| 4496 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4497 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4498 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4499 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4500 | |
| 4501 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4505 | VkDeviceSize size, uint32_t data) const { |
| 4506 | bool skip = false; |
| 4507 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4508 | assert(cb_access_context); |
| 4509 | if (!cb_access_context) return skip; |
| 4510 | |
| 4511 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4512 | assert(context); |
| 4513 | if (!context) return skip; |
| 4514 | |
| 4515 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4516 | |
| 4517 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4518 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4519 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4520 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4521 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4522 | "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] | 4523 | 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] | 4524 | } |
| 4525 | } |
| 4526 | return skip; |
| 4527 | } |
| 4528 | |
| 4529 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4530 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4531 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4532 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4533 | assert(cb_access_context); |
| 4534 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 4535 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4536 | assert(context); |
| 4537 | |
| 4538 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4539 | |
| 4540 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4541 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4542 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4543 | } |
| 4544 | } |
| 4545 | |
| 4546 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4547 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4548 | const VkImageResolve *pRegions) const { |
| 4549 | bool skip = false; |
| 4550 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4551 | assert(cb_access_context); |
| 4552 | if (!cb_access_context) return skip; |
| 4553 | |
| 4554 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4555 | assert(context); |
| 4556 | if (!context) return skip; |
| 4557 | |
| 4558 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4559 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4560 | |
| 4561 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4562 | const auto &resolve_region = pRegions[region]; |
| 4563 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4564 | 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] | 4565 | resolve_region.srcOffset, resolve_region.extent); |
| 4566 | if (hazard.hazard) { |
| 4567 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4568 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4569 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4570 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4571 | } |
| 4572 | } |
| 4573 | |
| 4574 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4575 | 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] | 4576 | resolve_region.dstOffset, resolve_region.extent); |
| 4577 | if (hazard.hazard) { |
| 4578 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4579 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4580 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4581 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4582 | } |
| 4583 | if (skip) break; |
| 4584 | } |
| 4585 | } |
| 4586 | |
| 4587 | return skip; |
| 4588 | } |
| 4589 | |
| 4590 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4591 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4592 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4593 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4594 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4595 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4596 | assert(cb_access_context); |
| 4597 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 4598 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4599 | assert(context); |
| 4600 | |
| 4601 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4602 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4603 | |
| 4604 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4605 | const auto &resolve_region = pRegions[region]; |
| 4606 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4607 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4608 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4609 | } |
| 4610 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4611 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4612 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4613 | } |
| 4614 | } |
| 4615 | } |
| 4616 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4617 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4618 | const VkResolveImageInfo2KHR *pResolveImageInfo) const { |
| 4619 | bool skip = false; |
| 4620 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4621 | assert(cb_access_context); |
| 4622 | if (!cb_access_context) return skip; |
| 4623 | |
| 4624 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4625 | assert(context); |
| 4626 | if (!context) return skip; |
| 4627 | |
| 4628 | const auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4629 | const auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4630 | |
| 4631 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4632 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4633 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4634 | 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] | 4635 | resolve_region.srcOffset, resolve_region.extent); |
| 4636 | if (hazard.hazard) { |
| 4637 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 4638 | "vkCmdResolveImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 4639 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4640 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4641 | } |
| 4642 | } |
| 4643 | |
| 4644 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4645 | 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] | 4646 | resolve_region.dstOffset, resolve_region.extent); |
| 4647 | if (hazard.hazard) { |
| 4648 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 4649 | "vkCmdResolveImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 4650 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4651 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4652 | } |
| 4653 | if (skip) break; |
| 4654 | } |
| 4655 | } |
| 4656 | |
| 4657 | return skip; |
| 4658 | } |
| 4659 | |
| 4660 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4661 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 4662 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 4663 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4664 | assert(cb_access_context); |
| 4665 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE2KHR); |
| 4666 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4667 | assert(context); |
| 4668 | |
| 4669 | auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4670 | auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4671 | |
| 4672 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4673 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4674 | if (src_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4675 | context->UpdateAccessState(*src_image, SYNC_RESOLVE_TRANSFER_READ, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4676 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4677 | } |
| 4678 | if (dst_image) { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4679 | context->UpdateAccessState(*dst_image, SYNC_RESOLVE_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4680 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4681 | } |
| 4682 | } |
| 4683 | } |
| 4684 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4685 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4686 | VkDeviceSize dataSize, const void *pData) const { |
| 4687 | bool skip = false; |
| 4688 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4689 | assert(cb_access_context); |
| 4690 | if (!cb_access_context) return skip; |
| 4691 | |
| 4692 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4693 | assert(context); |
| 4694 | if (!context) return skip; |
| 4695 | |
| 4696 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4697 | |
| 4698 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4699 | // VK_WHOLE_SIZE not allowed |
| 4700 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4701 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4702 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4703 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4704 | "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] | 4705 | 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] | 4706 | } |
| 4707 | } |
| 4708 | return skip; |
| 4709 | } |
| 4710 | |
| 4711 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4712 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4713 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4714 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4715 | assert(cb_access_context); |
| 4716 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 4717 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4718 | assert(context); |
| 4719 | |
| 4720 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4721 | |
| 4722 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4723 | // VK_WHOLE_SIZE not allowed |
| 4724 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4725 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4726 | } |
| 4727 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4728 | |
| 4729 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4730 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 4731 | bool skip = false; |
| 4732 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4733 | assert(cb_access_context); |
| 4734 | if (!cb_access_context) return skip; |
| 4735 | |
| 4736 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4737 | assert(context); |
| 4738 | if (!context) return skip; |
| 4739 | |
| 4740 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4741 | |
| 4742 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4743 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4744 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4745 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4746 | skip |= |
| 4747 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4748 | "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] | 4749 | 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] | 4750 | } |
| 4751 | } |
| 4752 | return skip; |
| 4753 | } |
| 4754 | |
| 4755 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4756 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4757 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4758 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4759 | assert(cb_access_context); |
| 4760 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 4761 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4762 | assert(context); |
| 4763 | |
| 4764 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4765 | |
| 4766 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4767 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4768 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4769 | } |
| 4770 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4771 | |
| 4772 | bool SyncValidator::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
| 4773 | bool skip = false; |
| 4774 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4775 | assert(cb_context); |
| 4776 | if (!cb_context) return skip; |
| 4777 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4778 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 4779 | return set_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | void SyncValidator::PostCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 4783 | StateTracker::PostCallRecordCmdSetEvent(commandBuffer, event, stageMask); |
| 4784 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4785 | assert(cb_context); |
| 4786 | if (!cb_context) return; |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4787 | SyncOpSetEvent set_event_op(CMD_SETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4788 | set_event_op.Record(cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4789 | } |
| 4790 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4791 | bool SyncValidator::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4792 | const VkDependencyInfoKHR *pDependencyInfo) const { |
| 4793 | bool skip = false; |
| 4794 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4795 | assert(cb_context); |
| 4796 | if (!cb_context || !pDependencyInfo) return skip; |
| 4797 | |
| 4798 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 4799 | return set_event_op.Validate(*cb_context); |
| 4800 | } |
| 4801 | |
| 4802 | void SyncValidator::PostCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4803 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 4804 | StateTracker::PostCallRecordCmdSetEvent2KHR(commandBuffer, event, pDependencyInfo); |
| 4805 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4806 | assert(cb_context); |
| 4807 | if (!cb_context || !pDependencyInfo) return; |
| 4808 | |
| 4809 | SyncOpSetEvent set_event_op(CMD_SETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, *pDependencyInfo); |
| 4810 | set_event_op.Record(cb_context); |
| 4811 | } |
| 4812 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4813 | bool SyncValidator::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4814 | VkPipelineStageFlags stageMask) const { |
| 4815 | bool skip = false; |
| 4816 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4817 | assert(cb_context); |
| 4818 | if (!cb_context) return skip; |
| 4819 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4820 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 4821 | return reset_event_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4822 | } |
| 4823 | |
| 4824 | void SyncValidator::PostCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 4825 | StateTracker::PostCallRecordCmdResetEvent(commandBuffer, event, stageMask); |
| 4826 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4827 | assert(cb_context); |
| 4828 | if (!cb_context) return; |
| 4829 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4830 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4831 | reset_event_op.Record(cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4832 | } |
| 4833 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4834 | bool SyncValidator::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4835 | VkPipelineStageFlags2KHR stageMask) const { |
| 4836 | bool skip = false; |
| 4837 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4838 | assert(cb_context); |
| 4839 | if (!cb_context) return skip; |
| 4840 | |
| 4841 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4842 | return reset_event_op.Validate(*cb_context); |
| 4843 | } |
| 4844 | |
| 4845 | void SyncValidator::PostCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4846 | VkPipelineStageFlags2KHR stageMask) { |
| 4847 | StateTracker::PostCallRecordCmdResetEvent2KHR(commandBuffer, event, stageMask); |
| 4848 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4849 | assert(cb_context); |
| 4850 | if (!cb_context) return; |
| 4851 | |
| 4852 | SyncOpResetEvent reset_event_op(CMD_RESETEVENT2KHR, *this, cb_context->GetQueueFlags(), event, stageMask); |
| 4853 | reset_event_op.Record(cb_context); |
| 4854 | } |
| 4855 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4856 | bool SyncValidator::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4857 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4858 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4859 | uint32_t bufferMemoryBarrierCount, |
| 4860 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4861 | uint32_t imageMemoryBarrierCount, |
| 4862 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 4863 | bool skip = false; |
| 4864 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4865 | assert(cb_context); |
| 4866 | if (!cb_context) return skip; |
| 4867 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4868 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 4869 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 4870 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 4871 | return wait_events_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | void SyncValidator::PostCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4875 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4876 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4877 | uint32_t bufferMemoryBarrierCount, |
| 4878 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4879 | uint32_t imageMemoryBarrierCount, |
| 4880 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 4881 | StateTracker::PostCallRecordCmdWaitEvents(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
| 4882 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 4883 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 4884 | |
| 4885 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4886 | assert(cb_context); |
| 4887 | if (!cb_context) return; |
| 4888 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4889 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS, *this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, |
| 4890 | dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 4891 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
| 4892 | return wait_events_op.Record(cb_context); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4893 | } |
| 4894 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4895 | bool SyncValidator::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4896 | const VkDependencyInfoKHR *pDependencyInfos) const { |
| 4897 | bool skip = false; |
| 4898 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4899 | assert(cb_context); |
| 4900 | if (!cb_context) return skip; |
| 4901 | |
| 4902 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 4903 | skip |= wait_events_op.Validate(*cb_context); |
| 4904 | return skip; |
| 4905 | } |
| 4906 | |
| 4907 | void SyncValidator::PostCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4908 | const VkDependencyInfoKHR *pDependencyInfos) { |
| 4909 | StateTracker::PostCallRecordCmdWaitEvents2KHR(commandBuffer, eventCount, pEvents, pDependencyInfos); |
| 4910 | |
| 4911 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4912 | assert(cb_context); |
| 4913 | if (!cb_context) return; |
| 4914 | |
| 4915 | SyncOpWaitEvents wait_events_op(CMD_WAITEVENTS2KHR, *this, cb_context->GetQueueFlags(), eventCount, pEvents, pDependencyInfos); |
| 4916 | wait_events_op.Record(cb_context); |
| 4917 | } |
| 4918 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4919 | void SyncEventState::ResetFirstScope() { |
| 4920 | for (const auto address_type : kAddressTypes) { |
| 4921 | first_scope[static_cast<size_t>(address_type)].clear(); |
| 4922 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 4923 | scope = SyncExecScope(); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | // 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] | 4927 | SyncEventState::IgnoreReason SyncEventState::IsIgnoredByWait(CMD_TYPE cmd, VkPipelineStageFlags2KHR srcStageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4928 | IgnoreReason reason = NotIgnored; |
| 4929 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4930 | if ((CMD_WAITEVENTS2KHR == cmd) && (CMD_SETEVENT == last_command)) { |
| 4931 | reason = SetVsWait2; |
| 4932 | } else if ((last_command == CMD_RESETEVENT || last_command == CMD_RESETEVENT2KHR) && !HasBarrier(0U, 0U)) { |
| 4933 | reason = (last_command == CMD_RESETEVENT) ? ResetWaitRace : Reset2WaitRace; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4934 | } else if (unsynchronized_set) { |
| 4935 | reason = SetRace; |
| 4936 | } else { |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4937 | const VkPipelineStageFlags2KHR missing_bits = scope.mask_param & ~srcStageMask; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4938 | if (missing_bits) reason = MissingStageBits; |
| 4939 | } |
| 4940 | |
| 4941 | return reason; |
| 4942 | } |
| 4943 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 4944 | bool SyncEventState::HasBarrier(VkPipelineStageFlags2KHR stageMask, VkPipelineStageFlags2KHR exec_scope_arg) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4945 | bool has_barrier = (last_command == CMD_NONE) || (stageMask & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) || |
| 4946 | (barriers & exec_scope_arg) || (barriers & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 4947 | return has_barrier; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4948 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 4949 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4950 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 4951 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4952 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 4953 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 4954 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 4955 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4956 | : SyncOpBase(cmd), barriers_(1) { |
| 4957 | auto &barrier_set = barriers_[0]; |
| 4958 | barrier_set.dependency_flags = dependencyFlags; |
| 4959 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, srcStageMask); |
| 4960 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, dstStageMask); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 4961 | // 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] | 4962 | barrier_set.MakeMemoryBarriers(barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, memoryBarrierCount, |
| 4963 | pMemoryBarriers); |
| 4964 | barrier_set.MakeBufferMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 4965 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
| 4966 | barrier_set.MakeImageMemoryBarriers(sync_state, barrier_set.src_exec_scope, barrier_set.dst_exec_scope, dependencyFlags, |
| 4967 | imageMemoryBarrierCount, pImageMemoryBarriers); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 4968 | } |
| 4969 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 4970 | SyncOpBarriers::SyncOpBarriers(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t event_count, |
| 4971 | const VkDependencyInfoKHR *dep_infos) |
| 4972 | : SyncOpBase(cmd), barriers_(event_count) { |
| 4973 | for (uint32_t i = 0; i < event_count; i++) { |
| 4974 | const auto &dep_info = dep_infos[i]; |
| 4975 | auto &barrier_set = barriers_[i]; |
| 4976 | barrier_set.dependency_flags = dep_info.dependencyFlags; |
| 4977 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 4978 | barrier_set.src_exec_scope = SyncExecScope::MakeSrc(queue_flags, stage_masks.src); |
| 4979 | barrier_set.dst_exec_scope = SyncExecScope::MakeDst(queue_flags, stage_masks.dst); |
| 4980 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
| 4981 | barrier_set.MakeMemoryBarriers(queue_flags, dep_info.dependencyFlags, dep_info.memoryBarrierCount, |
| 4982 | dep_info.pMemoryBarriers); |
| 4983 | barrier_set.MakeBufferMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.bufferMemoryBarrierCount, |
| 4984 | dep_info.pBufferMemoryBarriers); |
| 4985 | barrier_set.MakeImageMemoryBarriers(sync_state, queue_flags, dep_info.dependencyFlags, dep_info.imageMemoryBarrierCount, |
| 4986 | dep_info.pImageMemoryBarriers); |
| 4987 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4988 | } |
| 4989 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4990 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 4991 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 4992 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 4993 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 4994 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 4995 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 4996 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 4997 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers) {} |
| 4998 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 4999 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5000 | const VkDependencyInfoKHR &dep_info) |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5001 | : SyncOpBarriers(cmd, sync_state, queue_flags, 1, &dep_info) {} |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5002 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5003 | bool SyncOpPipelineBarrier::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5004 | bool skip = false; |
| 5005 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5006 | assert(context); |
| 5007 | if (!context) return skip; |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5008 | assert(barriers_.size() == 1); // PipelineBarriers only support a single barrier set. |
| 5009 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5010 | // Validate Image Layout transitions |
John Zulauf | 6fdf3d0 | 2021-03-05 16:50:47 -0700 | [diff] [blame] | 5011 | const auto &barrier_set = barriers_[0]; |
| 5012 | for (const auto &image_barrier : barrier_set.image_memory_barriers) { |
| 5013 | if (image_barrier.new_layout == image_barrier.old_layout) continue; // Only interested in layout transitions at this point. |
| 5014 | const auto *image_state = image_barrier.image.get(); |
| 5015 | if (!image_state) continue; |
| 5016 | const auto hazard = context->DetectImageBarrierHazard(image_barrier); |
| 5017 | if (hazard.hazard) { |
| 5018 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 5019 | const auto &sync_state = cb_context.GetSyncState(); |
| 5020 | const auto image_handle = image_state->image; |
| 5021 | skip |= sync_state.LogError(image_handle, string_SyncHazardVUID(hazard.hazard), |
| 5022 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5023 | string_SyncHazard(hazard.hazard), image_barrier.index, |
| 5024 | sync_state.report_data->FormatHandle(image_handle).c_str(), |
| 5025 | cb_context.FormatUsage(hazard).c_str()); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5026 | } |
| 5027 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5028 | return skip; |
| 5029 | } |
| 5030 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5031 | struct SyncOpPipelineBarrierFunctorFactory { |
| 5032 | using BarrierOpFunctor = PipelineBarrierOp; |
| 5033 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5034 | using GlobalBarrierOpFunctor = PipelineBarrierOp; |
| 5035 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5036 | using BufferRange = ResourceAccessRange; |
| 5037 | using ImageRange = subresource_adapter::ImageRangeGenerator; |
| 5038 | using GlobalRange = ResourceAccessRange; |
| 5039 | |
| 5040 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier, bool layout_transition) const { |
| 5041 | return ApplyFunctor(BarrierOpFunctor(barrier, layout_transition)); |
| 5042 | } |
| 5043 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, const ResourceUsageTag &tag) const { |
| 5044 | return GlobalApplyFunctor(true /* resolve */, size_hint, tag); |
| 5045 | } |
| 5046 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier) const { |
| 5047 | return GlobalBarrierOpFunctor(barrier, false); |
| 5048 | } |
| 5049 | |
| 5050 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range) const { |
| 5051 | if (!SimpleBinding(buffer)) return ResourceAccessRange(); |
| 5052 | const auto base_address = ResourceBaseAddress(buffer); |
| 5053 | return (range + base_address); |
| 5054 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5055 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | 264cce0 | 2021-02-05 14:40:47 -0700 | [diff] [blame] | 5056 | if (!SimpleBinding(image)) return subresource_adapter::ImageRangeGenerator(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5057 | |
| 5058 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5059 | 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] | 5060 | return range_gen; |
| 5061 | } |
| 5062 | GlobalRange MakeGlobalRangeGen(AccessAddressType) const { return kFullRange; } |
| 5063 | }; |
| 5064 | |
| 5065 | template <typename Barriers, typename FunctorFactory> |
| 5066 | void SyncOpBarriers::ApplyBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag &tag, |
| 5067 | AccessContext *context) { |
| 5068 | for (const auto &barrier : barriers) { |
| 5069 | const auto *state = barrier.GetState(); |
| 5070 | if (state) { |
| 5071 | auto *const accesses = &context->GetAccessStateMap(GetAccessAddressType(*state)); |
| 5072 | auto update_action = factory.MakeApplyFunctor(barrier.barrier, barrier.IsLayoutTransition()); |
| 5073 | auto range_gen = factory.MakeRangeGen(*state, barrier.Range()); |
| 5074 | UpdateMemoryAccessState(accesses, update_action, &range_gen); |
| 5075 | } |
| 5076 | } |
| 5077 | } |
| 5078 | |
| 5079 | template <typename Barriers, typename FunctorFactory> |
| 5080 | void SyncOpBarriers::ApplyGlobalBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag &tag, |
| 5081 | AccessContext *access_context) { |
| 5082 | auto barriers_functor = factory.MakeGlobalApplyFunctor(barriers.size(), tag); |
| 5083 | for (const auto &barrier : barriers) { |
| 5084 | barriers_functor.EmplaceBack(factory.MakeGlobalBarrierOpFunctor(barrier)); |
| 5085 | } |
| 5086 | for (const auto address_type : kAddressTypes) { |
| 5087 | auto range_gen = factory.MakeGlobalRangeGen(address_type); |
| 5088 | UpdateMemoryAccessState(&(access_context->GetAccessStateMap(address_type)), barriers_functor, &range_gen); |
| 5089 | } |
| 5090 | } |
| 5091 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5092 | void SyncOpPipelineBarrier::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5093 | SyncOpPipelineBarrierFunctorFactory factory; |
| 5094 | auto *access_context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5095 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5096 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5097 | // Pipeline barriers only have a single barrier set, unlike WaitEvents2 |
| 5098 | assert(barriers_.size() == 1); |
| 5099 | const auto &barrier_set = barriers_[0]; |
| 5100 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5101 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5102 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
| 5103 | |
| 5104 | if (barrier_set.single_exec_scope) { |
| 5105 | cb_context->ApplyGlobalBarriersToEvents(barrier_set.src_exec_scope, barrier_set.dst_exec_scope); |
| 5106 | } else { |
| 5107 | for (const auto &barrier : barrier_set.memory_barriers) { |
| 5108 | cb_context->ApplyGlobalBarriersToEvents(barrier.src_exec_scope, barrier.dst_exec_scope); |
| 5109 | } |
| 5110 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5111 | } |
| 5112 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5113 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(const SyncExecScope &src, const SyncExecScope &dst, |
| 5114 | VkDependencyFlags dependency_flags, uint32_t memory_barrier_count, |
| 5115 | const VkMemoryBarrier *barriers) { |
| 5116 | memory_barriers.reserve(std::max<uint32_t>(1, memory_barrier_count)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5117 | 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] | 5118 | const auto &barrier = barriers[barrier_index]; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5119 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5120 | memory_barriers.emplace_back(sync_barrier); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5121 | } |
| 5122 | if (0 == memory_barrier_count) { |
| 5123 | // If there are no global memory barriers, force an exec barrier |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5124 | memory_barriers.emplace_back(SyncBarrier(src, dst)); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5125 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5126 | single_exec_scope = true; |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5127 | } |
| 5128 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5129 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5130 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5131 | uint32_t barrier_count, const VkBufferMemoryBarrier *barriers) { |
| 5132 | buffer_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5133 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5134 | const auto &barrier = barriers[index]; |
| 5135 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5136 | if (buffer) { |
| 5137 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5138 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5139 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5140 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5141 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5142 | buffer_memory_barriers.emplace_back(); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5143 | } |
| 5144 | } |
| 5145 | } |
| 5146 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5147 | void SyncOpBarriers::BarrierSet::MakeMemoryBarriers(VkQueueFlags queue_flags, VkDependencyFlags dependency_flags, |
| 5148 | uint32_t memory_barrier_count, const VkMemoryBarrier2KHR *barriers) { |
| 5149 | memory_barriers.reserve(memory_barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5150 | 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] | 5151 | const auto &barrier = barriers[barrier_index]; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5152 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5153 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5154 | SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5155 | memory_barriers.emplace_back(sync_barrier); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5156 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5157 | single_exec_scope = false; |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5160 | void SyncOpBarriers::BarrierSet::MakeBufferMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5161 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5162 | const VkBufferMemoryBarrier2KHR *barriers) { |
| 5163 | buffer_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5164 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5165 | const auto &barrier = barriers[index]; |
| 5166 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5167 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5168 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5169 | if (buffer) { |
| 5170 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5171 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5172 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5173 | buffer_memory_barriers.emplace_back(buffer, sync_barrier, range); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5174 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5175 | buffer_memory_barriers.emplace_back(); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5176 | } |
| 5177 | } |
| 5178 | } |
| 5179 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5180 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, |
| 5181 | const SyncExecScope &dst, VkDependencyFlags dependencyFlags, |
| 5182 | uint32_t barrier_count, const VkImageMemoryBarrier *barriers) { |
| 5183 | image_memory_barriers.reserve(barrier_count); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5184 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5185 | const auto &barrier = barriers[index]; |
| 5186 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5187 | if (image) { |
| 5188 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5189 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5190 | 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] | 5191 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5192 | image_memory_barriers.emplace_back(); |
| 5193 | 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] | 5194 | } |
| 5195 | } |
| 5196 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5197 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5198 | void SyncOpBarriers::BarrierSet::MakeImageMemoryBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5199 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5200 | const VkImageMemoryBarrier2KHR *barriers) { |
| 5201 | image_memory_barriers.reserve(barrier_count); |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5202 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5203 | const auto &barrier = barriers[index]; |
| 5204 | auto src = SyncExecScope::MakeSrc(queue_flags, barrier.srcStageMask); |
| 5205 | auto dst = SyncExecScope::MakeDst(queue_flags, barrier.dstStageMask); |
| 5206 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5207 | if (image) { |
| 5208 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5209 | const SyncBarrier sync_barrier(barrier, src, dst); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5210 | 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] | 5211 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5212 | image_memory_barriers.emplace_back(); |
| 5213 | 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] | 5214 | } |
| 5215 | } |
| 5216 | } |
| 5217 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5218 | 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] | 5219 | const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5220 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5221 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5222 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5223 | : SyncOpBarriers(cmd, sync_state, queue_flags, srcStageMask, dstStageMask, VkDependencyFlags(0U), memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5224 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 5225 | pImageMemoryBarriers) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5226 | MakeEventsList(sync_state, eventCount, pEvents); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5227 | } |
| 5228 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5229 | SyncOpWaitEvents::SyncOpWaitEvents(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t eventCount, |
| 5230 | const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfo) |
| 5231 | : SyncOpBarriers(cmd, sync_state, queue_flags, eventCount, pDependencyInfo) { |
| 5232 | MakeEventsList(sync_state, eventCount, pEvents); |
| 5233 | assert(events_.size() == barriers_.size()); // Just so nobody gets clever and decides to cull the event or barrier arrays |
| 5234 | } |
| 5235 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5236 | bool SyncOpWaitEvents::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5237 | const char *const ignored = "Wait operation is ignored for this event."; |
| 5238 | bool skip = false; |
| 5239 | const auto &sync_state = cb_context.GetSyncState(); |
| 5240 | const auto command_buffer_handle = cb_context.GetCBState().commandBuffer; |
| 5241 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5242 | for (size_t barrier_set_index = 0; barrier_set_index < barriers_.size(); barrier_set_index++) { |
| 5243 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5244 | if (barrier_set.single_exec_scope) { |
| 5245 | if (barrier_set.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5246 | const std::string vuid = std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 5247 | skip = sync_state.LogInfo(command_buffer_handle, vuid, |
| 5248 | "%s, srcStageMask includes %s, unsupported by synchronization validation.", CmdName(), |
| 5249 | string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT)); |
| 5250 | } else { |
| 5251 | const auto &barriers = barrier_set.memory_barriers; |
| 5252 | for (size_t barrier_index = 0; barrier_index < barriers.size(); barrier_index++) { |
| 5253 | const auto &barrier = barriers[barrier_index]; |
| 5254 | if (barrier.src_exec_scope.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5255 | const std::string vuid = |
| 5256 | std::string("SYNC-") + std::string(CmdName()) + std::string("-hostevent-unsupported"); |
| 5257 | skip = |
| 5258 | sync_state.LogInfo(command_buffer_handle, vuid, |
| 5259 | "%s, srcStageMask %s of %s %zu, %s %zu, unsupported by synchronization validation.", |
| 5260 | CmdName(), string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT), |
| 5261 | "pDependencyInfo", barrier_set_index, "pMemoryBarriers", barrier_index); |
| 5262 | } |
| 5263 | } |
| 5264 | } |
| 5265 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5266 | } |
| 5267 | |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5268 | VkPipelineStageFlags2KHR event_stage_masks = 0U; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5269 | VkPipelineStageFlags2KHR barrier_mask_params = 0U; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5270 | bool events_not_found = false; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5271 | const auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5272 | assert(events_context); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5273 | size_t barrier_set_index = 0; |
| 5274 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 5275 | for (size_t event_index = 0; event_index < events_.size(); event_index++) |
| 5276 | for (const auto &event : events_) { |
| 5277 | const auto *sync_event = events_context->Get(event.get()); |
| 5278 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5279 | if (!sync_event) { |
| 5280 | // NOTE PHASE2: This is where we'll need queue submit time validation to come back and check the srcStageMask bits |
| 5281 | // or solve this with replay creating the SyncEventState in the queue context... also this will be a |
| 5282 | // new validation error... wait without previously submitted set event... |
| 5283 | events_not_found = true; // Demote "extra_stage_bits" error to warning, to avoid false positives at *record time* |
| 5284 | barrier_set_index += barrier_set_incr; |
| 5285 | continue; // Core, Lifetimes, or Param check needs to catch invalid events. |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5286 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5287 | const auto event_handle = sync_event->event->event; |
| 5288 | // TODO add "destroyed" checks |
| 5289 | |
| 5290 | barrier_mask_params |= barrier_set.src_exec_scope.mask_param; |
| 5291 | const auto &src_exec_scope = barrier_set.src_exec_scope; |
| 5292 | event_stage_masks |= sync_event->scope.mask_param; |
| 5293 | const auto ignore_reason = sync_event->IsIgnoredByWait(cmd_, src_exec_scope.mask_param); |
| 5294 | if (ignore_reason) { |
| 5295 | switch (ignore_reason) { |
| 5296 | case SyncEventState::ResetWaitRace: |
| 5297 | case SyncEventState::Reset2WaitRace: { |
| 5298 | // Four permuations of Reset and Wait calls... |
| 5299 | const char *vuid = |
| 5300 | (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent-event-03834" : "VUID-vkCmdResetEvent-event-03835"; |
| 5301 | if (ignore_reason == SyncEventState::Reset2WaitRace) { |
| 5302 | vuid = |
Jeremy Gebben | 476f5e2 | 2021-03-01 15:27:20 -0700 | [diff] [blame] | 5303 | (cmd_ == CMD_WAITEVENTS) ? "VUID-vkCmdResetEvent2KHR-event-03831" : "VUID-vkCmdResetEvent2KHR-event-03832"; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5304 | } |
| 5305 | const char *const message = |
| 5306 | "%s: %s %s operation following %s without intervening execution barrier, may cause race condition. %s"; |
| 5307 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5308 | sync_state.report_data->FormatHandle(event_handle).c_str(), CmdName(), |
| 5309 | CommandTypeString(sync_event->last_command), ignored); |
| 5310 | break; |
| 5311 | } |
| 5312 | case SyncEventState::SetRace: { |
| 5313 | // Issue error message that Wait is waiting on an signal subject to race condition, and is thus ignored for |
| 5314 | // this event |
| 5315 | const char *const vuid = "SYNC-vkCmdWaitEvents-unsynchronized-setops"; |
| 5316 | const char *const message = |
| 5317 | "%s: %s Unsychronized %s calls result in race conditions w.r.t. event signalling, %s %s"; |
| 5318 | const char *const reason = "First synchronization scope is undefined."; |
| 5319 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5320 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5321 | CommandTypeString(sync_event->last_command), reason, ignored); |
| 5322 | break; |
| 5323 | } |
| 5324 | case SyncEventState::MissingStageBits: { |
| 5325 | const auto missing_bits = sync_event->scope.mask_param & ~src_exec_scope.mask_param; |
| 5326 | // Issue error message that event waited for is not in wait events scope |
| 5327 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 5328 | const char *const message = |
| 5329 | "%s: %s stageMask %" PRIx64 " includes bits not present in srcStageMask 0x%" PRIx64 |
| 5330 | ". Bits missing from srcStageMask %s. %s"; |
| 5331 | skip |= sync_state.LogError(event_handle, vuid, message, CmdName(), |
| 5332 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5333 | sync_event->scope.mask_param, src_exec_scope.mask_param, |
| 5334 | sync_utils::StringPipelineStageFlags(missing_bits).c_str(), ignored); |
| 5335 | break; |
| 5336 | } |
| 5337 | case SyncEventState::SetVsWait2: { |
| 5338 | skip |= sync_state.LogError(event_handle, "VUID-vkCmdWaitEvents2KHR-pEvents-03837", |
| 5339 | "%s: Follows set of %s by %s. Disallowed.", CmdName(), |
| 5340 | sync_state.report_data->FormatHandle(event_handle).c_str(), |
| 5341 | CommandTypeString(sync_event->last_command)); |
| 5342 | break; |
| 5343 | } |
| 5344 | default: |
| 5345 | assert(ignore_reason == SyncEventState::NotIgnored); |
| 5346 | } |
| 5347 | } else if (barrier_set.image_memory_barriers.size()) { |
| 5348 | const auto &image_memory_barriers = barrier_set.image_memory_barriers; |
| 5349 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5350 | assert(context); |
| 5351 | for (const auto &image_memory_barrier : image_memory_barriers) { |
| 5352 | if (image_memory_barrier.old_layout == image_memory_barrier.new_layout) continue; |
| 5353 | const auto *image_state = image_memory_barrier.image.get(); |
| 5354 | if (!image_state) continue; |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5355 | const auto &subresource_range = image_memory_barrier.range; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5356 | const auto &src_access_scope = image_memory_barrier.barrier.src_access_scope; |
| 5357 | const auto hazard = |
| 5358 | context->DetectImageBarrierHazard(*image_state, sync_event->scope.exec_scope, src_access_scope, |
| 5359 | subresource_range, *sync_event, AccessContext::DetectOptions::kDetectAll); |
| 5360 | if (hazard.hazard) { |
| 5361 | skip |= sync_state.LogError(image_state->image, string_SyncHazardVUID(hazard.hazard), |
| 5362 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", CmdName(), |
| 5363 | string_SyncHazard(hazard.hazard), image_memory_barrier.index, |
| 5364 | sync_state.report_data->FormatHandle(image_state->image).c_str(), |
| 5365 | cb_context.FormatUsage(hazard).c_str()); |
| 5366 | break; |
| 5367 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5368 | } |
| 5369 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5370 | // TODO: Add infrastructure for checking pDependencyInfo's vs. CmdSetEvent2 VUID - vkCmdWaitEvents2KHR - pEvents - |
| 5371 | // 03839 |
| 5372 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5373 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5374 | |
| 5375 | // 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] | 5376 | 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] | 5377 | if (extra_stage_bits) { |
| 5378 | // 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] | 5379 | // NOTE: This isn't exactly the right VUID for WaitEvents2, but it's as close as we currently have support for |
| 5380 | const char *const vuid = |
| 5381 | (CMD_WAITEVENTS == cmd_) ? "VUID-vkCmdWaitEvents-srcStageMask-01158" : "VUID-vkCmdWaitEvents2KHR-pEvents-03838"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5382 | const char *const message = |
Jeremy Gebben | 40a2294 | 2020-12-22 14:22:06 -0700 | [diff] [blame] | 5383 | "%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] | 5384 | if (events_not_found) { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5385 | 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] | 5386 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5387 | " vkCmdSetEvent may be in previously submitted command buffer."); |
| 5388 | } else { |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5389 | 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] | 5390 | sync_utils::StringPipelineStageFlags(extra_stage_bits).c_str(), ""); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5391 | } |
| 5392 | } |
| 5393 | return skip; |
| 5394 | } |
| 5395 | |
| 5396 | struct SyncOpWaitEventsFunctorFactory { |
| 5397 | using BarrierOpFunctor = WaitEventBarrierOp; |
| 5398 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5399 | using GlobalBarrierOpFunctor = WaitEventBarrierOp; |
| 5400 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5401 | using BufferRange = EventSimpleRangeGenerator; |
| 5402 | using ImageRange = EventImageRangeGenerator; |
| 5403 | using GlobalRange = EventSimpleRangeGenerator; |
| 5404 | |
| 5405 | // Need to restrict to only valid exec and access scope for this event |
| 5406 | // Pass by value is intentional to get a copy we can change without modifying the passed barrier |
| 5407 | SyncBarrier RestrictToEvent(SyncBarrier barrier) const { |
John Zulauf | c523bf6 | 2021-02-16 08:20:34 -0700 | [diff] [blame] | 5408 | 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] | 5409 | barrier.src_access_scope = sync_event->scope.valid_accesses & barrier.src_access_scope; |
| 5410 | return barrier; |
| 5411 | } |
| 5412 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier_arg, bool layout_transition) const { |
| 5413 | auto barrier = RestrictToEvent(barrier_arg); |
| 5414 | return ApplyFunctor(BarrierOpFunctor(sync_event->first_scope_tag, barrier, layout_transition)); |
| 5415 | } |
| 5416 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, const ResourceUsageTag &tag) const { |
| 5417 | return GlobalApplyFunctor(false /* don't resolve */, size_hint, tag); |
| 5418 | } |
| 5419 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier_arg) const { |
| 5420 | auto barrier = RestrictToEvent(barrier_arg); |
| 5421 | return GlobalBarrierOpFunctor(sync_event->first_scope_tag, barrier, false); |
| 5422 | } |
| 5423 | |
| 5424 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range_arg) const { |
| 5425 | const AccessAddressType address_type = GetAccessAddressType(buffer); |
| 5426 | const auto base_address = ResourceBaseAddress(buffer); |
| 5427 | ResourceAccessRange range = SimpleBinding(buffer) ? (range_arg + base_address) : ResourceAccessRange(); |
| 5428 | EventSimpleRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), range); |
| 5429 | return filtered_range_gen; |
| 5430 | } |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5431 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5432 | if (!SimpleBinding(image)) return ImageRange(); |
| 5433 | const auto address_type = GetAccessAddressType(image); |
| 5434 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 110413c | 2021-03-20 05:38:38 -0600 | [diff] [blame] | 5435 | 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] | 5436 | EventImageRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), image_range_gen); |
| 5437 | |
| 5438 | return filtered_range_gen; |
| 5439 | } |
| 5440 | GlobalRange MakeGlobalRangeGen(AccessAddressType address_type) const { |
| 5441 | return EventSimpleRangeGenerator(sync_event->FirstScope(address_type), kFullRange); |
| 5442 | } |
| 5443 | SyncOpWaitEventsFunctorFactory(SyncEventState *sync_event_) : sync_event(sync_event_) { assert(sync_event); } |
| 5444 | SyncEventState *sync_event; |
| 5445 | }; |
| 5446 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5447 | void SyncOpWaitEvents::Record(CommandBufferAccessContext *cb_context) const { |
| 5448 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5449 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5450 | assert(access_context); |
| 5451 | if (!access_context) return; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5452 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5453 | assert(events_context); |
| 5454 | if (!events_context) return; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5455 | |
| 5456 | // Unlike PipelineBarrier, WaitEvent is *not* limited to accesses within the current subpass (if any) and thus needs to import |
| 5457 | // all accesses. Can instead import for all first_scopes, or a union of them, if this becomes a performance/memory issue, |
| 5458 | // but with no idea of the performance of the union, nor of whether it even matters... take the simplest approach here, |
| 5459 | access_context->ResolvePreviousAccesses(); |
| 5460 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5461 | // TODO... this needs change the SyncEventContext it's using depending on whether this is replay... the recorded |
| 5462 | // 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] | 5463 | size_t barrier_set_index = 0; |
| 5464 | size_t barrier_set_incr = (barriers_.size() == 1) ? 0 : 1; |
| 5465 | assert(barriers_.size() == 1 || (barriers_.size() == events_.size())); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5466 | for (auto &event_shared : events_) { |
| 5467 | if (!event_shared.get()) continue; |
| 5468 | auto *sync_event = events_context->GetFromShared(event_shared); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5469 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5470 | sync_event->last_command = cmd_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5471 | |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5472 | const auto &barrier_set = barriers_[barrier_set_index]; |
| 5473 | const auto &dst = barrier_set.dst_exec_scope; |
| 5474 | if (!sync_event->IsIgnoredByWait(cmd_, barrier_set.src_exec_scope.mask_param)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5475 | // These apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 5476 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 5477 | // of the barriers is maintained. |
| 5478 | SyncOpWaitEventsFunctorFactory factory(sync_event); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5479 | ApplyBarriers(barrier_set.buffer_memory_barriers, factory, tag, access_context); |
| 5480 | ApplyBarriers(barrier_set.image_memory_barriers, factory, tag, access_context); |
| 5481 | ApplyGlobalBarriers(barrier_set.memory_barriers, factory, tag, access_context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5482 | |
| 5483 | // Apply the global barrier to the event itself (for race condition tracking) |
| 5484 | // Events don't happen at a stage, so we need to store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 5485 | sync_event->barriers = dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 5486 | sync_event->barriers |= dst.exec_scope; |
| 5487 | } else { |
| 5488 | // We ignored this wait, so we don't have any effective synchronization barriers for it. |
| 5489 | sync_event->barriers = 0U; |
| 5490 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5491 | barrier_set_index += barrier_set_incr; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5492 | } |
| 5493 | |
| 5494 | // Apply the pending barriers |
| 5495 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
| 5496 | access_context->ApplyToContext(apply_pending_action); |
| 5497 | } |
| 5498 | |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5499 | bool SyncValidator::PreCallValidateCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 5500 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 5501 | bool skip = false; |
| 5502 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5503 | assert(cb_access_context); |
| 5504 | if (!cb_access_context) return skip; |
| 5505 | |
| 5506 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5507 | assert(context); |
| 5508 | if (!context) return skip; |
| 5509 | |
| 5510 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5511 | |
| 5512 | if (dst_buffer) { |
| 5513 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 5514 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, range); |
| 5515 | if (hazard.hazard) { |
| 5516 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 5517 | "vkCmdWriteBufferMarkerAMD2: Hazard %s for dstBuffer %s. Access info %s.", |
| 5518 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), |
| 5519 | string_UsageTag(hazard.tag).c_str()); |
| 5520 | } |
| 5521 | } |
| 5522 | return skip; |
| 5523 | } |
| 5524 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5525 | 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] | 5526 | events_.reserve(event_count); |
| 5527 | for (uint32_t event_index = 0; event_index < event_count; event_index++) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5528 | events_.emplace_back(sync_state.GetShared<EVENT_STATE>(events[event_index])); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5529 | } |
| 5530 | } |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5531 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5532 | 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] | 5533 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5534 | : SyncOpBase(cmd), |
| 5535 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
| 5536 | exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5537 | |
| 5538 | bool SyncOpResetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5539 | auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5540 | assert(events_context); |
| 5541 | bool skip = false; |
| 5542 | if (!events_context) return skip; |
| 5543 | |
| 5544 | const auto &sync_state = cb_context.GetSyncState(); |
| 5545 | const auto *sync_event = events_context->Get(event_); |
| 5546 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5547 | |
| 5548 | const char *const set_wait = |
| 5549 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 5550 | "hazards."; |
| 5551 | const char *message = set_wait; // Only one message this call. |
| 5552 | if (!sync_event->HasBarrier(exec_scope_.mask_param, exec_scope_.exec_scope)) { |
| 5553 | const char *vuid = nullptr; |
| 5554 | switch (sync_event->last_command) { |
| 5555 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5556 | case CMD_SETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5557 | // Needs a barrier between set and reset |
| 5558 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-set"; |
| 5559 | break; |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5560 | case CMD_WAITEVENTS: |
| 5561 | case CMD_WAITEVENTS2KHR: { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5562 | // Needs to be in the barriers chain (either because of a barrier, or because of dstStageMask |
| 5563 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-wait"; |
| 5564 | break; |
| 5565 | } |
| 5566 | default: |
| 5567 | // The only other valid last command that wasn't one. |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5568 | assert((sync_event->last_command == CMD_NONE) || (sync_event->last_command == CMD_RESETEVENT) || |
| 5569 | (sync_event->last_command == CMD_RESETEVENT2KHR)); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5570 | break; |
| 5571 | } |
| 5572 | if (vuid) { |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5573 | skip |= sync_state.LogError(event_->event, vuid, message, CmdName(), |
| 5574 | sync_state.report_data->FormatHandle(event_->event).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5575 | CommandTypeString(sync_event->last_command)); |
| 5576 | } |
| 5577 | } |
| 5578 | return skip; |
| 5579 | } |
| 5580 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5581 | void SyncOpResetEvent::Record(CommandBufferAccessContext *cb_context) const { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5582 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5583 | assert(events_context); |
| 5584 | if (!events_context) return; |
| 5585 | |
| 5586 | auto *sync_event = events_context->GetFromShared(event_); |
| 5587 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5588 | |
| 5589 | // Update the event state |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5590 | sync_event->last_command = cmd_; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5591 | sync_event->unsynchronized_set = CMD_NONE; |
| 5592 | sync_event->ResetFirstScope(); |
| 5593 | sync_event->barriers = 0U; |
| 5594 | } |
| 5595 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5596 | 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] | 5597 | VkPipelineStageFlags2KHR stageMask) |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5598 | : SyncOpBase(cmd), |
| 5599 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5600 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, stageMask)), |
| 5601 | dep_info_() {} |
| 5602 | |
| 5603 | SyncOpSetEvent::SyncOpSetEvent(CMD_TYPE cmd, const SyncValidator &sync_state, VkQueueFlags queue_flags, VkEvent event, |
| 5604 | const VkDependencyInfoKHR &dep_info) |
| 5605 | : SyncOpBase(cmd), |
| 5606 | event_(sync_state.GetShared<EVENT_STATE>(event)), |
| 5607 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, sync_utils::GetGlobalStageMasks(dep_info).src)), |
| 5608 | dep_info_(new safe_VkDependencyInfoKHR(&dep_info)) {} |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5609 | |
| 5610 | bool SyncOpSetEvent::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5611 | // 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] | 5612 | bool skip = false; |
| 5613 | |
| 5614 | const auto &sync_state = cb_context.GetSyncState(); |
| 5615 | auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5616 | assert(events_context); |
| 5617 | if (!events_context) return skip; |
| 5618 | |
| 5619 | const auto *sync_event = events_context->Get(event_); |
| 5620 | if (!sync_event) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5621 | |
| 5622 | const char *const reset_set = |
| 5623 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 5624 | "hazards."; |
| 5625 | const char *const wait = |
| 5626 | "%s: %s %s operation following %s without intervening vkCmdResetEvent, may result in data hazard and is ignored."; |
| 5627 | |
| 5628 | 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] | 5629 | const char *vuid_stem = nullptr; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5630 | const char *message = nullptr; |
| 5631 | switch (sync_event->last_command) { |
| 5632 | case CMD_RESETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5633 | case CMD_RESETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5634 | // Needs a barrier between reset and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5635 | vuid_stem = "-missingbarrier-reset"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5636 | message = reset_set; |
| 5637 | break; |
| 5638 | case CMD_SETEVENT: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5639 | case CMD_SETEVENT2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5640 | // Needs a barrier between set and set |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5641 | vuid_stem = "-missingbarrier-set"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5642 | message = reset_set; |
| 5643 | break; |
| 5644 | case CMD_WAITEVENTS: |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5645 | case CMD_WAITEVENTS2KHR: |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5646 | // Needs a barrier or is in second execution scope |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5647 | vuid_stem = "-missingbarrier-wait"; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5648 | message = wait; |
| 5649 | break; |
| 5650 | default: |
| 5651 | // The only other valid last command that wasn't one. |
| 5652 | assert(sync_event->last_command == CMD_NONE); |
| 5653 | break; |
| 5654 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5655 | if (vuid_stem) { |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5656 | assert(nullptr != message); |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5657 | std::string vuid("SYNC-"); |
| 5658 | vuid.append(CmdName()).append(vuid_stem); |
| 5659 | skip |= sync_state.LogError(event_->event, vuid.c_str(), message, CmdName(), |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5660 | sync_state.report_data->FormatHandle(event_->event).c_str(), CmdName(), |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5661 | CommandTypeString(sync_event->last_command)); |
| 5662 | } |
| 5663 | } |
| 5664 | |
| 5665 | return skip; |
| 5666 | } |
| 5667 | |
John Zulauf | 36ef928 | 2021-02-02 11:47:24 -0700 | [diff] [blame] | 5668 | void SyncOpSetEvent::Record(CommandBufferAccessContext *cb_context) const { |
| 5669 | const auto tag = cb_context->NextCommandTag(cmd_); |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5670 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5671 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5672 | assert(events_context); |
| 5673 | if (!events_context) return; |
| 5674 | |
| 5675 | auto *sync_event = events_context->GetFromShared(event_); |
| 5676 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5677 | |
| 5678 | // NOTE: We're going to simply record the sync scope here, as anything else would be implementation defined/undefined |
| 5679 | // and we're issuing errors re: missing barriers between event commands, which if the user fixes would fix |
| 5680 | // any issues caused by naive scope setting here. |
| 5681 | |
| 5682 | // What happens with two SetEvent is that one cannot know what group of operations will be waited for. |
| 5683 | // Given: |
| 5684 | // Stuff1; SetEvent; Stuff2; SetEvent; WaitEvents; |
| 5685 | // WaitEvents cannot know which of Stuff1, Stuff2, or both has completed execution. |
| 5686 | |
| 5687 | if (!sync_event->HasBarrier(src_exec_scope_.mask_param, src_exec_scope_.exec_scope)) { |
| 5688 | sync_event->unsynchronized_set = sync_event->last_command; |
| 5689 | sync_event->ResetFirstScope(); |
| 5690 | } else if (sync_event->scope.exec_scope == 0) { |
| 5691 | // We only set the scope if there isn't one |
| 5692 | sync_event->scope = src_exec_scope_; |
| 5693 | |
| 5694 | auto set_scope = [&sync_event](AccessAddressType address_type, const ResourceAccessRangeMap::value_type &access) { |
| 5695 | auto &scope_map = sync_event->first_scope[static_cast<size_t>(address_type)]; |
| 5696 | if (access.second.InSourceScopeOrChain(sync_event->scope.exec_scope, sync_event->scope.valid_accesses)) { |
| 5697 | scope_map.insert(scope_map.end(), std::make_pair(access.first, true)); |
| 5698 | } |
| 5699 | }; |
| 5700 | access_context->ForAll(set_scope); |
| 5701 | sync_event->unsynchronized_set = CMD_NONE; |
| 5702 | sync_event->first_scope_tag = tag; |
| 5703 | } |
John Zulauf | 4edde62 | 2021-02-15 08:54:50 -0700 | [diff] [blame] | 5704 | // TODO: Store dep_info_ shared ptr in sync_state for WaitEvents2 validation |
| 5705 | sync_event->last_command = cmd_; |
John Zulauf | 6ce2437 | 2021-01-30 05:56:25 -0700 | [diff] [blame] | 5706 | sync_event->barriers = 0U; |
| 5707 | } |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 5708 | |
| 5709 | SyncOpBeginRenderPass::SyncOpBeginRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, |
| 5710 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 5711 | const VkSubpassBeginInfo *pSubpassBeginInfo, const char *cmd_name) |
| 5712 | : SyncOpBase(cmd, cmd_name) { |
| 5713 | if (pRenderPassBegin) { |
| 5714 | rp_state_ = sync_state.GetShared<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
| 5715 | renderpass_begin_info_ = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
| 5716 | const auto *fb_state = sync_state.Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
| 5717 | if (fb_state) { |
| 5718 | shared_attachments_ = sync_state.GetSharedAttachmentViews(*renderpass_begin_info_.ptr(), *fb_state); |
| 5719 | // TODO: Revisit this when all attachment validation is through SyncOps to see if we can discard the plain pointer copy |
| 5720 | // Note that this a safe to presist as long as shared_attachments is not cleared |
| 5721 | attachments_.reserve(shared_attachments_.size()); |
sfricke-samsung | 01c9ae9 | 2021-02-09 22:30:52 -0800 | [diff] [blame] | 5722 | for (const auto &attachment : shared_attachments_) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 5723 | attachments_.emplace_back(attachment.get()); |
| 5724 | } |
| 5725 | } |
| 5726 | if (pSubpassBeginInfo) { |
| 5727 | subpass_begin_info_ = safe_VkSubpassBeginInfo(pSubpassBeginInfo); |
| 5728 | } |
| 5729 | } |
| 5730 | } |
| 5731 | |
| 5732 | bool SyncOpBeginRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5733 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 5734 | bool skip = false; |
| 5735 | |
| 5736 | assert(rp_state_.get()); |
| 5737 | if (nullptr == rp_state_.get()) return skip; |
| 5738 | auto &rp_state = *rp_state_.get(); |
| 5739 | |
| 5740 | const uint32_t subpass = 0; |
| 5741 | |
| 5742 | // Construct the state we can use to validate against... (since validation is const and RecordCmdBeginRenderPass |
| 5743 | // hasn't happened yet) |
| 5744 | const std::vector<AccessContext> empty_context_vector; |
| 5745 | AccessContext temp_context(subpass, cb_context.GetQueueFlags(), rp_state.subpass_dependencies, empty_context_vector, |
| 5746 | cb_context.GetCurrentAccessContext()); |
| 5747 | |
| 5748 | // Validate attachment operations |
| 5749 | if (attachments_.size() == 0) return skip; |
| 5750 | const auto &render_area = renderpass_begin_info_.renderArea; |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 5751 | |
| 5752 | // Since the isn't a valid RenderPassAccessContext until Record, needs to create the view/generator list... we could limit this |
| 5753 | // by predicating on whether subpass 0 uses the attachment if it is too expensive to create the full list redundantly here. |
| 5754 | // More broadly we could look at thread specific state shared between Validate and Record as is done for other heavyweight |
| 5755 | // operations (though it's currently a messy approach) |
| 5756 | AttachmentViewGenVector view_gens = RenderPassAccessContext::CreateAttachmentViewGen(render_area, attachments_); |
| 5757 | 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] | 5758 | |
| 5759 | // Validate load operations if there were no layout transition hazards |
| 5760 | if (!skip) { |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 5761 | temp_context.RecordLayoutTransitions(rp_state, subpass, view_gens, kCurrentCommandTag); |
| 5762 | 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] | 5763 | } |
| 5764 | |
| 5765 | return skip; |
| 5766 | } |
| 5767 | |
| 5768 | void SyncOpBeginRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
| 5769 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5770 | assert(rp_state_.get()); |
| 5771 | if (nullptr == rp_state_.get()) return; |
| 5772 | const auto tag = cb_context->NextCommandTag(cmd_); |
| 5773 | cb_context->RecordBeginRenderPass(*rp_state_.get(), renderpass_begin_info_.renderArea, attachments_, tag); |
| 5774 | } |
| 5775 | |
| 5776 | SyncOpNextSubpass::SyncOpNextSubpass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 5777 | const VkSubpassEndInfo *pSubpassEndInfo, const char *name_override) |
| 5778 | : SyncOpBase(cmd, name_override) { |
| 5779 | if (pSubpassBeginInfo) { |
| 5780 | subpass_begin_info_.initialize(pSubpassBeginInfo); |
| 5781 | } |
| 5782 | if (pSubpassEndInfo) { |
| 5783 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 5784 | } |
| 5785 | } |
| 5786 | |
| 5787 | bool SyncOpNextSubpass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5788 | bool skip = false; |
| 5789 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 5790 | if (!renderpass_context) return skip; |
| 5791 | |
| 5792 | skip |= renderpass_context->ValidateNextSubpass(cb_context.GetExecutionContext(), CmdName()); |
| 5793 | return skip; |
| 5794 | } |
| 5795 | |
| 5796 | void SyncOpNextSubpass::Record(CommandBufferAccessContext *cb_context) const { |
| 5797 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5798 | cb_context->RecordNextSubpass(cmd_); |
| 5799 | } |
| 5800 | |
| 5801 | SyncOpEndRenderPass::SyncOpEndRenderPass(CMD_TYPE cmd, const SyncValidator &sync_state, const VkSubpassEndInfo *pSubpassEndInfo, |
| 5802 | const char *name_override) |
| 5803 | : SyncOpBase(cmd, name_override) { |
| 5804 | if (pSubpassEndInfo) { |
| 5805 | subpass_end_info_.initialize(pSubpassEndInfo); |
| 5806 | } |
| 5807 | } |
| 5808 | |
| 5809 | bool SyncOpEndRenderPass::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5810 | bool skip = false; |
| 5811 | const auto *renderpass_context = cb_context.GetCurrentRenderPassContext(); |
| 5812 | |
| 5813 | if (!renderpass_context) return skip; |
| 5814 | skip |= renderpass_context->ValidateEndRenderPass(cb_context.GetExecutionContext(), CmdName()); |
| 5815 | return skip; |
| 5816 | } |
| 5817 | |
| 5818 | void SyncOpEndRenderPass::Record(CommandBufferAccessContext *cb_context) const { |
| 5819 | // TODO PHASE2 need to have a consistent way to record to either command buffer or queue contexts |
| 5820 | cb_context->RecordEndRenderPass(cmd_); |
| 5821 | } |
Jeremy Gebben | df3fcc3 | 2021-02-15 08:53:17 -0700 | [diff] [blame] | 5822 | |
| 5823 | void SyncValidator::PreCallRecordCmdWriteBufferMarker2AMD(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 5824 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
| 5825 | StateTracker::PreCallRecordCmdWriteBufferMarker2AMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
| 5826 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 5827 | assert(cb_access_context); |
| 5828 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 5829 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 5830 | assert(context); |
| 5831 | |
| 5832 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 5833 | |
| 5834 | if (dst_buffer) { |
| 5835 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
| 5836 | context->UpdateAccessState(*dst_buffer, SYNC_COPY_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
| 5837 | } |
| 5838 | } |
John Zulauf | d05c584 | 2021-03-26 11:32:16 -0600 | [diff] [blame] | 5839 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 5840 | AttachmentViewGen::AttachmentViewGen(const IMAGE_VIEW_STATE *view, const VkOffset3D &offset, const VkExtent3D &extent) |
| 5841 | : view_(view), view_mask_(), gen_store_() { |
| 5842 | if (!view_ || !view_->image_state || !SimpleBinding(*view_->image_state)) return; |
| 5843 | const IMAGE_STATE &image_state = *view_->image_state.get(); |
| 5844 | const auto base_address = ResourceBaseAddress(image_state); |
| 5845 | const auto *encoder = image_state.fragment_encoder.get(); |
| 5846 | if (!encoder) return; |
| 5847 | const VkOffset3D zero_offset = {0, 0, 0}; |
| 5848 | const VkExtent3D &image_extent = image_state.createInfo.extent; |
| 5849 | // Intentional copy |
| 5850 | VkImageSubresourceRange subres_range = view_->normalized_subresource_range; |
| 5851 | view_mask_ = subres_range.aspectMask; |
| 5852 | gen_store_[Gen::kViewSubresource].emplace(*encoder, subres_range, zero_offset, image_extent, base_address); |
| 5853 | gen_store_[Gen::kRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 5854 | |
| 5855 | const auto depth = view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT; |
| 5856 | if (depth && (depth != view_mask_)) { |
| 5857 | subres_range.aspectMask = depth; |
| 5858 | gen_store_[Gen::kDepthOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 5859 | } |
| 5860 | const auto stencil = view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT; |
| 5861 | if (stencil && (stencil != view_mask_)) { |
| 5862 | subres_range.aspectMask = stencil; |
| 5863 | gen_store_[Gen::kStencilOnlyRenderArea].emplace(*encoder, subres_range, offset, extent, base_address); |
| 5864 | } |
| 5865 | } |
| 5866 | |
| 5867 | const ImageRangeGen *AttachmentViewGen::GetRangeGen(AttachmentViewGen::Gen gen_type) const { |
| 5868 | const ImageRangeGen *got = nullptr; |
| 5869 | switch (gen_type) { |
| 5870 | case kViewSubresource: |
| 5871 | got = &gen_store_[kViewSubresource]; |
| 5872 | break; |
| 5873 | case kRenderArea: |
| 5874 | got = &gen_store_[kRenderArea]; |
| 5875 | break; |
| 5876 | case kDepthOnlyRenderArea: |
| 5877 | got = |
| 5878 | (view_mask_ == VK_IMAGE_ASPECT_DEPTH_BIT) ? &gen_store_[Gen::kRenderArea] : &gen_store_[Gen::kDepthOnlyRenderArea]; |
| 5879 | break; |
| 5880 | case kStencilOnlyRenderArea: |
| 5881 | got = (view_mask_ == VK_IMAGE_ASPECT_STENCIL_BIT) ? &gen_store_[Gen::kRenderArea] |
| 5882 | : &gen_store_[Gen::kStencilOnlyRenderArea]; |
| 5883 | break; |
| 5884 | default: |
| 5885 | assert(got); |
| 5886 | } |
| 5887 | return got; |
| 5888 | } |
| 5889 | |
| 5890 | AttachmentViewGen::Gen AttachmentViewGen::GetDepthStencilRenderAreaGenType(bool depth_op, bool stencil_op) const { |
| 5891 | assert(IsValid()); |
| 5892 | assert(view_mask_ & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); |
| 5893 | if (depth_op) { |
| 5894 | assert(view_mask_ & VK_IMAGE_ASPECT_DEPTH_BIT); |
| 5895 | if (stencil_op) { |
| 5896 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 5897 | return kRenderArea; |
| 5898 | } |
| 5899 | return kDepthOnlyRenderArea; |
| 5900 | } |
| 5901 | if (stencil_op) { |
| 5902 | assert(view_mask_ & VK_IMAGE_ASPECT_STENCIL_BIT); |
| 5903 | return kStencilOnlyRenderArea; |
| 5904 | } |
| 5905 | |
| 5906 | assert(depth_op || stencil_op); |
| 5907 | return kRenderArea; |
| 5908 | } |
| 5909 | |
| 5910 | AccessAddressType AttachmentViewGen::GetAddressType() const { return AccessContext::ImageAddressType(*view_->image_state); } |