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 | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 29 | const static std::array<AccessAddressType, static_cast<size_t>(AccessAddressType::kTypeCount)> kAddressTypes = { |
| 30 | AccessAddressType::kLinear, AccessAddressType::kIdealized}; |
| 31 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 32 | static constexpr AccessAddressType GetAccessAddressType(const BUFFER_STATE &) { return AccessAddressType::kLinear; }; |
| 33 | static AccessAddressType GetAccessAddressType(const IMAGE_STATE &image) { return AccessContext::ImageAddressType(image); } |
| 34 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 35 | static const char *string_SyncHazardVUID(SyncHazard hazard) { |
| 36 | switch (hazard) { |
| 37 | case SyncHazard::NONE: |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 38 | return "SYNC-HAZARD-NONE"; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 39 | break; |
| 40 | case SyncHazard::READ_AFTER_WRITE: |
| 41 | return "SYNC-HAZARD-READ_AFTER_WRITE"; |
| 42 | break; |
| 43 | case SyncHazard::WRITE_AFTER_READ: |
| 44 | return "SYNC-HAZARD-WRITE_AFTER_READ"; |
| 45 | break; |
| 46 | case SyncHazard::WRITE_AFTER_WRITE: |
| 47 | return "SYNC-HAZARD-WRITE_AFTER_WRITE"; |
| 48 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 49 | case SyncHazard::READ_RACING_WRITE: |
| 50 | return "SYNC-HAZARD-READ-RACING-WRITE"; |
| 51 | break; |
| 52 | case SyncHazard::WRITE_RACING_WRITE: |
| 53 | return "SYNC-HAZARD-WRITE-RACING-WRITE"; |
| 54 | break; |
| 55 | case SyncHazard::WRITE_RACING_READ: |
| 56 | return "SYNC-HAZARD-WRITE-RACING-READ"; |
| 57 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 58 | default: |
| 59 | assert(0); |
| 60 | } |
| 61 | return "SYNC-HAZARD-INVALID"; |
| 62 | } |
| 63 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 64 | static bool IsHazardVsRead(SyncHazard hazard) { |
| 65 | switch (hazard) { |
| 66 | case SyncHazard::NONE: |
| 67 | return false; |
| 68 | break; |
| 69 | case SyncHazard::READ_AFTER_WRITE: |
| 70 | return false; |
| 71 | break; |
| 72 | case SyncHazard::WRITE_AFTER_READ: |
| 73 | return true; |
| 74 | break; |
| 75 | case SyncHazard::WRITE_AFTER_WRITE: |
| 76 | return false; |
| 77 | break; |
| 78 | case SyncHazard::READ_RACING_WRITE: |
| 79 | return false; |
| 80 | break; |
| 81 | case SyncHazard::WRITE_RACING_WRITE: |
| 82 | return false; |
| 83 | break; |
| 84 | case SyncHazard::WRITE_RACING_READ: |
| 85 | return true; |
| 86 | break; |
| 87 | default: |
| 88 | assert(0); |
| 89 | } |
| 90 | return false; |
| 91 | } |
| 92 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 93 | static const char *string_SyncHazard(SyncHazard hazard) { |
| 94 | switch (hazard) { |
| 95 | case SyncHazard::NONE: |
| 96 | return "NONR"; |
| 97 | break; |
| 98 | case SyncHazard::READ_AFTER_WRITE: |
| 99 | return "READ_AFTER_WRITE"; |
| 100 | break; |
| 101 | case SyncHazard::WRITE_AFTER_READ: |
| 102 | return "WRITE_AFTER_READ"; |
| 103 | break; |
| 104 | case SyncHazard::WRITE_AFTER_WRITE: |
| 105 | return "WRITE_AFTER_WRITE"; |
| 106 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 107 | case SyncHazard::READ_RACING_WRITE: |
| 108 | return "READ_RACING_WRITE"; |
| 109 | break; |
| 110 | case SyncHazard::WRITE_RACING_WRITE: |
| 111 | return "WRITE_RACING_WRITE"; |
| 112 | break; |
| 113 | case SyncHazard::WRITE_RACING_READ: |
| 114 | return "WRITE_RACING_READ"; |
| 115 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 116 | default: |
| 117 | assert(0); |
| 118 | } |
| 119 | return "INVALID HAZARD"; |
| 120 | } |
| 121 | |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 122 | static const SyncStageAccessInfoType *SyncStageAccessInfoFromMask(SyncStageAccessFlags flags) { |
| 123 | // Return the info for the first bit found |
| 124 | const SyncStageAccessInfoType *info = nullptr; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 125 | for (size_t i = 0; i < flags.size(); i++) { |
| 126 | if (flags.test(i)) { |
| 127 | info = &syncStageAccessInfoByStageAccessIndex[i]; |
| 128 | break; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | return info; |
| 132 | } |
| 133 | |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 134 | static std::string string_SyncStageAccessFlags(const SyncStageAccessFlags &flags, const char *sep = "|") { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 135 | std::string out_str; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 136 | if (flags.none()) { |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 137 | out_str = "0"; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 138 | } else { |
| 139 | for (size_t i = 0; i < syncStageAccessInfoByStageAccessIndex.size(); i++) { |
| 140 | const auto &info = syncStageAccessInfoByStageAccessIndex[i]; |
| 141 | if ((flags & info.stage_access_bit).any()) { |
| 142 | if (!out_str.empty()) { |
| 143 | out_str.append(sep); |
| 144 | } |
| 145 | out_str.append(info.name); |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 146 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 147 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 148 | if (out_str.length() == 0) { |
| 149 | out_str.append("Unhandled SyncStageAccess"); |
| 150 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 151 | } |
| 152 | return out_str; |
| 153 | } |
| 154 | |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 155 | static std::string string_UsageTag(const ResourceUsageTag &tag) { |
| 156 | std::stringstream out; |
| 157 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 158 | out << "command: " << CommandTypeString(tag.command); |
| 159 | out << ", seq_no: " << tag.seq_num; |
| 160 | if (tag.sub_command != 0) { |
| 161 | out << ", subcmd: " << tag.sub_command; |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 162 | } |
| 163 | return out.str(); |
| 164 | } |
| 165 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 166 | std::string CommandBufferAccessContext::FormatUsage(const HazardResult &hazard) const { |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 167 | const auto &tag = hazard.tag; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 168 | assert(hazard.usage_index < static_cast<SyncStageAccessIndex>(syncStageAccessInfoByStageAccessIndex.size())); |
| 169 | const auto &usage_info = syncStageAccessInfoByStageAccessIndex[hazard.usage_index]; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 170 | std::stringstream out; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 171 | const auto *info = SyncStageAccessInfoFromMask(hazard.prior_access); |
| 172 | const char *stage_access_name = info ? info->name : "INVALID_STAGE_ACCESS"; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 173 | out << "(usage: " << usage_info.name << ", prior_usage: " << stage_access_name; |
| 174 | if (IsHazardVsRead(hazard.hazard)) { |
| 175 | const auto barriers = hazard.access_state->GetReadBarriers(hazard.prior_access); |
| 176 | out << ", read_barriers: " << string_VkPipelineStageFlags(barriers); |
| 177 | } else { |
| 178 | SyncStageAccessFlags write_barrier = hazard.access_state->GetWriteBarriers(); |
| 179 | out << ", write_barriers: " << string_SyncStageAccessFlags(write_barrier); |
| 180 | } |
| 181 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 182 | // PHASE2 TODO -- add comand buffer and reset from secondary if applicable |
| 183 | out << ", " << string_UsageTag(tag) << ", reset_no: " << reset_count_; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 184 | return out.str(); |
| 185 | } |
| 186 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 187 | // NOTE: the attachement read flag is put *only* in the access scope and not in the exect scope, since the ordering |
| 188 | // rules apply only to this specific access for this stage, and not the stage as a whole. The ordering detection |
| 189 | // also reflects this special case for read hazard detection (using access instead of exec scope) |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 190 | static constexpr VkPipelineStageFlags kColorAttachmentExecScope = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 191 | static const SyncStageAccessFlags kColorAttachmentAccessScope = |
| 192 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_BIT | |
| 193 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT | |
| 194 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE_BIT | |
| 195 | SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT; // Note: this is intentionally not in the exec scope |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 196 | static constexpr VkPipelineStageFlags kDepthStencilAttachmentExecScope = |
| 197 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 198 | static const SyncStageAccessFlags kDepthStencilAttachmentAccessScope = |
| 199 | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 200 | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 201 | SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT; // Note: this is intentionally not in the exec scope |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 202 | static constexpr VkPipelineStageFlags kRasterAttachmentExecScope = kDepthStencilAttachmentExecScope | kColorAttachmentExecScope; |
| 203 | static const SyncStageAccessFlags kRasterAttachmentAccessScope = kDepthStencilAttachmentAccessScope | kColorAttachmentAccessScope; |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 204 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 205 | ResourceAccessState::OrderingBarriers ResourceAccessState::kOrderingRules = { |
| 206 | {{0U, SyncStageAccessFlags()}, |
| 207 | {kColorAttachmentExecScope, kColorAttachmentAccessScope}, |
| 208 | {kDepthStencilAttachmentExecScope, kDepthStencilAttachmentAccessScope}, |
| 209 | {kRasterAttachmentExecScope, kRasterAttachmentAccessScope}}}; |
| 210 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 211 | // 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] | 212 | static const ResourceUsageTag kCurrentCommandTag(ResourceUsageTag::kMaxIndex, ResourceUsageTag::kMaxCount, |
| 213 | ResourceUsageTag::kMaxCount, CMD_NONE); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 214 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 215 | static VkDeviceSize ResourceBaseAddress(const BINDABLE &bindable) { |
| 216 | return bindable.binding.offset + bindable.binding.mem_state->fake_base_address; |
| 217 | } |
| 218 | |
| 219 | static bool SimpleBinding(const BINDABLE &bindable) { return !bindable.sparse && bindable.binding.mem_state; } |
| 220 | |
locke-lunarg | 3c03800 | 2020-04-30 23:08:08 -0600 | [diff] [blame] | 221 | inline VkDeviceSize GetRealWholeSize(VkDeviceSize offset, VkDeviceSize size, VkDeviceSize whole_size) { |
| 222 | if (size == VK_WHOLE_SIZE) { |
| 223 | return (whole_size - offset); |
| 224 | } |
| 225 | return size; |
| 226 | } |
| 227 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 228 | static inline VkDeviceSize GetBufferWholeSize(const BUFFER_STATE &buf_state, VkDeviceSize offset, VkDeviceSize size) { |
| 229 | return GetRealWholeSize(offset, size, buf_state.createInfo.size); |
| 230 | } |
| 231 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 232 | template <typename T> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 233 | static ResourceAccessRange MakeRange(const T &has_offset_and_size) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 234 | return ResourceAccessRange(has_offset_and_size.offset, (has_offset_and_size.offset + has_offset_and_size.size)); |
| 235 | } |
| 236 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 237 | static ResourceAccessRange MakeRange(VkDeviceSize start, VkDeviceSize size) { return ResourceAccessRange(start, (start + size)); } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 238 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 239 | static inline ResourceAccessRange MakeRange(const BUFFER_STATE &buffer, VkDeviceSize offset, VkDeviceSize size) { |
| 240 | return MakeRange(offset, GetBufferWholeSize(buffer, offset, size)); |
| 241 | } |
| 242 | |
| 243 | static inline ResourceAccessRange MakeRange(const BUFFER_VIEW_STATE &buf_view_state) { |
| 244 | return MakeRange(*buf_view_state.buffer_state.get(), buf_view_state.create_info.offset, buf_view_state.create_info.range); |
| 245 | } |
| 246 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 247 | // Range generators for to allow event scope filtration to be limited to the top of the resource access traversal pipeline |
| 248 | // |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 249 | // Note: there is no "begin/end" or reset facility. These are each written as "one time through" generators. |
| 250 | // |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 251 | // Usage: |
| 252 | // Constructor() -- initializes the generator to point to the begin of the space declared. |
| 253 | // * -- the current range of the generator empty signfies end |
| 254 | // ++ -- advance to the next non-empty range (or end) |
| 255 | |
| 256 | // A wrapper for a single range with the same semantics as the actual generators below |
| 257 | template <typename KeyType> |
| 258 | class SingleRangeGenerator { |
| 259 | public: |
| 260 | SingleRangeGenerator(const KeyType &range) : current_(range) {} |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 261 | const KeyType &operator*() const { return current_; } |
| 262 | const KeyType *operator->() const { return ¤t_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 263 | SingleRangeGenerator &operator++() { |
| 264 | current_ = KeyType(); // just one real range |
| 265 | return *this; |
| 266 | } |
| 267 | |
| 268 | bool operator==(const SingleRangeGenerator &other) const { return current_ == other.current_; } |
| 269 | |
| 270 | private: |
| 271 | SingleRangeGenerator() = default; |
| 272 | const KeyType range_; |
| 273 | KeyType current_; |
| 274 | }; |
| 275 | |
| 276 | // Generate the ranges that are the intersection of range and the entries in the FilterMap |
| 277 | template <typename FilterMap, typename KeyType = typename FilterMap::key_type> |
| 278 | class FilteredRangeGenerator { |
| 279 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 280 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 281 | FilteredRangeGenerator() : range_(), filter_(nullptr), filter_pos_(), current_() { |
| 282 | // Default construction for KeyType *must* be empty range |
| 283 | assert(current_.empty()); |
| 284 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 285 | FilteredRangeGenerator(const FilterMap &filter, const KeyType &range) |
| 286 | : range_(range), filter_(&filter), filter_pos_(), current_() { |
| 287 | SeekBegin(); |
| 288 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 289 | FilteredRangeGenerator(const FilteredRangeGenerator &from) = default; |
| 290 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 291 | const KeyType &operator*() const { return current_; } |
| 292 | const KeyType *operator->() const { return ¤t_; } |
| 293 | FilteredRangeGenerator &operator++() { |
| 294 | ++filter_pos_; |
| 295 | UpdateCurrent(); |
| 296 | return *this; |
| 297 | } |
| 298 | |
| 299 | bool operator==(const FilteredRangeGenerator &other) const { return current_ == other.current_; } |
| 300 | |
| 301 | private: |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 302 | void UpdateCurrent() { |
| 303 | if (filter_pos_ != filter_->cend()) { |
| 304 | current_ = range_ & filter_pos_->first; |
| 305 | } else { |
| 306 | current_ = KeyType(); |
| 307 | } |
| 308 | } |
| 309 | void SeekBegin() { |
| 310 | filter_pos_ = filter_->lower_bound(range_); |
| 311 | UpdateCurrent(); |
| 312 | } |
| 313 | const KeyType range_; |
| 314 | const FilterMap *filter_; |
| 315 | typename FilterMap::const_iterator filter_pos_; |
| 316 | KeyType current_; |
| 317 | }; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 318 | using SingleAccessRangeGenerator = SingleRangeGenerator<ResourceAccessRange>; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 319 | using EventSimpleRangeGenerator = FilteredRangeGenerator<SyncEventState::ScopeMap>; |
| 320 | |
| 321 | // Templated to allow for different Range generators or map sources... |
| 322 | |
| 323 | // 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] | 324 | template <typename FilterMap, typename RangeGen, typename KeyType = typename FilterMap::key_type> |
| 325 | class FilteredGeneratorGenerator { |
| 326 | public: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 327 | // Default constructed is safe to dereference for "empty" test, but for no other operation. |
| 328 | FilteredGeneratorGenerator() : filter_(nullptr), gen_(), filter_pos_(), current_() { |
| 329 | // Default construction for KeyType *must* be empty range |
| 330 | assert(current_.empty()); |
| 331 | } |
| 332 | 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] | 333 | SeekBegin(); |
| 334 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 335 | FilteredGeneratorGenerator(const FilteredGeneratorGenerator &from) = default; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 336 | const KeyType &operator*() const { return current_; } |
| 337 | const KeyType *operator->() const { return ¤t_; } |
| 338 | FilteredGeneratorGenerator &operator++() { |
| 339 | KeyType gen_range = GenRange(); |
| 340 | KeyType filter_range = FilterRange(); |
| 341 | current_ = KeyType(); |
| 342 | while (gen_range.non_empty() && filter_range.non_empty() && current_.empty()) { |
| 343 | if (gen_range.end > filter_range.end) { |
| 344 | // if the generated range is beyond the filter_range, advance the filter range |
| 345 | filter_range = AdvanceFilter(); |
| 346 | } else { |
| 347 | gen_range = AdvanceGen(); |
| 348 | } |
| 349 | current_ = gen_range & filter_range; |
| 350 | } |
| 351 | return *this; |
| 352 | } |
| 353 | |
| 354 | bool operator==(const FilteredGeneratorGenerator &other) const { return current_ == other.current_; } |
| 355 | |
| 356 | private: |
| 357 | KeyType AdvanceFilter() { |
| 358 | ++filter_pos_; |
| 359 | auto filter_range = FilterRange(); |
| 360 | if (filter_range.valid()) { |
| 361 | FastForwardGen(filter_range); |
| 362 | } |
| 363 | return filter_range; |
| 364 | } |
| 365 | KeyType AdvanceGen() { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 366 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 367 | auto gen_range = GenRange(); |
| 368 | if (gen_range.valid()) { |
| 369 | FastForwardFilter(gen_range); |
| 370 | } |
| 371 | return gen_range; |
| 372 | } |
| 373 | |
| 374 | KeyType FilterRange() const { return (filter_pos_ != filter_->cend()) ? filter_pos_->first : KeyType(); } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 375 | KeyType GenRange() const { return *gen_; } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 376 | |
| 377 | KeyType FastForwardFilter(const KeyType &range) { |
| 378 | auto filter_range = FilterRange(); |
| 379 | int retry_count = 0; |
John Zulauf | 10f1f52 | 2020-12-18 12:00:35 -0700 | [diff] [blame] | 380 | const static int kRetryLimit = 2; // TODO -- determine whether this limit is optimal |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 381 | while (!filter_range.empty() && (filter_range.end <= range.begin)) { |
| 382 | if (retry_count < kRetryLimit) { |
| 383 | ++filter_pos_; |
| 384 | filter_range = FilterRange(); |
| 385 | retry_count++; |
| 386 | } else { |
| 387 | // Okay we've tried walking, do a seek. |
| 388 | filter_pos_ = filter_->lower_bound(range); |
| 389 | break; |
| 390 | } |
| 391 | } |
| 392 | return FilterRange(); |
| 393 | } |
| 394 | |
| 395 | // TODO: Consider adding "seek" (or an absolute bound "get" to range generators to make this walk |
| 396 | // faster. |
| 397 | KeyType FastForwardGen(const KeyType &range) { |
| 398 | auto gen_range = GenRange(); |
| 399 | while (!gen_range.empty() && (gen_range.end <= range.begin)) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 400 | ++gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 401 | gen_range = GenRange(); |
| 402 | } |
| 403 | return gen_range; |
| 404 | } |
| 405 | |
| 406 | void SeekBegin() { |
| 407 | auto gen_range = GenRange(); |
| 408 | if (gen_range.empty()) { |
| 409 | current_ = KeyType(); |
| 410 | filter_pos_ = filter_->cend(); |
| 411 | } else { |
| 412 | filter_pos_ = filter_->lower_bound(gen_range); |
| 413 | current_ = gen_range & FilterRange(); |
| 414 | } |
| 415 | } |
| 416 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 417 | const FilterMap *filter_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 418 | RangeGen gen_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 419 | typename FilterMap::const_iterator filter_pos_; |
| 420 | KeyType current_; |
| 421 | }; |
| 422 | |
| 423 | using EventImageRangeGenerator = FilteredGeneratorGenerator<SyncEventState::ScopeMap, subresource_adapter::ImageRangeGenerator>; |
| 424 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 425 | 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] | 426 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 427 | ResourceAccessRange GetBufferRange(VkDeviceSize offset, VkDeviceSize buf_whole_size, uint32_t first_index, uint32_t count, |
| 428 | VkDeviceSize stride) { |
| 429 | VkDeviceSize range_start = offset + first_index * stride; |
| 430 | VkDeviceSize range_size = 0; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 431 | if (count == UINT32_MAX) { |
| 432 | range_size = buf_whole_size - range_start; |
| 433 | } else { |
| 434 | range_size = count * stride; |
| 435 | } |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 436 | return MakeRange(range_start, range_size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 437 | } |
| 438 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 439 | SyncStageAccessIndex GetSyncStageAccessIndexsByDescriptorSet(VkDescriptorType descriptor_type, const interface_var &descriptor_data, |
| 440 | VkShaderStageFlagBits stage_flag) { |
| 441 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 442 | assert(stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT); |
| 443 | return SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ; |
| 444 | } |
| 445 | auto stage_access = syncStageAccessMaskByShaderStage.find(stage_flag); |
| 446 | if (stage_access == syncStageAccessMaskByShaderStage.end()) { |
| 447 | assert(0); |
| 448 | } |
| 449 | if (descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) { |
| 450 | return stage_access->second.uniform_read; |
| 451 | } |
| 452 | |
| 453 | // If the desriptorSet is writable, we don't need to care SHADER_READ. SHADER_WRITE is enough. |
| 454 | // Because if write hazard happens, read hazard might or might not happen. |
| 455 | // But if write hazard doesn't happen, read hazard is impossible to happen. |
| 456 | if (descriptor_data.is_writable) { |
| 457 | return stage_access->second.shader_write; |
| 458 | } |
| 459 | return stage_access->second.shader_read; |
| 460 | } |
| 461 | |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 462 | bool IsImageLayoutDepthWritable(VkImageLayout image_layout) { |
| 463 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 464 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL || |
| 465 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) |
| 466 | ? true |
| 467 | : false; |
| 468 | } |
| 469 | |
| 470 | bool IsImageLayoutStencilWritable(VkImageLayout image_layout) { |
| 471 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 472 | image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL || |
| 473 | image_layout == VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL) |
| 474 | ? true |
| 475 | : false; |
| 476 | } |
| 477 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 478 | // 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] | 479 | template <typename Action> |
| 480 | static void ApplyOverImageRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &subresource_range_arg, |
| 481 | Action &action) { |
| 482 | // At this point the "apply over range" logic only supports a single memory binding |
| 483 | if (!SimpleBinding(image_state)) return; |
| 484 | auto subresource_range = NormalizeSubresourceRange(image_state.createInfo, subresource_range_arg); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 485 | const auto base_address = ResourceBaseAddress(image_state); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 486 | subresource_adapter::ImageRangeGenerator range_gen(*image_state.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
| 487 | image_state.createInfo.extent, base_address); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 488 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 489 | action(*range_gen); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 493 | // Tranverse the attachment resolves for this a specific subpass, and do action() to them. |
| 494 | // Used by both validation and record operations |
| 495 | // |
| 496 | // The signature for Action() reflect the needs of both uses. |
| 497 | template <typename Action> |
| 498 | void ResolveOperation(Action &action, const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 499 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass) { |
| 500 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 501 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 502 | const auto &rp_ci = rp_state.createInfo; |
| 503 | const auto *attachment_ci = rp_ci.pAttachments; |
| 504 | const auto &subpass_ci = rp_ci.pSubpasses[subpass]; |
| 505 | |
| 506 | // Color resolves -- require an inuse color attachment and a matching inuse resolve attachment |
| 507 | const auto *color_attachments = subpass_ci.pColorAttachments; |
| 508 | const auto *color_resolve = subpass_ci.pResolveAttachments; |
| 509 | if (color_resolve && color_attachments) { |
| 510 | for (uint32_t i = 0; i < subpass_ci.colorAttachmentCount; i++) { |
| 511 | const auto &color_attach = color_attachments[i].attachment; |
| 512 | const auto &resolve_attach = subpass_ci.pResolveAttachments[i].attachment; |
| 513 | if ((color_attach != VK_ATTACHMENT_UNUSED) && (resolve_attach != VK_ATTACHMENT_UNUSED)) { |
| 514 | action("color", "resolve read", color_attach, resolve_attach, attachment_views[color_attach], |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 515 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, SyncOrdering::kColorAttachment, offset, extent, 0); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 516 | action("color", "resolve write", color_attach, resolve_attach, attachment_views[resolve_attach], |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 517 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kColorAttachment, offset, extent, 0); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | // Depth stencil resolve only if the extension is present |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 523 | const auto ds_resolve = LvlFindInChain<VkSubpassDescriptionDepthStencilResolve>(subpass_ci.pNext); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 524 | if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment && |
| 525 | (ds_resolve->pDepthStencilResolveAttachment->attachment != VK_ATTACHMENT_UNUSED) && subpass_ci.pDepthStencilAttachment && |
| 526 | (subpass_ci.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) { |
| 527 | const auto src_at = subpass_ci.pDepthStencilAttachment->attachment; |
| 528 | const auto src_ci = attachment_ci[src_at]; |
| 529 | // The formats are required to match so we can pick either |
| 530 | const bool resolve_depth = (ds_resolve->depthResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasDepth(src_ci.format); |
| 531 | const bool resolve_stencil = (ds_resolve->stencilResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasStencil(src_ci.format); |
| 532 | const auto dst_at = ds_resolve->pDepthStencilResolveAttachment->attachment; |
| 533 | VkImageAspectFlags aspect_mask = 0u; |
| 534 | |
| 535 | // Figure out which aspects are actually touched during resolve operations |
| 536 | const char *aspect_string = nullptr; |
| 537 | if (resolve_depth && resolve_stencil) { |
| 538 | // Validate all aspects together |
| 539 | aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 540 | aspect_string = "depth/stencil"; |
| 541 | } else if (resolve_depth) { |
| 542 | // Validate depth only |
| 543 | aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 544 | aspect_string = "depth"; |
| 545 | } else if (resolve_stencil) { |
| 546 | // Validate all stencil only |
| 547 | aspect_mask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 548 | aspect_string = "stencil"; |
| 549 | } |
| 550 | |
| 551 | if (aspect_mask) { |
| 552 | action(aspect_string, "resolve read", src_at, dst_at, attachment_views[src_at], |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 553 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, SyncOrdering::kRaster, offset, extent, aspect_mask); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 554 | action(aspect_string, "resolve write", src_at, dst_at, attachment_views[dst_at], |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 555 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, offset, extent, aspect_mask); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | // Action for validating resolve operations |
| 561 | class ValidateResolveAction { |
| 562 | public: |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 563 | ValidateResolveAction(VkRenderPass render_pass, uint32_t subpass, const AccessContext &context, |
| 564 | const CommandBufferAccessContext &cb_context, const char *func_name) |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 565 | : render_pass_(render_pass), |
| 566 | subpass_(subpass), |
| 567 | context_(context), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 568 | cb_context_(cb_context), |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 569 | func_name_(func_name), |
| 570 | skip_(false) {} |
| 571 | void operator()(const char *aspect_name, const char *attachment_name, uint32_t src_at, uint32_t dst_at, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 572 | const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 573 | const VkOffset3D &offset, const VkExtent3D &extent, VkImageAspectFlags aspect_mask) { |
| 574 | HazardResult hazard; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 575 | hazard = context_.DetectHazard(view, current_usage, ordering_rule, offset, extent, aspect_mask); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 576 | if (hazard.hazard) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 577 | skip_ |= |
| 578 | cb_context_.GetSyncState().LogError(render_pass_, string_SyncHazardVUID(hazard.hazard), |
| 579 | "%s: Hazard %s in subpass %" PRIu32 "during %s %s, from attachment %" PRIu32 |
| 580 | " to resolve attachment %" PRIu32 ". Access info %s.", |
| 581 | func_name_, string_SyncHazard(hazard.hazard), subpass_, aspect_name, |
| 582 | attachment_name, src_at, dst_at, cb_context_.FormatUsage(hazard).c_str()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | // Providing a mechanism for the constructing caller to get the result of the validation |
| 586 | bool GetSkip() const { return skip_; } |
| 587 | |
| 588 | private: |
| 589 | VkRenderPass render_pass_; |
| 590 | const uint32_t subpass_; |
| 591 | const AccessContext &context_; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 592 | const CommandBufferAccessContext &cb_context_; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 593 | const char *func_name_; |
| 594 | bool skip_; |
| 595 | }; |
| 596 | |
| 597 | // Update action for resolve operations |
| 598 | class UpdateStateResolveAction { |
| 599 | public: |
| 600 | UpdateStateResolveAction(AccessContext &context, const ResourceUsageTag &tag) : context_(context), tag_(tag) {} |
| 601 | void operator()(const char *aspect_name, const char *attachment_name, uint32_t src_at, uint32_t dst_at, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 602 | const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 603 | const VkOffset3D &offset, const VkExtent3D &extent, VkImageAspectFlags aspect_mask) { |
| 604 | // Ignores validation only arguments... |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 605 | context_.UpdateAccessState(view, current_usage, ordering_rule, offset, extent, aspect_mask, tag_); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | private: |
| 609 | AccessContext &context_; |
| 610 | const ResourceUsageTag &tag_; |
| 611 | }; |
| 612 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 613 | void HazardResult::Set(const ResourceAccessState *access_state_, SyncStageAccessIndex usage_index_, SyncHazard hazard_, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 614 | const SyncStageAccessFlags &prior_, const ResourceUsageTag &tag_) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 615 | access_state = std::unique_ptr<const ResourceAccessState>(new ResourceAccessState(*access_state_)); |
| 616 | usage_index = usage_index_; |
| 617 | hazard = hazard_; |
| 618 | prior_access = prior_; |
| 619 | tag = tag_; |
| 620 | } |
| 621 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 622 | AccessContext::AccessContext(uint32_t subpass, VkQueueFlags queue_flags, |
| 623 | const std::vector<SubpassDependencyGraphNode> &dependencies, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 624 | const std::vector<AccessContext> &contexts, const AccessContext *external_context) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 625 | Reset(); |
| 626 | const auto &subpass_dep = dependencies[subpass]; |
| 627 | prev_.reserve(subpass_dep.prev.size()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 628 | 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] | 629 | for (const auto &prev_dep : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 630 | const auto prev_pass = prev_dep.first->pass; |
| 631 | const auto &prev_barriers = prev_dep.second; |
| 632 | assert(prev_dep.second.size()); |
| 633 | prev_.emplace_back(&contexts[prev_pass], queue_flags, prev_barriers); |
| 634 | prev_by_subpass_[prev_pass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 635 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 636 | |
| 637 | async_.reserve(subpass_dep.async.size()); |
| 638 | for (const auto async_subpass : subpass_dep.async) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 639 | async_.emplace_back(&contexts[async_subpass]); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 640 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 641 | if (subpass_dep.barrier_from_external.size()) { |
| 642 | src_external_ = TrackBack(external_context, queue_flags, subpass_dep.barrier_from_external); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 643 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 644 | if (subpass_dep.barrier_to_external.size()) { |
| 645 | dst_external_ = TrackBack(this, queue_flags, subpass_dep.barrier_to_external); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 646 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 647 | } |
| 648 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 649 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 650 | HazardResult AccessContext::DetectPreviousHazard(AccessAddressType type, const Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 651 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 652 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 653 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 654 | |
| 655 | HazardResult hazard; |
| 656 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 657 | hazard = detector.Detect(prev); |
| 658 | } |
| 659 | return hazard; |
| 660 | } |
| 661 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 662 | template <typename Action> |
| 663 | void AccessContext::ForAll(Action &&action) { |
| 664 | for (const auto address_type : kAddressTypes) { |
| 665 | auto &accesses = GetAccessStateMap(address_type); |
| 666 | for (const auto &access : accesses) { |
| 667 | action(address_type, access); |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 672 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 673 | // the DAG of the contexts (for example subpasses) |
| 674 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 675 | HazardResult AccessContext::DetectHazard(AccessAddressType type, const Detector &detector, const ResourceAccessRange &range, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 676 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 677 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 678 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 679 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 680 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 681 | // so we'll check these first |
| 682 | for (const auto &async_context : async_) { |
| 683 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 684 | if (hazard.hazard) return hazard; |
| 685 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 686 | } |
| 687 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 688 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 689 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 690 | const auto &accesses = GetAccessStateMap(type); |
| 691 | const auto from = accesses.lower_bound(range); |
| 692 | const auto to = accesses.upper_bound(range); |
| 693 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 694 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 695 | for (auto pos = from; pos != to; ++pos) { |
| 696 | // Cover any leading gap, or gap between entries |
| 697 | if (detect_prev) { |
| 698 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 699 | // Cover any leading gap, or gap between entries |
| 700 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 701 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 702 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 703 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 704 | if (hazard.hazard) return hazard; |
| 705 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 706 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 707 | gap.begin = pos->first.end; |
| 708 | } |
| 709 | |
| 710 | hazard = detector.Detect(pos); |
| 711 | if (hazard.hazard) return hazard; |
| 712 | } |
| 713 | |
| 714 | if (detect_prev) { |
| 715 | // Detect in the trailing empty as needed |
| 716 | gap.end = range.end; |
| 717 | if (gap.non_empty()) { |
| 718 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 719 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | return hazard; |
| 723 | } |
| 724 | |
| 725 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 726 | template <typename Detector> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 727 | HazardResult AccessContext::DetectAsyncHazard(AccessAddressType type, const Detector &detector, |
| 728 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 729 | auto &accesses = GetAccessStateMap(type); |
| 730 | const auto from = accesses.lower_bound(range); |
| 731 | const auto to = accesses.upper_bound(range); |
| 732 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 733 | HazardResult hazard; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 734 | for (auto pos = from; pos != to && !hazard.hazard; ++pos) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 735 | hazard = detector.DetectAsync(pos, start_tag_); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 736 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 737 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 738 | return hazard; |
| 739 | } |
| 740 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 741 | struct ApplySubpassTransitionBarriersAction { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 742 | explicit ApplySubpassTransitionBarriersAction(const std::vector<SyncBarrier> &barriers_) : barriers(barriers_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 743 | void operator()(ResourceAccessState *access) const { |
| 744 | assert(access); |
| 745 | access->ApplyBarriers(barriers, true); |
| 746 | } |
| 747 | const std::vector<SyncBarrier> &barriers; |
| 748 | }; |
| 749 | |
| 750 | struct ApplyTrackbackBarriersAction { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 751 | explicit ApplyTrackbackBarriersAction(const std::vector<SyncBarrier> &barriers_) : barriers(barriers_) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 752 | void operator()(ResourceAccessState *access) const { |
| 753 | assert(access); |
| 754 | assert(!access->HasPendingState()); |
| 755 | access->ApplyBarriers(barriers, false); |
| 756 | access->ApplyPendingBarriers(kCurrentCommandTag); |
| 757 | } |
| 758 | const std::vector<SyncBarrier> &barriers; |
| 759 | }; |
| 760 | |
| 761 | // Splits a single map entry into piece matching the entries in [first, last) the total range over [first, last) must be |
| 762 | // contained with entry. Entry must be an iterator pointing to dest, first and last must be iterators pointing to a |
| 763 | // *different* map from dest. |
| 764 | // Returns the position past the last resolved range -- the entry covering the remainder of entry->first not included in the |
| 765 | // range [first, last) |
| 766 | template <typename BarrierAction> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 767 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 768 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 769 | BarrierAction &barrier_action) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 770 | auto at = entry; |
| 771 | for (auto pos = first; pos != last; ++pos) { |
| 772 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 773 | assert(at->first.includes(pos->first)); |
| 774 | assert(at != dest->end()); |
| 775 | // Trim up at to the same size as the entry to resolve |
| 776 | at = sparse_container::split(at, *dest, pos->first); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 777 | auto access = pos->second; // intentional copy |
| 778 | barrier_action(&access); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 779 | at->second.Resolve(access); |
| 780 | ++at; // Go to the remaining unused section of entry |
| 781 | } |
| 782 | } |
| 783 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 784 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 785 | SyncBarrier merged = {}; |
| 786 | for (const auto &barrier : barriers) { |
| 787 | merged.Merge(barrier); |
| 788 | } |
| 789 | return merged; |
| 790 | } |
| 791 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 792 | template <typename BarrierAction> |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 793 | void AccessContext::ResolveAccessRange(AccessAddressType type, const ResourceAccessRange &range, BarrierAction &barrier_action, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 794 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 795 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 796 | if (!range.non_empty()) return; |
| 797 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 798 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 799 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 800 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 801 | if (current->pos_B->valid) { |
| 802 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 803 | auto access = src_pos->second; // intentional copy |
| 804 | barrier_action(&access); |
| 805 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 806 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 807 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 808 | trimmed->second.Resolve(access); |
| 809 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 810 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 811 | 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] | 812 | 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] | 813 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 814 | } else { |
| 815 | // we have to descend to fill this gap |
| 816 | if (recur_to_infill) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 817 | if (current->pos_A->valid) { |
| 818 | // Dest is valid, so we need to accumulate along the DAG and then resolve... in an N-to-1 resolve operation |
| 819 | ResourceAccessRangeMap gap_map; |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 820 | ResolvePreviousAccess(type, current_range, &gap_map, infill_state); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 821 | ResolveMapToEntry(resolve_map, current->pos_A->lower_bound, gap_map.begin(), gap_map.end(), barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 822 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 823 | // There isn't anything in dest in current)range, so we can accumulate directly into it. |
| 824 | ResolvePreviousAccess(type, current_range, resolve_map, infill_state); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 825 | // Need to apply the barrier to the accesses we accumulated, noting that we haven't updated current |
| 826 | for (auto pos = resolve_map->lower_bound(current_range); pos != current->pos_A->lower_bound; ++pos) { |
| 827 | barrier_action(&pos->second); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 831 | // iterator of the outer while. |
| 832 | |
| 833 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 834 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 835 | // we stepped on the dest map |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 836 | const auto seek_to = current_range.end - 1; // The subtraction is safe as range can't be empty (loop condition) |
| 837 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 838 | current.seek(seek_to); |
| 839 | } else if (!current->pos_A->valid && infill_state) { |
| 840 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 841 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 842 | 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] | 843 | } |
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 | ++current; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 846 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 847 | |
| 848 | // Infill if range goes passed both the current and resolve map prior contents |
| 849 | if (recur_to_infill && (current->range.end < range.end)) { |
| 850 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
| 851 | ResourceAccessRangeMap gap_map; |
| 852 | const auto the_end = resolve_map->end(); |
| 853 | ResolvePreviousAccess(type, trailing_fill_range, &gap_map, infill_state); |
| 854 | for (auto &access : gap_map) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 855 | barrier_action(&access.second); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 856 | resolve_map->insert(the_end, access); |
| 857 | } |
| 858 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 859 | } |
| 860 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 861 | void AccessContext::ResolvePreviousAccess(AccessAddressType type, const ResourceAccessRange &range, |
| 862 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state) const { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 863 | if ((prev_.size() == 0) && (src_external_.context == nullptr)) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 864 | if (range.non_empty() && infill_state) { |
| 865 | descent_map->insert(std::make_pair(range, *infill_state)); |
| 866 | } |
| 867 | } else { |
| 868 | // Look for something to fill the gap further along. |
| 869 | for (const auto &prev_dep : prev_) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 870 | const ApplyTrackbackBarriersAction barrier_action(prev_dep.barriers); |
| 871 | prev_dep.context->ResolveAccessRange(type, range, barrier_action, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 872 | } |
| 873 | |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 874 | if (src_external_.context) { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 875 | const ApplyTrackbackBarriersAction barrier_action(src_external_.barriers); |
| 876 | src_external_.context->ResolveAccessRange(type, range, barrier_action, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 877 | } |
| 878 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 879 | } |
| 880 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 881 | // Non-lazy import of all accesses, WaitEvents needs this. |
| 882 | void AccessContext::ResolvePreviousAccesses() { |
| 883 | ResourceAccessState default_state; |
| 884 | for (const auto address_type : kAddressTypes) { |
| 885 | ResolvePreviousAccess(address_type, kFullRange, &GetAccessStateMap(address_type), &default_state); |
| 886 | } |
| 887 | } |
| 888 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 889 | AccessAddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
| 890 | return (image.fragment_encoder->IsLinearImage()) ? AccessAddressType::kLinear : AccessAddressType::kIdealized; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 891 | } |
| 892 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 893 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
| 894 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 895 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE; |
| 896 | return stage_access; |
| 897 | } |
| 898 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
| 899 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 900 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE; |
| 901 | return stage_access; |
| 902 | } |
| 903 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 904 | // Caller must manage returned pointer |
| 905 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
| 906 | uint32_t subpass, const VkRect2D &render_area, |
| 907 | std::vector<const IMAGE_VIEW_STATE *> attachment_views) { |
| 908 | auto *proxy = new AccessContext(context); |
| 909 | proxy->UpdateAttachmentResolveAccess(rp_state, render_area, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 910 | proxy->UpdateAttachmentStoreAccess(rp_state, render_area, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 911 | return proxy; |
| 912 | } |
| 913 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 914 | template <typename BarrierAction> |
John Zulauf | 52446eb | 2020-10-22 16:40:08 -0600 | [diff] [blame] | 915 | class ResolveAccessRangeFunctor { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 916 | public: |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 917 | ResolveAccessRangeFunctor(const AccessContext &context, AccessAddressType address_type, ResourceAccessRangeMap *descent_map, |
| 918 | const ResourceAccessState *infill_state, BarrierAction &barrier_action) |
John Zulauf | 52446eb | 2020-10-22 16:40:08 -0600 | [diff] [blame] | 919 | : context_(context), |
| 920 | address_type_(address_type), |
| 921 | descent_map_(descent_map), |
| 922 | infill_state_(infill_state), |
| 923 | barrier_action_(barrier_action) {} |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 924 | ResolveAccessRangeFunctor() = delete; |
| 925 | void operator()(const ResourceAccessRange &range) const { |
| 926 | context_.ResolveAccessRange(address_type_, range, barrier_action_, descent_map_, infill_state_); |
| 927 | } |
| 928 | |
| 929 | private: |
John Zulauf | 52446eb | 2020-10-22 16:40:08 -0600 | [diff] [blame] | 930 | const AccessContext &context_; |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 931 | const AccessAddressType address_type_; |
John Zulauf | 52446eb | 2020-10-22 16:40:08 -0600 | [diff] [blame] | 932 | ResourceAccessRangeMap *const descent_map_; |
| 933 | const ResourceAccessState *infill_state_; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 934 | BarrierAction &barrier_action_; |
| 935 | }; |
| 936 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 937 | template <typename BarrierAction> |
| 938 | void AccessContext::ResolveAccessRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 939 | BarrierAction &barrier_action, AccessAddressType address_type, |
| 940 | ResourceAccessRangeMap *descent_map, const ResourceAccessState *infill_state) const { |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 941 | const ResolveAccessRangeFunctor<BarrierAction> action(*this, address_type, descent_map, infill_state, barrier_action); |
| 942 | ApplyOverImageRange(image_state, subresource_range, action); |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 943 | } |
| 944 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 945 | // Layout transitions are handled as if the were occuring in the beginning of the next subpass |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 946 | bool AccessContext::ValidateLayoutTransitions(const CommandBufferAccessContext &cb_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 947 | const VkRect2D &render_area, uint32_t subpass, |
| 948 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 949 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 950 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 951 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 952 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 953 | // those affects have not been recorded yet. |
| 954 | // |
| 955 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 956 | // to apply and only copy then, if this proves a hot spot. |
| 957 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 958 | TrackBack proxy_track_back; |
| 959 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 960 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 961 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 962 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 963 | |
| 964 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
| 965 | if (prev_needs_proxy) { |
| 966 | if (!proxy_for_prev) { |
| 967 | proxy_for_prev.reset(CreateStoreResolveProxyContext(*track_back->context, rp_state, transition.prev_pass, |
| 968 | render_area, attachment_views)); |
| 969 | proxy_track_back = *track_back; |
| 970 | proxy_track_back.context = proxy_for_prev.get(); |
| 971 | } |
| 972 | track_back = &proxy_track_back; |
| 973 | } |
| 974 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 975 | if (hazard.hazard) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 976 | skip |= cb_context.GetSyncState().LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 977 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 978 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 979 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 980 | string_VkImageLayout(transition.old_layout), |
| 981 | string_VkImageLayout(transition.new_layout), |
| 982 | cb_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | return skip; |
| 986 | } |
| 987 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 988 | bool AccessContext::ValidateLoadOperation(const CommandBufferAccessContext &cb_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 989 | const VkRect2D &render_area, uint32_t subpass, |
| 990 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 991 | const char *func_name) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 992 | bool skip = false; |
| 993 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 994 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 995 | VkOffset3D offset = CastTo3D(render_area.offset); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 996 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 997 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 998 | if (subpass == rp_state.attachment_first_subpass[i]) { |
| 999 | if (attachment_views[i] == nullptr) continue; |
| 1000 | const IMAGE_VIEW_STATE &view = *attachment_views[i]; |
| 1001 | const IMAGE_STATE *image = view.image_state.get(); |
| 1002 | if (image == nullptr) continue; |
| 1003 | const auto &ci = attachment_ci[i]; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1004 | |
| 1005 | // Need check in the following way |
| 1006 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 1007 | // vs. transition |
| 1008 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 1009 | // for each aspect loaded. |
| 1010 | |
| 1011 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1012 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1013 | const bool is_color = !(has_depth || has_stencil); |
| 1014 | |
| 1015 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1016 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1017 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1018 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1019 | const char *aspect = nullptr; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1020 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1021 | auto hazard_range = view.normalized_subresource_range; |
| 1022 | bool checked_stencil = false; |
| 1023 | if (is_color) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1024 | hazard = DetectHazard(*image, load_index, view.normalized_subresource_range, SyncOrdering::kColorAttachment, offset, |
John Zulauf | 859089b | 2020-10-29 17:37:03 -0600 | [diff] [blame] | 1025 | extent); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1026 | aspect = "color"; |
| 1027 | } else { |
| 1028 | if (has_depth) { |
| 1029 | hazard_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1030 | hazard = DetectHazard(*image, load_index, hazard_range, SyncOrdering::kDepthStencilAttachment, offset, extent); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1031 | aspect = "depth"; |
| 1032 | } |
| 1033 | if (!hazard.hazard && has_stencil) { |
| 1034 | hazard_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1035 | hazard = DetectHazard(*image, stencil_load_index, hazard_range, SyncOrdering::kDepthStencilAttachment, offset, |
| 1036 | extent); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1037 | aspect = "stencil"; |
| 1038 | checked_stencil = true; |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | if (hazard.hazard) { |
| 1043 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1044 | const auto &sync_state = cb_context.GetSyncState(); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1045 | if (hazard.tag == kCurrentCommandTag) { |
| 1046 | // Hazard vs. ILT |
| 1047 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 1048 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1049 | " aspect %s during load with loadOp %s.", |
| 1050 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string); |
| 1051 | } else { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1052 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 1053 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1054 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1055 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1056 | cb_context.FormatUsage(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | return skip; |
| 1062 | } |
| 1063 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1064 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 1065 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 1066 | // store is part of the same Next/End operation. |
| 1067 | // The latter is handled in layout transistion validation directly |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1068 | bool AccessContext::ValidateStoreOperation(const CommandBufferAccessContext &cb_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1069 | const VkRect2D &render_area, uint32_t subpass, |
| 1070 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 1071 | const char *func_name) const { |
| 1072 | bool skip = false; |
| 1073 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 1074 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1075 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 1076 | |
| 1077 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1078 | if (subpass == rp_state.attachment_last_subpass[i]) { |
| 1079 | if (attachment_views[i] == nullptr) continue; |
| 1080 | const IMAGE_VIEW_STATE &view = *attachment_views[i]; |
| 1081 | const IMAGE_STATE *image = view.image_state.get(); |
| 1082 | if (image == nullptr) continue; |
| 1083 | const auto &ci = attachment_ci[i]; |
| 1084 | |
| 1085 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1086 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 1087 | // sake, we treat DONT_CARE as writing. |
| 1088 | const bool has_depth = FormatHasDepth(ci.format); |
| 1089 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1090 | const bool is_color = !(has_depth || has_stencil); |
| 1091 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1092 | if (!has_stencil && !store_op_stores) continue; |
| 1093 | |
| 1094 | HazardResult hazard; |
| 1095 | const char *aspect = nullptr; |
| 1096 | bool checked_stencil = false; |
| 1097 | if (is_color) { |
| 1098 | hazard = DetectHazard(*image, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1099 | view.normalized_subresource_range, SyncOrdering::kRaster, offset, extent); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1100 | aspect = "color"; |
| 1101 | } else { |
| 1102 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1103 | auto hazard_range = view.normalized_subresource_range; |
| 1104 | if (has_depth && store_op_stores) { |
| 1105 | hazard_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 1106 | hazard = DetectHazard(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, hazard_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1107 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1108 | aspect = "depth"; |
| 1109 | } |
| 1110 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
| 1111 | hazard_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 1112 | hazard = DetectHazard(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, hazard_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1113 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1114 | aspect = "stencil"; |
| 1115 | checked_stencil = true; |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | if (hazard.hazard) { |
| 1120 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 1121 | const char *const store_op_string = string_VkAttachmentStoreOp(checked_stencil ? ci.stencilStoreOp : ci.storeOp); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1122 | skip |= cb_context.GetSyncState().LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 1123 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 1124 | " %s aspect during store with %s %s. Access info %s", |
| 1125 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, |
| 1126 | op_type_string, store_op_string, cb_context.FormatUsage(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | return skip; |
| 1131 | } |
| 1132 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1133 | bool AccessContext::ValidateResolveOperations(const CommandBufferAccessContext &cb_context, const RENDER_PASS_STATE &rp_state, |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1134 | const VkRect2D &render_area, |
| 1135 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, const char *func_name, |
| 1136 | uint32_t subpass) const { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1137 | ValidateResolveAction validate_action(rp_state.renderPass, subpass, *this, cb_context, func_name); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1138 | ResolveOperation(validate_action, rp_state, render_area, attachment_views, subpass); |
| 1139 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1140 | } |
| 1141 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1142 | class HazardDetector { |
| 1143 | SyncStageAccessIndex usage_index_; |
| 1144 | |
| 1145 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1146 | 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] | 1147 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1148 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1149 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1150 | explicit HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1151 | }; |
| 1152 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1153 | class HazardDetectorWithOrdering { |
| 1154 | const SyncStageAccessIndex usage_index_; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1155 | const SyncOrdering ordering_rule_; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1156 | |
| 1157 | public: |
| 1158 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1159 | return pos->second.DetectHazard(usage_index_, ordering_rule_); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1160 | } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1161 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1162 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1163 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1164 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, SyncOrdering ordering) : usage_index_(usage), ordering_rule_(ordering) {} |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1165 | }; |
| 1166 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1167 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1168 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1169 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1170 | const auto base_address = ResourceBaseAddress(buffer); |
| 1171 | HazardDetector detector(usage_index); |
| 1172 | return DetectHazard(AccessAddressType::kLinear, detector, (range + base_address), DetectOptions::kDetectAll); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 1173 | } |
| 1174 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1175 | template <typename Detector> |
| 1176 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 1177 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1178 | const VkExtent3D &extent, DetectOptions options) const { |
| 1179 | if (!SimpleBinding(image)) return HazardResult(); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1180 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1181 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1182 | base_address); |
| 1183 | const auto address_type = ImageAddressType(image); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1184 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1185 | HazardResult hazard = DetectHazard(address_type, detector, *range_gen, options); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1186 | if (hazard.hazard) return hazard; |
| 1187 | } |
| 1188 | return HazardResult(); |
| 1189 | } |
| 1190 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1191 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1192 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1193 | const VkExtent3D &extent) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1194 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1195 | subresource.layerCount}; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1196 | return DetectHazard(image, current_usage, subresource_range, offset, extent); |
| 1197 | } |
| 1198 | |
| 1199 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1200 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1201 | const VkExtent3D &extent) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1202 | HazardDetector detector(current_usage); |
| 1203 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
| 1204 | } |
| 1205 | |
| 1206 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1207 | const VkImageSubresourceRange &subresource_range, SyncOrdering ordering_rule, |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1208 | const VkOffset3D &offset, const VkExtent3D &extent) const { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1209 | HazardDetectorWithOrdering detector(current_usage, ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1210 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1211 | } |
| 1212 | |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1213 | // Some common code for looking at attachments, if there's anything wrong, we return no hazard, core validation |
| 1214 | // should have reported the issue regarding an invalid attachment entry |
| 1215 | HazardResult AccessContext::DetectHazard(const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1216 | SyncOrdering ordering_rule, const VkOffset3D &offset, const VkExtent3D &extent, |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1217 | VkImageAspectFlags aspect_mask) const { |
| 1218 | if (view != nullptr) { |
| 1219 | const IMAGE_STATE *image = view->image_state.get(); |
| 1220 | if (image != nullptr) { |
| 1221 | auto *detect_range = &view->normalized_subresource_range; |
| 1222 | VkImageSubresourceRange masked_range; |
| 1223 | if (aspect_mask) { // If present and non-zero, restrict the normalized range to aspects present in aspect_mask |
| 1224 | masked_range = view->normalized_subresource_range; |
| 1225 | masked_range.aspectMask = aspect_mask & masked_range.aspectMask; |
| 1226 | detect_range = &masked_range; |
| 1227 | } |
| 1228 | |
| 1229 | // NOTE: The range encoding code is not robust to invalid ranges, so we protect it from our change |
| 1230 | if (detect_range->aspectMask) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1231 | return DetectHazard(*image, current_usage, *detect_range, ordering_rule, offset, extent); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | return HazardResult(); |
| 1236 | } |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1237 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1238 | class BarrierHazardDetector { |
| 1239 | public: |
| 1240 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags src_exec_scope, |
| 1241 | SyncStageAccessFlags src_access_scope) |
| 1242 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1243 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1244 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1245 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1246 | } |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 1247 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1248 | // 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] | 1249 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | private: |
| 1253 | SyncStageAccessIndex usage_index_; |
| 1254 | VkPipelineStageFlags src_exec_scope_; |
| 1255 | SyncStageAccessFlags src_access_scope_; |
| 1256 | }; |
| 1257 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1258 | class EventBarrierHazardDetector { |
| 1259 | public: |
| 1260 | EventBarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags src_exec_scope, |
| 1261 | SyncStageAccessFlags src_access_scope, const SyncEventState::ScopeMap &event_scope, |
| 1262 | const ResourceUsageTag &scope_tag) |
| 1263 | : usage_index_(usage_index), |
| 1264 | src_exec_scope_(src_exec_scope), |
| 1265 | src_access_scope_(src_access_scope), |
| 1266 | event_scope_(event_scope), |
| 1267 | scope_pos_(event_scope.cbegin()), |
| 1268 | scope_end_(event_scope.cend()), |
| 1269 | scope_tag_(scope_tag) {} |
| 1270 | |
| 1271 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1272 | // TODO NOTE: This is almost the slowest way to do this... need to intelligently walk this... |
| 1273 | // Need to find a more efficient sync, since we know pos->first is strictly increasing call to call |
| 1274 | // NOTE: "cached_lower_bound_impl" with upgrades could do this. |
| 1275 | if (scope_pos_ == scope_end_) return HazardResult(); |
| 1276 | if (!scope_pos_->first.intersects(pos->first)) { |
| 1277 | event_scope_.lower_bound(pos->first); |
| 1278 | if ((scope_pos_ == scope_end_) || !scope_pos_->first.intersects(pos->first)) return HazardResult(); |
| 1279 | } |
| 1280 | |
| 1281 | // Some portion of this pos is in the event_scope, so check for a barrier hazard |
| 1282 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_, scope_tag_); |
| 1283 | } |
| 1284 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos, const ResourceUsageTag &start_tag) const { |
| 1285 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1286 | return pos->second.DetectAsyncHazard(usage_index_, start_tag); |
| 1287 | } |
| 1288 | |
| 1289 | private: |
| 1290 | SyncStageAccessIndex usage_index_; |
| 1291 | VkPipelineStageFlags src_exec_scope_; |
| 1292 | SyncStageAccessFlags src_access_scope_; |
| 1293 | const SyncEventState::ScopeMap &event_scope_; |
| 1294 | SyncEventState::ScopeMap::const_iterator scope_pos_; |
| 1295 | SyncEventState::ScopeMap::const_iterator scope_end_; |
| 1296 | const ResourceUsageTag &scope_tag_; |
| 1297 | }; |
| 1298 | |
| 1299 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags src_exec_scope, |
| 1300 | const SyncStageAccessFlags &src_access_scope, |
| 1301 | const VkImageSubresourceRange &subresource_range, |
| 1302 | const SyncEventState &sync_event, DetectOptions options) const { |
| 1303 | // It's not particularly DRY to get the address type in this function as well as lower down, but we have to select the |
| 1304 | // first access scope map to use, and there's no easy way to plumb it in below. |
| 1305 | const auto address_type = ImageAddressType(image); |
| 1306 | const auto &event_scope = sync_event.FirstScope(address_type); |
| 1307 | |
| 1308 | EventBarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope, |
| 1309 | event_scope, sync_event.first_scope_tag); |
| 1310 | VkOffset3D zero_offset = {0, 0, 0}; |
| 1311 | return DetectHazard(detector, image, subresource_range, zero_offset, image.createInfo.extent, options); |
| 1312 | } |
| 1313 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1314 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1315 | const SyncStageAccessFlags &src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1316 | const VkImageSubresourceRange &subresource_range, |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1317 | const DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1318 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope); |
| 1319 | VkOffset3D zero_offset = {0, 0, 0}; |
| 1320 | return DetectHazard(detector, image, subresource_range, zero_offset, image.createInfo.extent, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1323 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 1324 | const SyncStageAccessFlags &src_stage_accesses, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1325 | const VkImageMemoryBarrier &barrier) const { |
| 1326 | auto subresource_range = NormalizeSubresourceRange(image.createInfo, barrier.subresourceRange); |
| 1327 | const auto src_access_scope = SyncStageAccess::AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 1328 | return DetectImageBarrierHazard(image, src_exec_scope, src_access_scope, subresource_range, kDetectAll); |
| 1329 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1330 | HazardResult AccessContext::DetectImageBarrierHazard(const SyncImageMemoryBarrier &image_barrier) const { |
| 1331 | return DetectImageBarrierHazard(*image_barrier.image.get(), image_barrier.barrier.src_exec_scope, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1332 | image_barrier.barrier.src_access_scope, image_barrier.range.subresource_range, kDetectAll); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 1333 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1334 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1335 | template <typename Flags, typename Map> |
| 1336 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1337 | SyncStageAccessFlags scope = 0; |
| 1338 | for (const auto &bit_scope : map) { |
| 1339 | if (flag_mask < bit_scope.first) break; |
| 1340 | |
| 1341 | if (flag_mask & bit_scope.first) { |
| 1342 | scope |= bit_scope.second; |
| 1343 | } |
| 1344 | } |
| 1345 | return scope; |
| 1346 | } |
| 1347 | |
| 1348 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags stages) { |
| 1349 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1350 | } |
| 1351 | |
| 1352 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags accesses) { |
| 1353 | return AccessScopeImpl(accesses, syncStageAccessMaskByAccessBit); |
| 1354 | } |
| 1355 | |
| 1356 | // Getting from stage mask and access mask to stage/acess masks is something we need to be good at... |
| 1357 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags stages, VkAccessFlags accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1358 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1359 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1360 | // 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] | 1361 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1362 | } |
| 1363 | |
| 1364 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1365 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1366 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1367 | // that do incrementalupdates |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1368 | assert(accesses); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1369 | auto pos = accesses->lower_bound(range); |
| 1370 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1371 | // The range is empty, fill it with a default value. |
| 1372 | pos = action.Infill(accesses, pos, range); |
| 1373 | } else if (range.begin < pos->first.begin) { |
| 1374 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1375 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1376 | } else if (pos->first.begin < range.begin) { |
| 1377 | // Trim the beginning if needed |
| 1378 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1379 | ++pos; |
| 1380 | } |
| 1381 | |
| 1382 | const auto the_end = accesses->end(); |
| 1383 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1384 | if (pos->first.end > range.end) { |
| 1385 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1386 | } |
| 1387 | |
| 1388 | pos = action(accesses, pos); |
| 1389 | if (pos == the_end) break; |
| 1390 | |
| 1391 | auto next = pos; |
| 1392 | ++next; |
| 1393 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1394 | // Need to infill if next is disjoint |
| 1395 | 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] | 1396 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1397 | next = action.Infill(accesses, next, new_range); |
| 1398 | } |
| 1399 | pos = next; |
| 1400 | } |
| 1401 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1402 | |
| 1403 | // Give a comparable interface for range generators and ranges |
| 1404 | template <typename Action> |
| 1405 | inline void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, ResourceAccessRange *range) { |
| 1406 | assert(range); |
| 1407 | UpdateMemoryAccessState(accesses, *range, action); |
| 1408 | } |
| 1409 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1410 | template <typename Action, typename RangeGen> |
| 1411 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const Action &action, RangeGen *range_gen_arg) { |
| 1412 | assert(range_gen_arg); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1413 | 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] | 1414 | for (; range_gen->non_empty(); ++range_gen) { |
| 1415 | UpdateMemoryAccessState(accesses, *range_gen, action); |
| 1416 | } |
| 1417 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1418 | |
| 1419 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1420 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1421 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1422 | // this is only called on gaps, and never returns a gap. |
| 1423 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1424 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1425 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1426 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1427 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1428 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1429 | auto &access_state = pos->second; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1430 | access_state.Update(usage, ordering_rule, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1431 | return pos; |
| 1432 | } |
| 1433 | |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1434 | UpdateMemoryAccessStateFunctor(AccessAddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1435 | SyncOrdering ordering_rule_, const ResourceUsageTag &tag_) |
| 1436 | : type(type_), context(context_), usage(usage_), ordering_rule(ordering_rule_), tag(tag_) {} |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1437 | const AccessAddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1438 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1439 | const SyncStageAccessIndex usage; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1440 | const SyncOrdering ordering_rule; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1441 | const ResourceUsageTag &tag; |
| 1442 | }; |
| 1443 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1444 | // The barrier operation for pipeline and subpass dependencies` |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1445 | struct PipelineBarrierOp { |
| 1446 | SyncBarrier barrier; |
| 1447 | bool layout_transition; |
| 1448 | PipelineBarrierOp(const SyncBarrier &barrier_, bool layout_transition_) |
| 1449 | : barrier(barrier_), layout_transition(layout_transition_) {} |
| 1450 | PipelineBarrierOp() = default; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1451 | PipelineBarrierOp(const PipelineBarrierOp &) = default; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1452 | void operator()(ResourceAccessState *access_state) const { access_state->ApplyBarrier(barrier, layout_transition); } |
| 1453 | }; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1454 | // The barrier operation for wait events |
| 1455 | struct WaitEventBarrierOp { |
| 1456 | const ResourceUsageTag *scope_tag; |
| 1457 | SyncBarrier barrier; |
| 1458 | bool layout_transition; |
| 1459 | WaitEventBarrierOp(const ResourceUsageTag &scope_tag_, const SyncBarrier &barrier_, bool layout_transition_) |
| 1460 | : scope_tag(&scope_tag_), barrier(barrier_), layout_transition(layout_transition_) {} |
| 1461 | WaitEventBarrierOp() = default; |
| 1462 | void operator()(ResourceAccessState *access_state) const { |
| 1463 | assert(scope_tag); // Not valid to have a non-scope op executed, default construct included for std::vector support |
| 1464 | access_state->ApplyBarrier(*scope_tag, barrier, layout_transition); |
| 1465 | } |
| 1466 | }; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1467 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1468 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1469 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1470 | // of a collection is known/present. |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1471 | template <typename BarrierOp> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1472 | class ApplyBarrierOpsFunctor { |
| 1473 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1474 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1475 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1476 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1477 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1478 | auto &access_state = pos->second; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1479 | for (const auto &op : barrier_ops_) { |
| 1480 | op(&access_state); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1481 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1482 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1483 | if (resolve_) { |
| 1484 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1485 | // another walk |
| 1486 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1487 | } |
| 1488 | return pos; |
| 1489 | } |
| 1490 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1491 | // 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] | 1492 | ApplyBarrierOpsFunctor(bool resolve, size_t size_hint, const ResourceUsageTag &tag) |
| 1493 | : resolve_(resolve), barrier_ops_(), tag_(tag) { |
| 1494 | barrier_ops_.reserve(size_hint); |
| 1495 | } |
| 1496 | void EmplaceBack(const BarrierOp &op) { barrier_ops_.emplace_back(op); } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1497 | |
| 1498 | private: |
| 1499 | bool resolve_; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1500 | std::vector<BarrierOp> barrier_ops_; |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1501 | const ResourceUsageTag &tag_; |
| 1502 | }; |
| 1503 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1504 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1505 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1506 | template <typename BarrierOp> |
| 1507 | class ApplyBarrierFunctor { |
| 1508 | public: |
| 1509 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1510 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
| 1511 | |
| 1512 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
| 1513 | auto &access_state = pos->second; |
| 1514 | barrier_op_(&access_state); |
| 1515 | return pos; |
| 1516 | } |
| 1517 | |
| 1518 | ApplyBarrierFunctor(const BarrierOp &barrier_op) : barrier_op_(barrier_op) {} |
| 1519 | |
| 1520 | private: |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1521 | BarrierOp barrier_op_; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 1522 | }; |
| 1523 | |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 1524 | // This functor resolves the pendinging state. |
| 1525 | class ResolvePendingBarrierFunctor { |
| 1526 | public: |
| 1527 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1528 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
| 1529 | |
| 1530 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
| 1531 | auto &access_state = pos->second; |
| 1532 | access_state.ApplyPendingBarriers(tag_); |
| 1533 | return pos; |
| 1534 | } |
| 1535 | |
| 1536 | ResolvePendingBarrierFunctor(const ResourceUsageTag &tag) : tag_(tag) {} |
| 1537 | |
| 1538 | private: |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1539 | const ResourceUsageTag &tag_; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1540 | }; |
| 1541 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1542 | void AccessContext::UpdateAccessState(AccessAddressType type, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
| 1543 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
| 1544 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1545 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1546 | } |
| 1547 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1548 | 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] | 1549 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1550 | if (!SimpleBinding(buffer)) return; |
| 1551 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1552 | UpdateAccessState(AccessAddressType::kLinear, current_usage, ordering_rule, range + base_address, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1553 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1554 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1555 | 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] | 1556 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1557 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1558 | if (!SimpleBinding(image)) return; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1559 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1560 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent, |
| 1561 | base_address); |
| 1562 | const auto address_type = ImageAddressType(image); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1563 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, ordering_rule, tag); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1564 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1565 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), *range_gen, action); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1566 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1567 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1568 | void AccessContext::UpdateAccessState(const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, SyncOrdering ordering_rule, |
| 1569 | const VkOffset3D &offset, const VkExtent3D &extent, VkImageAspectFlags aspect_mask, |
| 1570 | const ResourceUsageTag &tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1571 | if (view != nullptr) { |
| 1572 | const IMAGE_STATE *image = view->image_state.get(); |
| 1573 | if (image != nullptr) { |
| 1574 | auto *update_range = &view->normalized_subresource_range; |
| 1575 | VkImageSubresourceRange masked_range; |
| 1576 | if (aspect_mask) { // If present and non-zero, restrict the normalized range to aspects present in aspect_mask |
| 1577 | masked_range = view->normalized_subresource_range; |
| 1578 | masked_range.aspectMask = aspect_mask & masked_range.aspectMask; |
| 1579 | update_range = &masked_range; |
| 1580 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1581 | UpdateAccessState(*image, current_usage, ordering_rule, *update_range, offset, extent, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1585 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1586 | 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] | 1587 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1588 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1589 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1590 | subresource.layerCount}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1591 | UpdateAccessState(image, current_usage, ordering_rule, subresource_range, offset, extent, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1592 | } |
| 1593 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1594 | template <typename Action> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1595 | void AccessContext::UpdateResourceAccess(const BUFFER_STATE &buffer, const ResourceAccessRange &range, const Action action) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1596 | if (!SimpleBinding(buffer)) return; |
| 1597 | const auto base_address = ResourceBaseAddress(buffer); |
John Zulauf | 43cc746 | 2020-12-03 12:33:12 -0700 | [diff] [blame] | 1598 | UpdateMemoryAccessState(&GetAccessStateMap(AccessAddressType::kLinear), (range + base_address), action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | template <typename Action> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1602 | void AccessContext::UpdateResourceAccess(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range, |
| 1603 | const Action action) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1604 | if (!SimpleBinding(image)) return; |
| 1605 | const auto address_type = ImageAddressType(image); |
| 1606 | auto *accesses = &GetAccessStateMap(address_type); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1607 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1608 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1609 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
| 1610 | image.createInfo.extent, base_address); |
| 1611 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1612 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 150e533 | 2020-12-03 08:52:52 -0700 | [diff] [blame] | 1613 | UpdateMemoryAccessState(accesses, *range_gen, action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1614 | } |
| 1615 | } |
| 1616 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1617 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 1618 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass, |
| 1619 | const ResourceUsageTag &tag) { |
| 1620 | UpdateStateResolveAction update(*this, tag); |
| 1621 | ResolveOperation(update, rp_state, render_area, attachment_views, subpass); |
| 1622 | } |
| 1623 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1624 | void AccessContext::UpdateAttachmentStoreAccess(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 1625 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass, |
| 1626 | const ResourceUsageTag &tag) { |
| 1627 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 1628 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1629 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 1630 | |
| 1631 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1632 | if (rp_state.attachment_last_subpass[i] == subpass) { |
| 1633 | if (attachment_views[i] == nullptr) continue; // UNUSED |
| 1634 | const auto &view = *attachment_views[i]; |
| 1635 | const IMAGE_STATE *image = view.image_state.get(); |
| 1636 | if (image == nullptr) continue; |
| 1637 | |
| 1638 | const auto &ci = attachment_ci[i]; |
| 1639 | const bool has_depth = FormatHasDepth(ci.format); |
| 1640 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1641 | const bool is_color = !(has_depth || has_stencil); |
| 1642 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1643 | |
| 1644 | if (is_color && store_op_stores) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1645 | UpdateAccessState(*image, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, SyncOrdering::kRaster, |
| 1646 | view.normalized_subresource_range, offset, extent, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1647 | } else { |
| 1648 | auto update_range = view.normalized_subresource_range; |
| 1649 | if (has_depth && store_op_stores) { |
| 1650 | update_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1651 | UpdateAccessState(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, |
| 1652 | update_range, offset, extent, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1653 | } |
| 1654 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1655 | if (has_stencil && stencil_op_stores) { |
| 1656 | update_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1657 | UpdateAccessState(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, SyncOrdering::kRaster, |
| 1658 | update_range, offset, extent, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1659 | } |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | } |
| 1664 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1665 | template <typename Action> |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 1666 | void AccessContext::ApplyToContext(const Action &barrier_action) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1667 | // 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] | 1668 | for (const auto address_type : kAddressTypes) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1669 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), kFullRange, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1674 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1675 | auto &context = contexts[subpass_index]; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1676 | ApplyTrackbackBarriersAction barrier_action(context.GetDstExternalTrackBack().barriers); |
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 | context.ResolveAccessRange(address_type, kFullRange, barrier_action, &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1683 | // Suitable only for *subpass* access contexts |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1684 | HazardResult AccessContext::DetectSubpassTransitionHazard(const TrackBack &track_back, const IMAGE_VIEW_STATE *attach_view) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1685 | if (!attach_view) return HazardResult(); |
| 1686 | const auto image_state = attach_view->image_state.get(); |
| 1687 | if (!image_state) return HazardResult(); |
| 1688 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1689 | // 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] | 1690 | assert(track_back.context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1691 | |
| 1692 | // 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] | 1693 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1694 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
| 1695 | HazardResult hazard = |
| 1696 | track_back.context->DetectImageBarrierHazard(*image_state, merged_barrier.src_exec_scope, merged_barrier.src_access_scope, |
| 1697 | attach_view->normalized_subresource_range, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1698 | if (!hazard.hazard) { |
| 1699 | // The Async hazard check is against the current context's async set. |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1700 | hazard = DetectImageBarrierHazard(*image_state, merged_barrier.src_exec_scope, merged_barrier.src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1701 | attach_view->normalized_subresource_range, kDetectAsync); |
| 1702 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1703 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1704 | return hazard; |
| 1705 | } |
| 1706 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1707 | void AccessContext::RecordLayoutTransitions(const RENDER_PASS_STATE &rp_state, uint32_t subpass, |
| 1708 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 1709 | const ResourceUsageTag &tag) { |
| 1710 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1711 | const ResourceAccessState empty_infill; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 1712 | for (const auto &transition : transitions) { |
| 1713 | const auto prev_pass = transition.prev_pass; |
| 1714 | const auto attachment_view = attachment_views[transition.attachment]; |
| 1715 | if (!attachment_view) continue; |
| 1716 | const auto *image = attachment_view->image_state.get(); |
| 1717 | if (!image) continue; |
| 1718 | if (!SimpleBinding(*image)) continue; |
| 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); |
| 1726 | const auto address_type = ImageAddressType(*image); |
| 1727 | auto &target_map = GetAccessStateMap(address_type); |
| 1728 | ApplySubpassTransitionBarriersAction barrier_action(trackback->barriers); |
| 1729 | prev_context->ResolveAccessRange(*image, attachment_view->normalized_subresource_range, barrier_action, address_type, |
John Zulauf | 646cc29 | 2020-10-23 09:16:45 -0600 | [diff] [blame] | 1730 | &target_map, &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 | // Class CommandBufferAccessContext: Keep track of resource access state information for a specific command buffer |
| 1757 | bool CommandBufferAccessContext::ValidateBeginRenderPass(const RENDER_PASS_STATE &rp_state, |
| 1758 | |
| 1759 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1760 | const VkSubpassBeginInfo *pSubpassBeginInfo, const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1761 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 1762 | bool skip = false; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1763 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1764 | assert(pRenderPassBegin); |
| 1765 | if (nullptr == pRenderPassBegin) return skip; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1766 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1767 | const uint32_t subpass = 0; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1768 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1769 | // Construct the state we can use to validate against... (since validation is const and RecordCmdBeginRenderPass |
| 1770 | // hasn't happened yet) |
| 1771 | const std::vector<AccessContext> empty_context_vector; |
| 1772 | AccessContext temp_context(subpass, queue_flags_, rp_state.subpass_dependencies, empty_context_vector, |
| 1773 | const_cast<AccessContext *>(&cb_access_context_)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1774 | |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1775 | // Create a view list |
| 1776 | const auto fb_state = sync_state_->Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
| 1777 | assert(fb_state); |
| 1778 | if (nullptr == fb_state) return skip; |
| 1779 | // NOTE: Must not use COMMAND_BUFFER_STATE variant of this as RecordCmdBeginRenderPass hasn't run and thus |
| 1780 | // the activeRenderPass.* fields haven't been set. |
| 1781 | const auto views = sync_state_->GetAttachmentViews(*pRenderPassBegin, *fb_state); |
| 1782 | |
| 1783 | // Validate transitions |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1784 | skip |= temp_context.ValidateLayoutTransitions(*this, rp_state, pRenderPassBegin->renderArea, subpass, views, func_name); |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1785 | |
| 1786 | // Validate load operations if there were no layout transition hazards |
| 1787 | if (!skip) { |
| 1788 | temp_context.RecordLayoutTransitions(rp_state, subpass, views, kCurrentCommandTag); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1789 | skip |= temp_context.ValidateLoadOperation(*this, rp_state, pRenderPassBegin->renderArea, subpass, views, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1790 | } |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 1791 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1792 | return skip; |
| 1793 | } |
| 1794 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1795 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1796 | const char *func_name) const { |
| 1797 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1798 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1799 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1800 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pipe, &per_sets); |
| 1801 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1802 | return skip; |
| 1803 | } |
| 1804 | |
| 1805 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1806 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1807 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1808 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1809 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1810 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1811 | for (const auto &stage_state : pipe->stage_state) { |
| 1812 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->graphicsPipelineCI.pRasterizationState && |
| 1813 | pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1814 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1815 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1816 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1817 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1818 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1819 | set_binding.first.second); |
| 1820 | const auto descriptor_type = binding_it.GetType(); |
| 1821 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1822 | auto array_idx = 0; |
| 1823 | |
| 1824 | if (binding_it.IsVariableDescriptorCount()) { |
| 1825 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1826 | } |
| 1827 | SyncStageAccessIndex sync_index = |
| 1828 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1829 | |
| 1830 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1831 | uint32_t index = i - index_range.start; |
| 1832 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1833 | switch (descriptor->GetClass()) { |
| 1834 | case DescriptorClass::ImageSampler: |
| 1835 | case DescriptorClass::Image: { |
| 1836 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1837 | VkImageLayout image_layout; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1838 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1839 | const auto image_sampler_descriptor = static_cast<const ImageSamplerDescriptor *>(descriptor); |
| 1840 | img_view_state = image_sampler_descriptor->GetImageViewState(); |
| 1841 | image_layout = image_sampler_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1842 | } else { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1843 | const auto image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 1844 | img_view_state = image_descriptor->GetImageViewState(); |
| 1845 | image_layout = image_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1846 | } |
| 1847 | if (!img_view_state) continue; |
| 1848 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
| 1849 | VkExtent3D extent = {}; |
| 1850 | VkOffset3D offset = {}; |
| 1851 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1852 | extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1853 | offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1854 | } else { |
| 1855 | extent = img_state->createInfo.extent; |
| 1856 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1857 | HazardResult hazard; |
| 1858 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
| 1859 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 1860 | // Input attachments are subject to raster ordering rules |
| 1861 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1862 | SyncOrdering::kRaster, offset, extent); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1863 | } else { |
| 1864 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, offset, extent); |
| 1865 | } |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1866 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1867 | skip |= sync_state_->LogError( |
| 1868 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1869 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 1870 | ", index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1871 | func_name, string_SyncHazard(hazard.hazard), |
| 1872 | sync_state_->report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1873 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1874 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1875 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1876 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1877 | set_binding.first.second, index, FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1878 | } |
| 1879 | break; |
| 1880 | } |
| 1881 | case DescriptorClass::TexelBuffer: { |
| 1882 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1883 | if (!buf_view_state) continue; |
| 1884 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1885 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1886 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1887 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1888 | skip |= sync_state_->LogError( |
| 1889 | buf_view_state->buffer_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1890 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1891 | func_name, string_SyncHazard(hazard.hazard), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1892 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view).c_str(), |
| 1893 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1894 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1895 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1896 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1897 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1898 | } |
| 1899 | break; |
| 1900 | } |
| 1901 | case DescriptorClass::GeneralBuffer: { |
| 1902 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1903 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1904 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1905 | const ResourceAccessRange range = |
| 1906 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1907 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 1908 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1909 | skip |= sync_state_->LogError( |
| 1910 | buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1911 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1912 | func_name, string_SyncHazard(hazard.hazard), |
| 1913 | sync_state_->report_data->FormatHandle(buf_state->buffer).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1914 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1915 | sync_state_->report_data->FormatHandle(pipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1916 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1917 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 1918 | FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1919 | } |
| 1920 | break; |
| 1921 | } |
| 1922 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1923 | default: |
| 1924 | break; |
| 1925 | } |
| 1926 | } |
| 1927 | } |
| 1928 | } |
| 1929 | return skip; |
| 1930 | } |
| 1931 | |
| 1932 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1933 | const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1934 | const PIPELINE_STATE *pipe = nullptr; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1935 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1936 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pipe, &per_sets); |
| 1937 | if (!pipe || !per_sets) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1938 | return; |
| 1939 | } |
| 1940 | |
| 1941 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1942 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1943 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1944 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1945 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1946 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1947 | for (const auto &stage_state : pipe->stage_state) { |
| 1948 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pipe->graphicsPipelineCI.pRasterizationState && |
| 1949 | pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1950 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1951 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1952 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1953 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1954 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1955 | set_binding.first.second); |
| 1956 | const auto descriptor_type = binding_it.GetType(); |
| 1957 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1958 | auto array_idx = 0; |
| 1959 | |
| 1960 | if (binding_it.IsVariableDescriptorCount()) { |
| 1961 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1962 | } |
| 1963 | SyncStageAccessIndex sync_index = |
| 1964 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1965 | |
| 1966 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1967 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1968 | switch (descriptor->GetClass()) { |
| 1969 | case DescriptorClass::ImageSampler: |
| 1970 | case DescriptorClass::Image: { |
| 1971 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
| 1972 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
| 1973 | img_view_state = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetImageViewState(); |
| 1974 | } else { |
| 1975 | img_view_state = static_cast<const ImageDescriptor *>(descriptor)->GetImageViewState(); |
| 1976 | } |
| 1977 | if (!img_view_state) continue; |
| 1978 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
| 1979 | VkExtent3D extent = {}; |
| 1980 | VkOffset3D offset = {}; |
| 1981 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1982 | extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1983 | offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1984 | } else { |
| 1985 | extent = img_state->createInfo.extent; |
| 1986 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1987 | SyncOrdering ordering_rule = (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) |
| 1988 | ? SyncOrdering::kRaster |
| 1989 | : SyncOrdering::kNonAttachment; |
| 1990 | current_context_->UpdateAccessState(*img_state, sync_index, ordering_rule, |
| 1991 | img_view_state->normalized_subresource_range, offset, extent, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1992 | break; |
| 1993 | } |
| 1994 | case DescriptorClass::TexelBuffer: { |
| 1995 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1996 | if (!buf_view_state) continue; |
| 1997 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1998 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 1999 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2000 | break; |
| 2001 | } |
| 2002 | case DescriptorClass::GeneralBuffer: { |
| 2003 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 2004 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 2005 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2006 | const ResourceAccessRange range = |
| 2007 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2008 | current_context_->UpdateAccessState(*buf_state, sync_index, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2009 | break; |
| 2010 | } |
| 2011 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 2012 | default: |
| 2013 | break; |
| 2014 | } |
| 2015 | } |
| 2016 | } |
| 2017 | } |
| 2018 | } |
| 2019 | |
| 2020 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const char *func_name) const { |
| 2021 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2022 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2023 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2024 | return skip; |
| 2025 | } |
| 2026 | |
| 2027 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2028 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2029 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2030 | |
| 2031 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2032 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2033 | if (binding_description.binding < binding_buffers_size) { |
| 2034 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2035 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->destroyed) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2036 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2037 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2038 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2039 | vertexCount, binding_description.stride); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2040 | auto hazard = current_context_->DetectHazard(*buf_state, SYNC_VERTEX_INPUT_VERTEX_ATTRIBUTE_READ, range); |
| 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 | 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] | 2044 | 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] | 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 | } |
| 2049 | return skip; |
| 2050 | } |
| 2051 | |
| 2052 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2053 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2054 | if (!pipe) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2055 | return; |
| 2056 | } |
| 2057 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 2058 | const auto &binding_buffers_size = binding_buffers.size(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2059 | const auto &binding_descriptions_size = pipe->vertex_binding_descriptions_.size(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2060 | |
| 2061 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2062 | const auto &binding_description = pipe->vertex_binding_descriptions_[i]; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2063 | if (binding_description.binding < binding_buffers_size) { |
| 2064 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2065 | if (binding_buffer.buffer_state == nullptr || binding_buffer.buffer_state->destroyed) continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2066 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2067 | auto *buf_state = binding_buffer.buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2068 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 2069 | vertexCount, binding_description.stride); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2070 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_INPUT_VERTEX_ATTRIBUTE_READ, SyncOrdering::kNonAttachment, |
| 2071 | range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2072 | } |
| 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const char *func_name) const { |
| 2077 | bool skip = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2078 | 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] | 2079 | return skip; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2080 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2081 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2082 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2083 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2084 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2085 | firstIndex, indexCount, index_size); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2086 | auto hazard = current_context_->DetectHazard(*index_buf_state, SYNC_VERTEX_INPUT_INDEX_READ, range); |
| 2087 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2088 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2089 | 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] | 2090 | 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] | 2091 | 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] | 2092 | } |
| 2093 | |
| 2094 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2095 | // We will detect more accurate range in the future. |
| 2096 | skip |= ValidateDrawVertex(UINT32_MAX, 0, func_name); |
| 2097 | return skip; |
| 2098 | } |
| 2099 | |
| 2100 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag &tag) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2101 | 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] | 2102 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 2103 | auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2104 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2105 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 2106 | firstIndex, indexCount, index_size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2107 | current_context_->UpdateAccessState(*index_buf_state, SYNC_VERTEX_INPUT_INDEX_READ, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2108 | |
| 2109 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 2110 | // We will detect more accurate range in the future. |
| 2111 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 2112 | } |
| 2113 | |
| 2114 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(const char *func_name) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2115 | bool skip = false; |
| 2116 | if (!current_renderpass_context_) return skip; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2117 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(*this, *cb_state_.get(), |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2118 | cb_state_->activeRenderPassBeginInfo.renderArea, func_name); |
| 2119 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2123 | if (current_renderpass_context_) { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2124 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), cb_state_->activeRenderPassBeginInfo.renderArea, |
| 2125 | tag); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2126 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2127 | } |
| 2128 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2129 | bool CommandBufferAccessContext::ValidateNextSubpass(const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2130 | bool skip = false; |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2131 | if (!current_renderpass_context_) return skip; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2132 | skip |= current_renderpass_context_->ValidateNextSubpass(*this, cb_state_->activeRenderPassBeginInfo.renderArea, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2133 | |
| 2134 | return skip; |
| 2135 | } |
| 2136 | |
| 2137 | bool CommandBufferAccessContext::ValidateEndRenderpass(const char *func_name) const { |
| 2138 | // TODO: Things to add here. |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2139 | // Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2140 | bool skip = false; |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 2141 | if (!current_renderpass_context_) return skip; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2142 | skip |= current_renderpass_context_->ValidateEndRenderPass(*this, cb_state_->activeRenderPassBeginInfo.renderArea, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2143 | |
| 2144 | return skip; |
| 2145 | } |
| 2146 | |
| 2147 | void CommandBufferAccessContext::RecordBeginRenderPass(const ResourceUsageTag &tag) { |
| 2148 | assert(sync_state_); |
| 2149 | if (!cb_state_) return; |
| 2150 | |
| 2151 | // Create an access context the current renderpass. |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2152 | render_pass_contexts_.emplace_back(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2153 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2154 | current_renderpass_context_->RecordBeginRenderPass(*sync_state_, *cb_state_, &cb_access_context_, queue_flags_, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2155 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2156 | } |
| 2157 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2158 | void CommandBufferAccessContext::RecordNextSubpass(const RENDER_PASS_STATE &rp_state, CMD_TYPE command) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2159 | assert(current_renderpass_context_); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2160 | auto prev_tag = NextCommandTag(command); |
| 2161 | auto next_tag = NextSubcommandTag(command); |
| 2162 | current_renderpass_context_->RecordNextSubpass(cb_state_->activeRenderPassBeginInfo.renderArea, prev_tag, next_tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2163 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
| 2164 | } |
| 2165 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2166 | void CommandBufferAccessContext::RecordEndRenderPass(const RENDER_PASS_STATE &render_pass, CMD_TYPE command) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2167 | assert(current_renderpass_context_); |
| 2168 | if (!current_renderpass_context_) return; |
| 2169 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2170 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, cb_state_->activeRenderPassBeginInfo.renderArea, |
| 2171 | NextCommandTag(command)); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2172 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2173 | current_renderpass_context_ = nullptr; |
| 2174 | } |
| 2175 | |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 2176 | bool CommandBufferAccessContext::ValidateSetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 2177 | VkPipelineStageFlags stageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2178 | // I'll put this here just in case we need to pass this in for future extension support |
| 2179 | const auto cmd = CMD_SETEVENT; |
| 2180 | bool skip = false; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2181 | const auto *event_state = sync_state_->Get<EVENT_STATE>(event); |
| 2182 | if (!event_state) return skip; |
| 2183 | |
| 2184 | const auto *sync_event = GetCurrentEventsContext()->Get(event_state); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2185 | if (!sync_event) return false; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 2186 | |
| 2187 | const char *const reset_set = |
| 2188 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 2189 | "hazards."; |
| 2190 | const char *const wait = |
| 2191 | "%s: %s %s operation following %s without intervening vkCmdResetEvent, may result in data hazard and is ignored."; |
| 2192 | |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2193 | const auto exec_scope = sync_utils::WithEarlierPipelineStages(sync_utils::ExpandPipelineStages(stageMask, GetQueueFlags())); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2194 | if (!sync_event->HasBarrier(stageMask, exec_scope)) { |
| 2195 | const char *vuid = nullptr; |
| 2196 | const char *message = nullptr; |
| 2197 | switch (sync_event->last_command) { |
| 2198 | case CMD_RESETEVENT: |
| 2199 | // Needs a barrier between reset and set |
| 2200 | vuid = "SYNC-vkCmdSetEvent-missingbarrier-reset"; |
| 2201 | message = reset_set; |
| 2202 | break; |
| 2203 | case CMD_SETEVENT: |
| 2204 | // Needs a barrier between set and set |
| 2205 | vuid = "SYNC-vkCmdSetEvent-missingbarrier-set"; |
| 2206 | message = reset_set; |
| 2207 | break; |
| 2208 | case CMD_WAITEVENTS: |
| 2209 | // Needs a barrier or is in second execution scope |
| 2210 | vuid = "SYNC-vkCmdSetEvent-missingbarrier-wait"; |
| 2211 | message = wait; |
| 2212 | break; |
| 2213 | default: |
| 2214 | // The only other valid last command that wasn't one. |
| 2215 | assert(sync_event->last_command == CMD_NONE); |
| 2216 | break; |
| 2217 | } |
| 2218 | if (vuid) { |
| 2219 | assert(nullptr != message); |
| 2220 | const char *const cmd_name = CommandTypeString(cmd); |
| 2221 | skip |= sync_state_->LogError(event, vuid, message, cmd_name, sync_state_->report_data->FormatHandle(event).c_str(), |
| 2222 | cmd_name, CommandTypeString(sync_event->last_command)); |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | return skip; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 2227 | } |
| 2228 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2229 | void CommandBufferAccessContext::RecordSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask, |
| 2230 | const ResourceUsageTag &tag) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2231 | auto event_state_shared = sync_state_->GetShared<EVENT_STATE>(event); |
| 2232 | if (!event_state_shared.get()) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 2233 | |
| 2234 | auto *sync_event = GetCurrentEventsContext()->GetFromShared(event_state_shared); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2235 | if (!sync_event) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 2236 | |
| 2237 | // NOTE: We're going to simply record the sync scope here, as anything else would be implementation defined/undefined |
| 2238 | // and we're issuing errors re: missing barriers between event commands, which if the user fixes would fix |
| 2239 | // any issues caused by naive scope setting here. |
| 2240 | |
| 2241 | // What happens with two SetEvent is that one cannot know what group of operations will be waited for. |
| 2242 | // Given: |
| 2243 | // Stuff1; SetEvent; Stuff2; SetEvent; WaitEvents; |
| 2244 | // WaitEvents cannot know which of Stuff1, Stuff2, or both has completed execution. |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2245 | auto scope = SyncExecScope::MakeSrc(GetQueueFlags(), stageMask); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2246 | |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2247 | if (!sync_event->HasBarrier(stageMask, scope.exec_scope)) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2248 | sync_event->unsynchronized_set = sync_event->last_command; |
| 2249 | sync_event->ResetFirstScope(); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2250 | } else if (sync_event->scope.exec_scope == 0) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2251 | // We only set the scope if there isn't one |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2252 | sync_event->scope = scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2253 | |
| 2254 | auto set_scope = [&sync_event](AccessAddressType address_type, const ResourceAccessRangeMap::value_type &access) { |
| 2255 | auto &scope_map = sync_event->first_scope[static_cast<size_t>(address_type)]; |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2256 | if (access.second.InSourceScopeOrChain(sync_event->scope.exec_scope, sync_event->scope.valid_accesses)) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2257 | scope_map.insert(scope_map.end(), std::make_pair(access.first, true)); |
| 2258 | } |
| 2259 | }; |
| 2260 | GetCurrentAccessContext()->ForAll(set_scope); |
| 2261 | sync_event->unsynchronized_set = CMD_NONE; |
| 2262 | sync_event->first_scope_tag = tag; |
| 2263 | } |
| 2264 | sync_event->last_command = CMD_SETEVENT; |
| 2265 | sync_event->barriers = 0U; |
| 2266 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 2267 | |
| 2268 | bool CommandBufferAccessContext::ValidateResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 2269 | VkPipelineStageFlags stageMask) const { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2270 | // I'll put this here just in case we need to pass this in for future extension support |
| 2271 | const auto cmd = CMD_RESETEVENT; |
| 2272 | |
| 2273 | bool skip = false; |
| 2274 | // TODO: EVENTS: |
| 2275 | // What is it we need to check... that we've had a reset since a set? Set/Set seems ill formed... |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2276 | auto event_state = sync_state_->Get<EVENT_STATE>(event); |
| 2277 | if (!event_state) return skip; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 2278 | |
| 2279 | const auto *sync_event = GetCurrentEventsContext()->Get(event_state); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2280 | if (!sync_event) return false; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 2281 | |
| 2282 | const char *const set_wait = |
| 2283 | "%s: %s %s operation following %s without intervening execution barrier, is a race condition and may result in data " |
| 2284 | "hazards."; |
| 2285 | const char *message = set_wait; // Only one message this call. |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2286 | const auto exec_scope = sync_utils::WithEarlierPipelineStages(sync_utils::ExpandPipelineStages(stageMask, GetQueueFlags())); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2287 | if (!sync_event->HasBarrier(stageMask, exec_scope)) { |
| 2288 | const char *vuid = nullptr; |
| 2289 | switch (sync_event->last_command) { |
| 2290 | case CMD_SETEVENT: |
| 2291 | // Needs a barrier between set and reset |
| 2292 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-set"; |
| 2293 | break; |
| 2294 | case CMD_WAITEVENTS: { |
| 2295 | // Needs to be in the barriers chain (either because of a barrier, or because of dstStageMask |
| 2296 | vuid = "SYNC-vkCmdResetEvent-missingbarrier-wait"; |
| 2297 | break; |
| 2298 | } |
| 2299 | default: |
| 2300 | // The only other valid last command that wasn't one. |
| 2301 | assert((sync_event->last_command == CMD_NONE) || (sync_event->last_command == CMD_RESETEVENT)); |
| 2302 | break; |
| 2303 | } |
| 2304 | if (vuid) { |
| 2305 | const char *const cmd_name = CommandTypeString(cmd); |
| 2306 | skip |= sync_state_->LogError(event, vuid, message, cmd_name, sync_state_->report_data->FormatHandle(event).c_str(), |
| 2307 | cmd_name, CommandTypeString(sync_event->last_command)); |
| 2308 | } |
| 2309 | } |
| 2310 | return skip; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2313 | void CommandBufferAccessContext::RecordResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 2314 | const auto cmd = CMD_RESETEVENT; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2315 | auto event_state_shared = sync_state_->GetShared<EVENT_STATE>(event); |
| 2316 | if (!event_state_shared.get()) return; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 2317 | |
| 2318 | auto *sync_event = GetCurrentEventsContext()->GetFromShared(event_state_shared); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2319 | if (!sync_event) return; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 2320 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2321 | // Clear out the first sync scope, any races vs. wait or set are reported, so we'll keep the bookkeeping simple assuming |
| 2322 | // the safe case |
| 2323 | for (const auto address_type : kAddressTypes) { |
| 2324 | sync_event->first_scope[static_cast<size_t>(address_type)].clear(); |
| 2325 | } |
| 2326 | |
| 2327 | // Update the event state |
| 2328 | sync_event->last_command = cmd; |
| 2329 | sync_event->unsynchronized_set = CMD_NONE; |
| 2330 | sync_event->ResetFirstScope(); |
| 2331 | sync_event->barriers = 0U; |
| 2332 | } |
| 2333 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2334 | void CommandBufferAccessContext::RecordDestroyEvent(VkEvent event) { |
| 2335 | // Erase is okay with the key not being |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 2336 | const auto *event_state = sync_state_->Get<EVENT_STATE>(event); |
| 2337 | if (event_state) { |
| 2338 | GetCurrentEventsContext()->Destroy(event_state); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2342 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const CommandBufferAccessContext &cb_context, |
| 2343 | const CMD_BUFFER_STATE &cmd, const VkRect2D &render_area, |
| 2344 | const char *func_name) const { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2345 | bool skip = false; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2346 | const auto &sync_state = cb_context.GetSyncState(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2347 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2348 | if (!pipe || |
| 2349 | (pipe->graphicsPipelineCI.pRasterizationState && pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2350 | return skip; |
| 2351 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2352 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2353 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
| 2354 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2355 | VkOffset3D offset = CastTo3D(render_area.offset); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2356 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2357 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2358 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2359 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2360 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2361 | if (location >= subpass.colorAttachmentCount || |
| 2362 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2363 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2364 | } |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2365 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pColorAttachments[location].attachment]; |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2366 | HazardResult hazard = current_context.DetectHazard(img_view_state, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2367 | SyncOrdering::kColorAttachment, offset, extent); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2368 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2369 | skip |= sync_state.LogError(img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2370 | "%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] | 2371 | func_name, string_SyncHazard(hazard.hazard), |
| 2372 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 2373 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2374 | location, cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2375 | } |
| 2376 | } |
| 2377 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2378 | |
| 2379 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2380 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2381 | if (pipe->graphicsPipelineCI.pDepthStencilState && subpass.pDepthStencilAttachment && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2382 | subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2383 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pDepthStencilAttachment->attachment]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2384 | bool depth_write = false, stencil_write = false; |
| 2385 | |
| 2386 | // PHASE1 TODO: These validation should be in core_checks. |
| 2387 | if (!FormatIsStencilOnly(img_view_state->create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2388 | pipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 2389 | pipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2390 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2391 | depth_write = true; |
| 2392 | } |
| 2393 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2394 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2395 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2396 | // PHASE1 TODO: These validation should be in core_checks. |
| 2397 | if (!FormatIsDepthOnly(img_view_state->create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2398 | pipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2399 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2400 | stencil_write = true; |
| 2401 | } |
| 2402 | |
| 2403 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2404 | if (depth_write) { |
| 2405 | HazardResult hazard = |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2406 | current_context.DetectHazard(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2407 | SyncOrdering::kDepthStencilAttachment, offset, extent, VK_IMAGE_ASPECT_DEPTH_BIT); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2408 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2409 | skip |= sync_state.LogError( |
| 2410 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2411 | "%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] | 2412 | func_name, string_SyncHazard(hazard.hazard), |
| 2413 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 2414 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2415 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2416 | } |
| 2417 | } |
| 2418 | if (stencil_write) { |
| 2419 | HazardResult hazard = |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2420 | current_context.DetectHazard(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2421 | SyncOrdering::kDepthStencilAttachment, offset, extent, VK_IMAGE_ASPECT_STENCIL_BIT); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2422 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 2423 | skip |= sync_state.LogError( |
| 2424 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2425 | "%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] | 2426 | func_name, string_SyncHazard(hazard.hazard), |
| 2427 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 2428 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2429 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2430 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | return skip; |
| 2434 | } |
| 2435 | |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2436 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd, const VkRect2D &render_area, |
| 2437 | const ResourceUsageTag &tag) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2438 | const auto *pipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2439 | if (!pipe || |
| 2440 | (pipe->graphicsPipelineCI.pRasterizationState && pipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2441 | return; |
| 2442 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2443 | const auto &list = pipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2444 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
| 2445 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2446 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2447 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2448 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 2449 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2450 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 2451 | for (const auto location : list) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2452 | if (location >= subpass.colorAttachmentCount || |
| 2453 | subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2454 | continue; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2455 | } |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 2456 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pColorAttachments[location].attachment]; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2457 | current_context.UpdateAccessState(img_view_state, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 2458 | SyncOrdering::kColorAttachment, offset, extent, 0, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2459 | } |
| 2460 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2461 | |
| 2462 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 2463 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2464 | if (pipe->graphicsPipelineCI.pDepthStencilState && subpass.pDepthStencilAttachment && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2465 | subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2466 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pDepthStencilAttachment->attachment]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2467 | bool depth_write = false, stencil_write = false; |
| 2468 | |
| 2469 | // PHASE1 TODO: These validation should be in core_checks. |
| 2470 | if (!FormatIsStencilOnly(img_view_state->create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2471 | pipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 2472 | pipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2473 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2474 | depth_write = true; |
| 2475 | } |
| 2476 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 2477 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 2478 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 2479 | // PHASE1 TODO: These validation should be in core_checks. |
| 2480 | if (!FormatIsDepthOnly(img_view_state->create_info.format) && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2481 | pipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2482 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 2483 | stencil_write = true; |
| 2484 | } |
| 2485 | |
| 2486 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 2487 | if (depth_write) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2488 | current_context.UpdateAccessState(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2489 | SyncOrdering::kDepthStencilAttachment, offset, extent, VK_IMAGE_ASPECT_DEPTH_BIT, |
| 2490 | tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2491 | } |
| 2492 | if (stencil_write) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2493 | current_context.UpdateAccessState(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 2494 | SyncOrdering::kDepthStencilAttachment, offset, extent, VK_IMAGE_ASPECT_STENCIL_BIT, |
| 2495 | tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 2496 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 2497 | } |
| 2498 | } |
| 2499 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2500 | bool RenderPassAccessContext::ValidateNextSubpass(const CommandBufferAccessContext &cb_context, const VkRect2D &render_area, |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2501 | const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2502 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2503 | bool skip = false; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2504 | skip |= CurrentContext().ValidateResolveOperations(cb_context, *rp_state_, render_area, attachment_views_, func_name, |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2505 | current_subpass_); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2506 | skip |= CurrentContext().ValidateStoreOperation(cb_context, *rp_state_, render_area, current_subpass_, attachment_views_, |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2507 | func_name); |
| 2508 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2509 | const auto next_subpass = current_subpass_ + 1; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2510 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2511 | skip |= next_context.ValidateLayoutTransitions(cb_context, *rp_state_, render_area, next_subpass, attachment_views_, func_name); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2512 | if (!skip) { |
| 2513 | // To avoid complex (and buggy) duplication of the affect of layout transitions on load operations, we'll record them |
| 2514 | // on a copy of the (empty) next context. |
| 2515 | // Note: The resource access map should be empty so hopefully this copy isn't too horrible from a perf POV. |
| 2516 | AccessContext temp_context(next_context); |
| 2517 | temp_context.RecordLayoutTransitions(*rp_state_, next_subpass, attachment_views_, kCurrentCommandTag); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2518 | skip |= temp_context.ValidateLoadOperation(cb_context, *rp_state_, render_area, next_subpass, attachment_views_, func_name); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2519 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2520 | return skip; |
| 2521 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2522 | bool RenderPassAccessContext::ValidateEndRenderPass(const CommandBufferAccessContext &cb_context, const VkRect2D &render_area, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2523 | const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2524 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2525 | bool skip = false; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2526 | skip |= CurrentContext().ValidateResolveOperations(cb_context, *rp_state_, render_area, attachment_views_, func_name, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2527 | current_subpass_); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2528 | skip |= CurrentContext().ValidateStoreOperation(cb_context, *rp_state_, render_area, current_subpass_, attachment_views_, |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2529 | func_name); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2530 | skip |= ValidateFinalSubpassLayoutTransitions(cb_context, render_area, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2531 | return skip; |
| 2532 | } |
| 2533 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2534 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy(const VkRect2D &render_area) const { |
| 2535 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, render_area, attachment_views_); |
| 2536 | } |
| 2537 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2538 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const CommandBufferAccessContext &cb_context, |
| 2539 | const VkRect2D &render_area, const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2540 | bool skip = false; |
| 2541 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2542 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2543 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2544 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2545 | // to apply and only copy then, if this proves a hot spot. |
| 2546 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2547 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2548 | // Validate the "finalLayout" transitions to external |
| 2549 | // Get them from where there we're hidding in the extra entry. |
| 2550 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2551 | for (const auto &transition : final_transitions) { |
| 2552 | const auto &attach_view = attachment_views_[transition.attachment]; |
| 2553 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
| 2554 | 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] | 2555 | auto *context = trackback.context; |
| 2556 | |
| 2557 | if (transition.prev_pass == current_subpass_) { |
| 2558 | if (!proxy_for_current) { |
| 2559 | // We haven't recorded resolve ofor the current_subpass, so we need to copy current and update it *as if* |
| 2560 | proxy_for_current.reset(CreateStoreResolveProxy(render_area)); |
| 2561 | } |
| 2562 | context = proxy_for_current.get(); |
| 2563 | } |
| 2564 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2565 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2566 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
| 2567 | auto hazard = context->DetectImageBarrierHazard(*attach_view->image_state, merged_barrier.src_exec_scope, |
| 2568 | merged_barrier.src_access_scope, attach_view->normalized_subresource_range, |
| 2569 | AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2570 | if (hazard.hazard) { |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2571 | skip |= cb_context.GetSyncState().LogError( |
| 2572 | rp_state_->renderPass, string_SyncHazardVUID(hazard.hazard), |
| 2573 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
| 2574 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 2575 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
| 2576 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
| 2577 | cb_context.FormatUsage(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | return skip; |
| 2581 | } |
| 2582 | |
| 2583 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag &tag) { |
| 2584 | // Add layout transitions... |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2585 | subpass_contexts_[current_subpass_].RecordLayoutTransitions(*rp_state_, current_subpass_, attachment_views_, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2586 | } |
| 2587 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2588 | void RenderPassAccessContext::RecordLoadOperations(const VkRect2D &render_area, const ResourceUsageTag &tag) { |
| 2589 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2590 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
| 2591 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2592 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2593 | |
| 2594 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2595 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
| 2596 | if (attachment_views_[i] == nullptr) continue; // UNUSED |
| 2597 | const auto &view = *attachment_views_[i]; |
| 2598 | const IMAGE_STATE *image = view.image_state.get(); |
| 2599 | if (image == nullptr) continue; |
| 2600 | |
| 2601 | const auto &ci = attachment_ci[i]; |
| 2602 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2603 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2604 | const bool is_color = !(has_depth || has_stencil); |
| 2605 | |
| 2606 | if (is_color) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2607 | subpass_context.UpdateAccessState(*image, ColorLoadUsage(ci.loadOp), SyncOrdering::kColorAttachment, |
| 2608 | view.normalized_subresource_range, offset, extent, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2609 | } else { |
| 2610 | auto update_range = view.normalized_subresource_range; |
| 2611 | if (has_depth) { |
| 2612 | update_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2613 | subpass_context.UpdateAccessState(*image, DepthStencilLoadUsage(ci.loadOp), |
| 2614 | SyncOrdering::kDepthStencilAttachment, update_range, offset, extent, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2615 | } |
| 2616 | if (has_stencil) { |
| 2617 | update_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2618 | subpass_context.UpdateAccessState(*image, DepthStencilLoadUsage(ci.stencilLoadOp), |
| 2619 | SyncOrdering::kDepthStencilAttachment, update_range, offset, extent, tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2620 | } |
| 2621 | } |
| 2622 | } |
| 2623 | } |
| 2624 | } |
| 2625 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2626 | void RenderPassAccessContext::RecordBeginRenderPass(const SyncValidator &state, const CMD_BUFFER_STATE &cb_state, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2627 | const AccessContext *external_context, VkQueueFlags queue_flags, |
| 2628 | const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2629 | current_subpass_ = 0; |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 2630 | rp_state_ = cb_state.activeRenderPass.get(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2631 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
| 2632 | // Add this for all subpasses here so that they exsist during next subpass validation |
| 2633 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2634 | 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] | 2635 | } |
| 2636 | attachment_views_ = state.GetCurrentAttachmentViews(cb_state); |
| 2637 | |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2638 | subpass_contexts_[current_subpass_].SetStartTag(tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2639 | RecordLayoutTransitions(tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2640 | RecordLoadOperations(cb_state.activeRenderPassBeginInfo.renderArea, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2641 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2642 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2643 | void RenderPassAccessContext::RecordNextSubpass(const VkRect2D &render_area, const ResourceUsageTag &prev_subpass_tag, |
| 2644 | const ResourceUsageTag &next_subpass_tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2645 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2646 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, render_area, attachment_views_, current_subpass_, prev_subpass_tag); |
| 2647 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, render_area, attachment_views_, current_subpass_, prev_subpass_tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2648 | |
Jeremy Gebben | 6ea9d9e | 2020-12-11 09:41:01 -0700 | [diff] [blame] | 2649 | // Move to the next sub-command for the new subpass. The resolve and store are logically part of the previous |
| 2650 | // subpass, so their tag needs to be different from the layout and load operations below. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2651 | current_subpass_++; |
| 2652 | assert(current_subpass_ < subpass_contexts_.size()); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2653 | subpass_contexts_[current_subpass_].SetStartTag(next_subpass_tag); |
| 2654 | RecordLayoutTransitions(next_subpass_tag); |
| 2655 | RecordLoadOperations(render_area, next_subpass_tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2656 | } |
| 2657 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2658 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const VkRect2D &render_area, |
| 2659 | const ResourceUsageTag &tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2660 | // Add the resolve and store accesses |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2661 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, render_area, attachment_views_, current_subpass_, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2662 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, render_area, attachment_views_, current_subpass_, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2663 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2664 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2665 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2666 | |
| 2667 | // Add the "finalLayout" transitions to external |
| 2668 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2669 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2670 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2671 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2672 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2673 | for (const auto &transition : final_transitions) { |
| 2674 | const auto &attachment = attachment_views_[transition.attachment]; |
| 2675 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | aa97d8b | 2020-07-14 10:58:13 -0600 | [diff] [blame] | 2676 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.context); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2677 | ApplyBarrierOpsFunctor<PipelineBarrierOp> barrier_action(true /* resolve */, last_trackback.barriers.size(), tag); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2678 | for (const auto &barrier : last_trackback.barriers) { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 2679 | barrier_action.EmplaceBack(PipelineBarrierOp(barrier, true)); |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2680 | } |
John Zulauf | 1e331ec | 2020-12-04 18:29:38 -0700 | [diff] [blame] | 2681 | external_context->UpdateResourceAccess(*attachment->image_state, attachment->normalized_subresource_range, barrier_action); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2682 | } |
| 2683 | } |
| 2684 | |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2685 | SyncExecScope SyncExecScope::MakeSrc(VkQueueFlags queue_flags, VkPipelineStageFlags mask_param) { |
| 2686 | SyncExecScope result; |
| 2687 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2688 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2689 | result.exec_scope = sync_utils::WithEarlierPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2690 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2691 | return result; |
| 2692 | } |
| 2693 | |
| 2694 | SyncExecScope SyncExecScope::MakeDst(VkQueueFlags queue_flags, VkPipelineStageFlags mask_param) { |
| 2695 | SyncExecScope result; |
| 2696 | result.mask_param = mask_param; |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 2697 | result.expanded_mask = sync_utils::ExpandPipelineStages(mask_param, queue_flags); |
| 2698 | result.exec_scope = sync_utils::WithLaterPipelineStages(result.expanded_mask); |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 2699 | result.valid_accesses = SyncStageAccess::AccessScopeByStage(result.exec_scope); |
| 2700 | return result; |
| 2701 | } |
| 2702 | |
| 2703 | SyncBarrier::SyncBarrier(const SyncExecScope &src, const SyncExecScope &dst) { |
| 2704 | src_exec_scope = src.exec_scope; |
| 2705 | src_access_scope = 0; |
| 2706 | dst_exec_scope = dst.exec_scope; |
| 2707 | dst_access_scope = 0; |
| 2708 | } |
| 2709 | |
| 2710 | template <typename Barrier> |
| 2711 | SyncBarrier::SyncBarrier(const Barrier &barrier, const SyncExecScope &src, const SyncExecScope &dst) { |
| 2712 | src_exec_scope = src.exec_scope; |
| 2713 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, barrier.srcAccessMask); |
| 2714 | dst_exec_scope = dst.exec_scope; |
| 2715 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, barrier.dstAccessMask); |
| 2716 | } |
| 2717 | |
| 2718 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &subpass) { |
| 2719 | auto src = SyncExecScope::MakeSrc(queue_flags, subpass.srcStageMask); |
| 2720 | src_exec_scope = src.exec_scope; |
| 2721 | src_access_scope = SyncStageAccess::AccessScope(src.valid_accesses, subpass.srcAccessMask); |
| 2722 | |
| 2723 | auto dst = SyncExecScope::MakeDst(queue_flags, subpass.dstStageMask); |
| 2724 | dst_exec_scope = dst.exec_scope; |
| 2725 | dst_access_scope = SyncStageAccess::AccessScope(dst.valid_accesses, subpass.dstAccessMask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2726 | } |
| 2727 | |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2728 | // Apply a list of barriers, without resolving pending state, useful for subpass layout transitions |
| 2729 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
| 2730 | for (const auto &barrier : barriers) { |
| 2731 | ApplyBarrier(barrier, layout_transition); |
| 2732 | } |
| 2733 | } |
| 2734 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2735 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2736 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2737 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2738 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers, const ResourceUsageTag &tag) { |
| 2739 | 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] | 2740 | assert(pending_write_barriers.none()); |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2741 | assert(!pending_write_dep_chain); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2742 | for (const auto &barrier : barriers) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2743 | ApplyBarrier(barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2744 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2745 | ApplyPendingBarriers(tag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2746 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2747 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2748 | HazardResult hazard; |
| 2749 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2750 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2751 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2752 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2753 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2754 | } |
| 2755 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2756 | // Write operation: |
| 2757 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2758 | // If reads exists -- test only against them because either: |
| 2759 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2760 | // * 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 |
| 2761 | // the current write happens after the reads, so just test the write against the reades |
| 2762 | // Otherwise test against last_write |
| 2763 | // |
| 2764 | // Look for casus belli for WAR |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2765 | if (last_reads.size()) { |
| 2766 | for (const auto &read_access : last_reads) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2767 | if (IsReadHazard(usage_stage, read_access)) { |
| 2768 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2769 | break; |
| 2770 | } |
| 2771 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2772 | } else if (last_write.any() && IsWriteHazard(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2773 | // Write-After-Write check -- if we have a previous write to test against |
| 2774 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2775 | } |
| 2776 | } |
| 2777 | return hazard; |
| 2778 | } |
| 2779 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 2780 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrdering &ordering_rule) const { |
| 2781 | const auto &ordering = GetOrderingRules(ordering_rule); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2782 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 2783 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2784 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2785 | const auto usage_stage = PipelineStageBit(usage_index); |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2786 | const bool input_attachment_ordering = (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT).any(); |
| 2787 | const bool last_write_is_ordered = (last_write & ordering.access_scope).any(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2788 | if (IsRead(usage_bit)) { |
| 2789 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 2790 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 2791 | if (is_raw_hazard) { |
| 2792 | // NOTE: we know last_write is non-zero |
| 2793 | // See if the ordering rules save us from the simple RAW check above |
| 2794 | // First check to see if the current usage is covered by the ordering rules |
| 2795 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 2796 | const bool usage_is_ordered = |
| 2797 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 2798 | if (usage_is_ordered) { |
| 2799 | // Now see of the most recent write (or a subsequent read) are ordered |
| 2800 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(ordering)); |
| 2801 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2802 | } |
| 2803 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2804 | if (is_raw_hazard) { |
| 2805 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 2806 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2807 | } else { |
| 2808 | // Only check for WAW if there are no reads since last_write |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2809 | bool usage_write_is_ordered = (usage_bit & ordering.access_scope).any(); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2810 | if (last_reads.size()) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2811 | // Look for any WAR hazards outside the ordered set of stages |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2812 | VkPipelineStageFlags ordered_stages = 0; |
| 2813 | if (usage_write_is_ordered) { |
| 2814 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
| 2815 | ordered_stages = GetOrderedStages(ordering); |
| 2816 | } |
| 2817 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 2818 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2819 | for (const auto &read_access : last_reads) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2820 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 2821 | if (IsReadHazard(usage_stage, read_access)) { |
| 2822 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2823 | break; |
| 2824 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2825 | } |
| 2826 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2827 | } else if (!(last_write_is_ordered && usage_write_is_ordered)) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2828 | if (last_write.any() && IsWriteHazard(usage_bit)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2829 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2830 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2831 | } |
| 2832 | } |
| 2833 | return hazard; |
| 2834 | } |
| 2835 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2836 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2837 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index, const ResourceUsageTag &start_tag) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2838 | HazardResult hazard; |
| 2839 | auto usage = FlagBit(usage_index); |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2840 | // Async checks need to not go back further than the start of the subpass, as we only want to find hazards between the async |
| 2841 | // subpasses. Anything older than that should have been checked at the start of each subpass, taking into account all of |
| 2842 | // the raster ordering rules. |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2843 | if (IsRead(usage)) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2844 | if (last_write.any() && (write_tag.index >= start_tag.index)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2845 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2846 | } |
| 2847 | } else { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2848 | if (last_write.any() && (write_tag.index >= start_tag.index)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2849 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2850 | } else if (last_reads.size() > 0) { |
Jeremy Gebben | c4b78c5 | 2020-12-11 09:39:47 -0700 | [diff] [blame] | 2851 | // 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] | 2852 | for (const auto &read_access : last_reads) { |
| 2853 | if (read_access.tag.index >= start_tag.index) { |
| 2854 | 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] | 2855 | break; |
| 2856 | } |
| 2857 | } |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2858 | } |
| 2859 | } |
| 2860 | return hazard; |
| 2861 | } |
| 2862 | |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2863 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags src_exec_scope, |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2864 | const SyncStageAccessFlags &src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2865 | // Only supporting image layout transitions for now |
| 2866 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2867 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2868 | // only test for WAW if there no intervening read operations. |
| 2869 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2870 | if (last_reads.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2871 | // Look at the reads if any |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2872 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2873 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2874 | 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] | 2875 | break; |
| 2876 | } |
| 2877 | } |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2878 | } else if (last_write.any() && IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2879 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2880 | } |
| 2881 | |
| 2882 | return hazard; |
| 2883 | } |
| 2884 | |
| 2885 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags src_exec_scope, |
| 2886 | const SyncStageAccessFlags &src_access_scope, |
| 2887 | const ResourceUsageTag &event_tag) const { |
| 2888 | // Only supporting image layout transitions for now |
| 2889 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2890 | HazardResult hazard; |
| 2891 | // only test for WAW if there no intervening read operations. |
| 2892 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 2893 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2894 | if (last_reads.size()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2895 | // Look at the reads if any... if reads exist, they are either the resaon the access is in the event |
| 2896 | // first scope, or they are a hazard. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2897 | for (const auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2898 | if (read_access.tag.IsBefore(event_tag)) { |
| 2899 | // The read is in the events first synchronization scope, so we use a barrier hazard check |
| 2900 | // If the read stage is not in the src sync scope |
| 2901 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 2902 | // then the barrier access is unsafe (R/W after R) |
| 2903 | if (read_access.IsReadBarrierHazard(src_exec_scope)) { |
| 2904 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2905 | break; |
| 2906 | } |
| 2907 | } else { |
| 2908 | // The read not in the event first sync scope and so is a hazard vs. the layout transition |
| 2909 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2910 | } |
| 2911 | } |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 2912 | } else if (last_write.any()) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 2913 | // if there are no reads, the write is either the reason the access is in the event scope... they are a hazard |
| 2914 | if (write_tag.IsBefore(event_tag)) { |
| 2915 | // The write is in the first sync scope of the event (sync their aren't any reads to be the reason) |
| 2916 | // So do a normal barrier hazard check |
| 2917 | if (IsWriteBarrierHazard(src_exec_scope, src_access_scope)) { |
| 2918 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2919 | } |
| 2920 | } else { |
| 2921 | // 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] | 2922 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2923 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2924 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2925 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2926 | return hazard; |
| 2927 | } |
| 2928 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2929 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 2930 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 2931 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 2932 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
| 2933 | if (write_tag.IsBefore(other.write_tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2934 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 2935 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2936 | *this = other; |
| 2937 | } else if (!other.write_tag.IsBefore(write_tag)) { |
| 2938 | // This is the *equals* case for write operations, we merged the write barriers and the read state (but without the |
| 2939 | // dependency chaining logic or any stage expansion) |
| 2940 | write_barriers |= other.write_barriers; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2941 | pending_write_barriers |= other.pending_write_barriers; |
| 2942 | pending_layout_transition |= other.pending_layout_transition; |
| 2943 | pending_write_dep_chain |= other.pending_write_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2944 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2945 | // Merge the read states |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2946 | const auto pre_merge_count = last_reads.size(); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2947 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2948 | 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] | 2949 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2950 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2951 | // 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] | 2952 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 2953 | // but we should wait on profiling data for that. |
| 2954 | 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] | 2955 | auto &my_read = last_reads[my_read_index]; |
| 2956 | if (other_read.stage == my_read.stage) { |
| 2957 | if (my_read.tag.IsBefore(other_read.tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2958 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2959 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2960 | my_read.tag = other_read.tag; |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2961 | my_read.pending_dep_chain = other_read.pending_dep_chain; |
| 2962 | // TODO: Phase 2 -- review the state merge logic to avoid false positive from overwriting the barriers |
| 2963 | // May require tracking more than one access per stage. |
| 2964 | my_read.barriers = other_read.barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2965 | if (my_read.stage == VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT) { |
| 2966 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 2967 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2968 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2969 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2970 | } else if (other_read.tag.IsBefore(my_read.tag)) { |
| 2971 | // The read tags match so merge the barriers |
| 2972 | my_read.barriers |= other_read.barriers; |
| 2973 | my_read.pending_dep_chain |= other_read.pending_dep_chain; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2974 | } |
John Zulauf | b02c1eb | 2020-10-06 16:33:36 -0600 | [diff] [blame] | 2975 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2976 | break; |
| 2977 | } |
| 2978 | } |
| 2979 | } else { |
| 2980 | // The other read stage doesn't exist in this, so add it. |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 2981 | last_reads.emplace_back(other_read); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2982 | last_read_stages |= other_read.stage; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2983 | if (other_read.stage == VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 2984 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2985 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2986 | } |
| 2987 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2988 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2989 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 2990 | // ignore it. |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 2991 | |
| 2992 | // Merge first access information by making a copy of this first_access and reconstructing with a shuffle |
| 2993 | // of the copy and other into this using the update first logic. |
| 2994 | // NOTE: All sorts of additional cleverness could be put into short circuts. (for example back is write and is before front |
| 2995 | // of the other first_accesses... ) |
| 2996 | if (!(first_accesses_ == other.first_accesses_) && !other.first_accesses_.empty()) { |
| 2997 | FirstAccesses firsts(std::move(first_accesses_)); |
| 2998 | first_accesses_.clear(); |
| 2999 | first_read_stages_ = 0U; |
| 3000 | auto a = firsts.begin(); |
| 3001 | auto a_end = firsts.end(); |
| 3002 | for (auto &b : other.first_accesses_) { |
| 3003 | // TODO: Determine whether "IsBefore" or "IsGloballyBefore" is needed... |
| 3004 | while (a != a_end && a->tag.IsBefore(b.tag)) { |
| 3005 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3006 | ++a; |
| 3007 | } |
| 3008 | UpdateFirst(b.tag, b.usage_index, b.ordering_rule); |
| 3009 | } |
| 3010 | for (; a != a_end; ++a) { |
| 3011 | UpdateFirst(a->tag, a->usage_index, a->ordering_rule); |
| 3012 | } |
| 3013 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3014 | } |
| 3015 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3016 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, SyncOrdering ordering_rule, const ResourceUsageTag &tag) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3017 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 3018 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3019 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3020 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 3021 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 3022 | const auto usage_stage = PipelineStageBit(usage_index); |
| 3023 | if (usage_stage & last_read_stages) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3024 | for (auto &read_access : last_reads) { |
| 3025 | if (read_access.stage == usage_stage) { |
| 3026 | read_access.Set(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3027 | break; |
| 3028 | } |
| 3029 | } |
| 3030 | } else { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3031 | last_reads.emplace_back(usage_stage, usage_bit, 0, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3032 | last_read_stages |= usage_stage; |
| 3033 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3034 | |
| 3035 | // Fragment shader reads come in two flavors, and we need to track if the one we're tracking is the special one. |
| 3036 | if (usage_stage == VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3037 | // TODO Revisit re: multiple reads for a given stage |
| 3038 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3039 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3040 | } else { |
| 3041 | // Assume write |
| 3042 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3043 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3044 | } |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3045 | UpdateFirst(tag, usage_index, ordering_rule); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3046 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3047 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3048 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 3049 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 3050 | // We can overwrite them as *this* write is now after them. |
| 3051 | // |
| 3052 | // 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] | 3053 | void ResourceAccessState::SetWrite(const SyncStageAccessFlags &usage_bit, const ResourceUsageTag &tag) { |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3054 | last_reads.clear(); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3055 | last_read_stages = 0; |
| 3056 | read_execution_barriers = 0; |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame] | 3057 | 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] | 3058 | |
| 3059 | write_barriers = 0; |
| 3060 | write_dependency_chain = 0; |
| 3061 | write_tag = tag; |
| 3062 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3063 | } |
| 3064 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3065 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 3066 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 3067 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 3068 | // replace the current write barriers or add to them, so accumulate to pending as well. |
| 3069 | void ResourceAccessState::ApplyBarrier(const SyncBarrier &barrier, bool layout_transition) { |
| 3070 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 3071 | // applying the memory barriers |
John Zulauf | 86356ca | 2020-10-19 11:46:41 -0600 | [diff] [blame] | 3072 | // NOTE: We update the write barrier if the write is in the first access scope or if there is a layout |
| 3073 | // transistion, under the theory of "most recent access". If the read/write *isn't* safe |
| 3074 | // vs. this layout transition DetectBarrierHazard should report it. We treat the layout |
| 3075 | // transistion *as* a write and in scope with the barrier (it's before visibility). |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3076 | if (layout_transition || WriteInSourceScopeOrChain(barrier.src_exec_scope, barrier.src_access_scope)) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3077 | pending_write_barriers |= barrier.dst_access_scope; |
| 3078 | pending_write_dep_chain |= barrier.dst_exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3079 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3080 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 3081 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3082 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3083 | if (!pending_layout_transition) { |
| 3084 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 3085 | // 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] | 3086 | for (auto &read_access : last_reads) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3087 | // The | implements the "dependency chain" logic for this access, as the barriers field stores the second sync scope |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3088 | if (barrier.src_exec_scope & (read_access.stage | read_access.barriers)) { |
| 3089 | read_access.pending_dep_chain |= barrier.dst_exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3090 | } |
| 3091 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3092 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 3093 | } |
| 3094 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3095 | // Apply the tag scoped memory barrier without updating the existing barriers. The execution barrier |
| 3096 | // changes the "chaining" state, but to keep barriers independent. See discussion above. |
| 3097 | void ResourceAccessState::ApplyBarrier(const ResourceUsageTag &scope_tag, const SyncBarrier &barrier, bool layout_transition) { |
| 3098 | // The scope logic for events is, if we're here, the resource usage was flagged as "in the first execution scope" at |
| 3099 | // the time of the SetEvent, thus all we need check is whether the access is the same one (i.e. before the scope tag |
| 3100 | // in order to know if it's in the excecution scope |
| 3101 | // Notice that the layout transition sets the pending barriers *regardless*, as any lack of src_access_scope to |
| 3102 | // guard against the layout transition should be reported in the detect barrier hazard phase, and we only report |
| 3103 | // errors w.r.t. "most recent" accesses. |
| 3104 | if (layout_transition || ((write_tag.IsBefore(scope_tag)) && (barrier.src_access_scope & last_write).any())) { |
| 3105 | pending_write_barriers |= barrier.dst_access_scope; |
| 3106 | pending_write_dep_chain |= barrier.dst_exec_scope; |
| 3107 | } |
| 3108 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 3109 | pending_layout_transition |= layout_transition; |
| 3110 | |
| 3111 | if (!pending_layout_transition) { |
| 3112 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 3113 | // 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] | 3114 | for (auto &read_access : last_reads) { |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3115 | // If this read is the same one we included in the set event and in scope, then apply the execution barrier... |
| 3116 | // NOTE: That's not really correct... this read stage might *not* have been included in the setevent, and the barriers |
| 3117 | // representing the chain might have changed since then (that would be an odd usage), so as a first approximation |
| 3118 | // we'll assume the barriers *haven't* been changed since (if the tag hasn't), and while this could be a false |
| 3119 | // positive in the case of Set; SomeBarrier; Wait; we'll live with it until we can add more state to the first scope |
| 3120 | // capture (the specific write and read stages that *were* in scope at the moment of SetEvents. |
| 3121 | // TODO: eliminate the false positive by including write/read-stages "in scope" information in SetEvents first_scope |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3122 | if (read_access.tag.IsBefore(scope_tag) && (barrier.src_exec_scope & (read_access.stage | read_access.barriers))) { |
| 3123 | read_access.pending_dep_chain |= barrier.dst_exec_scope; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3124 | } |
| 3125 | } |
| 3126 | } |
| 3127 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3128 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag &tag) { |
| 3129 | if (pending_layout_transition) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3130 | // SetWrite clobbers the read count, and thus we don't have to clear the read_state out. |
| 3131 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3132 | UpdateFirst(tag, SYNC_IMAGE_LAYOUT_TRANSITION, SyncOrdering::kNonAttachment); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3133 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3134 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3135 | |
| 3136 | // Apply the accumulate execution barriers (and thus update chaining information) |
| 3137 | // 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] | 3138 | for (auto &read_access : last_reads) { |
| 3139 | read_access.barriers |= read_access.pending_dep_chain; |
| 3140 | read_execution_barriers |= read_access.barriers; |
| 3141 | read_access.pending_dep_chain = 0; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 3142 | } |
| 3143 | |
| 3144 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 3145 | write_dependency_chain |= pending_write_dep_chain; |
| 3146 | write_barriers |= pending_write_barriers; |
| 3147 | pending_write_dep_chain = 0; |
| 3148 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3149 | } |
| 3150 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3151 | // This should be just Bits or Index, but we don't have an invalid state for Index |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3152 | VkPipelineStageFlags ResourceAccessState::GetReadBarriers(const SyncStageAccessFlags &usage_bit) const { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3153 | VkPipelineStageFlags barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3154 | |
John Zulauf | ab7756b | 2020-12-29 16:10:16 -0700 | [diff] [blame] | 3155 | for (const auto &read_access : last_reads) { |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3156 | if ((read_access.access & usage_bit).any()) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3157 | barriers = read_access.barriers; |
| 3158 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3159 | } |
| 3160 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3161 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3162 | return barriers; |
| 3163 | } |
| 3164 | |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3165 | inline bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlagBits usage_stage, const SyncStageAccessFlags &usage) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3166 | assert(IsRead(usage)); |
| 3167 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 3168 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 3169 | // any reads that happen after. |
| 3170 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 3171 | // 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] | 3172 | return last_write.any() && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3173 | } |
| 3174 | |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3175 | VkPipelineStageFlags ResourceAccessState::GetOrderedStages(const OrderingBarrier &ordering) const { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3176 | // Whether the stage are in the ordering scope only matters if the current write is ordered |
| 3177 | VkPipelineStageFlags ordered_stages = last_read_stages & ordering.exec_scope; |
| 3178 | // Special input attachment handling as always (not encoded in exec_scop) |
Jeremy Gebben | d0de1f8 | 2020-11-09 08:21:07 -0700 | [diff] [blame] | 3179 | 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] | 3180 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 3181 | // If we have an input attachment in last_reads and input attachments are ordered we all that stage |
| 3182 | ordered_stages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; |
| 3183 | } |
| 3184 | |
| 3185 | return ordered_stages; |
| 3186 | } |
| 3187 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3188 | void ResourceAccessState::UpdateFirst(const ResourceUsageTag &tag, SyncStageAccessIndex usage_index, SyncOrdering ordering_rule) { |
| 3189 | // Only record until we record a write. |
| 3190 | if (first_accesses_.empty() || IsRead(first_accesses_.back().usage_index)) { |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 3191 | const VkPipelineStageFlags usage_stage = |
| 3192 | IsRead(usage_index) ? static_cast<VkPipelineStageFlags>(PipelineStageBit(usage_index)) : 0U; |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3193 | if (0 == (usage_stage & first_read_stages_)) { |
| 3194 | // If this is a read we haven't seen or a write, record. |
| 3195 | first_read_stages_ |= usage_stage; |
| 3196 | first_accesses_.emplace_back(tag, usage_index, ordering_rule); |
| 3197 | } |
| 3198 | } |
| 3199 | } |
| 3200 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3201 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3202 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 3203 | if (access_context) { |
| 3204 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3205 | } |
| 3206 | } |
| 3207 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3208 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 3209 | auto access_found = cb_access_state.find(command_buffer); |
| 3210 | if (access_found != cb_access_state.end()) { |
| 3211 | access_found->second->Reset(); |
| 3212 | cb_access_state.erase(access_found); |
| 3213 | } |
| 3214 | } |
| 3215 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3216 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3217 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 3218 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3219 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3220 | assert(cb_context); |
| 3221 | if (!cb_context) return skip; |
| 3222 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3223 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3224 | // If we have no previous accesses, we have no hazards |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3225 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3226 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3227 | |
| 3228 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3229 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3230 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3231 | const ResourceAccessRange src_range = MakeRange(*src_buffer, copy_region.srcOffset, copy_region.size); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3232 | auto hazard = context->DetectHazard(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3233 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3234 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3235 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3236 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3237 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3238 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3239 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3240 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3241 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3242 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3243 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3244 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3245 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3246 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3247 | cb_context->FormatUsage(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3248 | } |
| 3249 | } |
| 3250 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3251 | } |
| 3252 | return skip; |
| 3253 | } |
| 3254 | |
| 3255 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 3256 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3257 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3258 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3259 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3260 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3261 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3262 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3263 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3264 | |
| 3265 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3266 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3267 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3268 | const ResourceAccessRange src_range = MakeRange(*src_buffer, copy_region.srcOffset, copy_region.size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3269 | context->UpdateAccessState(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, SyncOrdering::kNonAttachment, src_range, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3270 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3271 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3272 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3273 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, dst_range, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3274 | } |
| 3275 | } |
| 3276 | } |
| 3277 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 3278 | void SyncValidator::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 3279 | // Clear out events from the command buffer contexts |
| 3280 | for (auto &cb_context : cb_access_state) { |
| 3281 | cb_context.second->RecordDestroyEvent(event); |
| 3282 | } |
| 3283 | } |
| 3284 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3285 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3286 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 3287 | bool skip = false; |
| 3288 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 3289 | assert(cb_context); |
| 3290 | if (!cb_context) return skip; |
| 3291 | const auto *context = cb_context->GetCurrentAccessContext(); |
| 3292 | |
| 3293 | // If we have no previous accesses, we have no hazards |
| 3294 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3295 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3296 | |
| 3297 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3298 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3299 | if (src_buffer) { |
| 3300 | const ResourceAccessRange src_range = MakeRange(*src_buffer, copy_region.srcOffset, copy_region.size); |
| 3301 | auto hazard = context->DetectHazard(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range); |
| 3302 | if (hazard.hazard) { |
| 3303 | // TODO -- add tag information to log msg when useful. |
| 3304 | skip |= LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3305 | "vkCmdCopyBuffer2KHR(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3306 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3307 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3308 | } |
| 3309 | } |
| 3310 | if (dst_buffer && !skip) { |
| 3311 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
| 3312 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range); |
| 3313 | if (hazard.hazard) { |
| 3314 | skip |= LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3315 | "vkCmdCopyBuffer2KHR(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
| 3316 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3317 | region, cb_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3318 | } |
| 3319 | } |
| 3320 | if (skip) break; |
| 3321 | } |
| 3322 | return skip; |
| 3323 | } |
| 3324 | |
| 3325 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 3326 | auto *cb_context = GetAccessContext(commandBuffer); |
| 3327 | assert(cb_context); |
| 3328 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER2KHR); |
| 3329 | auto *context = cb_context->GetCurrentAccessContext(); |
| 3330 | |
| 3331 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 3332 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 3333 | |
| 3334 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 3335 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 3336 | if (src_buffer) { |
| 3337 | const ResourceAccessRange src_range = MakeRange(*src_buffer, copy_region.srcOffset, copy_region.size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3338 | context->UpdateAccessState(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, SyncOrdering::kNonAttachment, src_range, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3339 | } |
| 3340 | if (dst_buffer) { |
| 3341 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3342 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, dst_range, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3343 | } |
| 3344 | } |
| 3345 | } |
| 3346 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3347 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3348 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3349 | const VkImageCopy *pRegions) const { |
| 3350 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3351 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3352 | assert(cb_access_context); |
| 3353 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3354 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3355 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3356 | assert(context); |
| 3357 | if (!context) return skip; |
| 3358 | |
| 3359 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3360 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3361 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3362 | const auto ©_region = pRegions[region]; |
| 3363 | if (src_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3364 | auto hazard = context->DetectHazard(*src_image, SYNC_TRANSFER_TRANSFER_READ, copy_region.srcSubresource, |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3365 | copy_region.srcOffset, copy_region.extent); |
| 3366 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3367 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3368 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3369 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3370 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3371 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3375 | VkExtent3D dst_copy_extent = |
| 3376 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3377 | auto hazard = context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, copy_region.dstSubresource, |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3378 | copy_region.dstOffset, dst_copy_extent); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3379 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3380 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3381 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3382 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3383 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3384 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 3385 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3386 | } |
| 3387 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3388 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3389 | return skip; |
| 3390 | } |
| 3391 | |
| 3392 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3393 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3394 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3395 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3396 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3397 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3398 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3399 | assert(context); |
| 3400 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3401 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3402 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3403 | |
| 3404 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3405 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3406 | if (src_image) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3407 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, SyncOrdering::kNonAttachment, |
| 3408 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 3409 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3410 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 3411 | VkExtent3D dst_copy_extent = |
| 3412 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3413 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
| 3414 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3415 | } |
| 3416 | } |
| 3417 | } |
| 3418 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3419 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 3420 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 3421 | bool skip = false; |
| 3422 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3423 | assert(cb_access_context); |
| 3424 | if (!cb_access_context) return skip; |
| 3425 | |
| 3426 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3427 | assert(context); |
| 3428 | if (!context) return skip; |
| 3429 | |
| 3430 | const auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3431 | const auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3432 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3433 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3434 | if (src_image) { |
| 3435 | auto hazard = context->DetectHazard(*src_image, SYNC_TRANSFER_TRANSFER_READ, copy_region.srcSubresource, |
| 3436 | copy_region.srcOffset, copy_region.extent); |
| 3437 | if (hazard.hazard) { |
| 3438 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 3439 | "vkCmdCopyImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 3440 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3441 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | if (dst_image) { |
| 3446 | VkExtent3D dst_copy_extent = |
| 3447 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
| 3448 | auto hazard = context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, copy_region.dstSubresource, |
| 3449 | copy_region.dstOffset, dst_copy_extent); |
| 3450 | if (hazard.hazard) { |
| 3451 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 3452 | "vkCmdCopyImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 3453 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3454 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3455 | } |
| 3456 | if (skip) break; |
| 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | return skip; |
| 3461 | } |
| 3462 | |
| 3463 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 3464 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3465 | assert(cb_access_context); |
| 3466 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE2KHR); |
| 3467 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3468 | assert(context); |
| 3469 | |
| 3470 | auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 3471 | auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 3472 | |
| 3473 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 3474 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 3475 | if (src_image) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3476 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, SyncOrdering::kNonAttachment, |
| 3477 | copy_region.srcSubresource, copy_region.srcOffset, copy_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3478 | } |
| 3479 | if (dst_image) { |
| 3480 | VkExtent3D dst_copy_extent = |
| 3481 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3482 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
| 3483 | copy_region.dstSubresource, copy_region.dstOffset, dst_copy_extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3484 | } |
| 3485 | } |
| 3486 | } |
| 3487 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3488 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3489 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3490 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3491 | uint32_t bufferMemoryBarrierCount, |
| 3492 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3493 | uint32_t imageMemoryBarrierCount, |
| 3494 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 3495 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3496 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3497 | assert(cb_access_context); |
| 3498 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 3499 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 3500 | SyncOpPipelineBarrier pipeline_barrier(*this, cb_access_context->GetQueueFlags(), srcStageMask, dstStageMask, dependencyFlags, |
| 3501 | memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 3502 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 3503 | skip = pipeline_barrier.Validate(*cb_access_context); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3504 | return skip; |
| 3505 | } |
| 3506 | |
| 3507 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3508 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3509 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3510 | uint32_t bufferMemoryBarrierCount, |
| 3511 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3512 | uint32_t imageMemoryBarrierCount, |
| 3513 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3514 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3515 | assert(cb_access_context); |
| 3516 | if (!cb_access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3517 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 3518 | SyncOpPipelineBarrier pipeline_barrier(*this, cb_access_context->GetQueueFlags(), srcStageMask, dstStageMask, dependencyFlags, |
| 3519 | memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 3520 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 3521 | pipeline_barrier.Record(cb_access_context, cb_access_context->NextCommandTag(CMD_PIPELINEBARRIER)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | void SyncValidator::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 3525 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result) { |
| 3526 | // The state tracker sets up the device state |
| 3527 | StateTracker::PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, result); |
| 3528 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3529 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 3530 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3531 | // TODO: Find a good way to do this hooklessly. |
| 3532 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 3533 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, LayerObjectTypeSyncValidation); |
| 3534 | SyncValidator *sync_device_state = static_cast<SyncValidator *>(validation_data); |
| 3535 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3536 | sync_device_state->SetCommandBufferResetCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3537 | sync_device_state->ResetCommandBufferCallback(command_buffer); |
| 3538 | }); |
| 3539 | sync_device_state->SetCommandBufferFreeCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 3540 | sync_device_state->FreeCommandBufferCallback(command_buffer); |
| 3541 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 3542 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3543 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3544 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3545 | const VkSubpassBeginInfo *pSubpassBeginInfo, const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3546 | bool skip = false; |
| 3547 | const auto rp_state = Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
| 3548 | auto cb_context = GetAccessContext(commandBuffer); |
| 3549 | |
| 3550 | if (rp_state && cb_context) { |
| 3551 | skip |= cb_context->ValidateBeginRenderPass(*rp_state, pRenderPassBegin, pSubpassBeginInfo, func_name); |
| 3552 | } |
| 3553 | |
| 3554 | return skip; |
| 3555 | } |
| 3556 | |
| 3557 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3558 | VkSubpassContents contents) const { |
| 3559 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3560 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3561 | subpass_begin_info.contents = contents; |
| 3562 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, "vkCmdBeginRenderPass"); |
| 3563 | return skip; |
| 3564 | } |
| 3565 | |
| 3566 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3567 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3568 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 3569 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, "vkCmdBeginRenderPass2"); |
| 3570 | return skip; |
| 3571 | } |
| 3572 | |
| 3573 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3574 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3575 | const VkSubpassBeginInfo *pSubpassBeginInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3576 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 3577 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, "vkCmdBeginRenderPass2KHR"); |
| 3578 | return skip; |
| 3579 | } |
| 3580 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3581 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 3582 | VkResult result) { |
| 3583 | // The state tracker sets up the command buffer state |
| 3584 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 3585 | |
| 3586 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 3587 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 3588 | assert(cb_access_context); |
| 3589 | cb_access_context->Reset(); |
| 3590 | } |
| 3591 | |
| 3592 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3593 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE command) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3594 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3595 | if (cb_context) { |
| 3596 | cb_context->RecordBeginRenderPass(cb_context->NextCommandTag(command)); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3597 | } |
| 3598 | } |
| 3599 | |
| 3600 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3601 | VkSubpassContents contents) { |
| 3602 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3603 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3604 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3605 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3609 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3610 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3611 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3615 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3616 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3617 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3618 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
| 3619 | } |
| 3620 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3621 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3622 | const VkSubpassEndInfo *pSubpassEndInfo, const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3623 | bool skip = false; |
| 3624 | |
| 3625 | auto cb_context = GetAccessContext(commandBuffer); |
| 3626 | assert(cb_context); |
| 3627 | auto cb_state = cb_context->GetCommandBufferState(); |
| 3628 | if (!cb_state) return skip; |
| 3629 | |
| 3630 | auto rp_state = cb_state->activeRenderPass; |
| 3631 | if (!rp_state) return skip; |
| 3632 | |
| 3633 | skip |= cb_context->ValidateNextSubpass(func_name); |
| 3634 | |
| 3635 | return skip; |
| 3636 | } |
| 3637 | |
| 3638 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 3639 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3640 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3641 | subpass_begin_info.contents = contents; |
| 3642 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, "vkCmdNextSubpass"); |
| 3643 | return skip; |
| 3644 | } |
| 3645 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3646 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3647 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3648 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
| 3649 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, "vkCmdNextSubpass2KHR"); |
| 3650 | return skip; |
| 3651 | } |
| 3652 | |
| 3653 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3654 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 3655 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
| 3656 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, "vkCmdNextSubpass2"); |
| 3657 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3661 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE command) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3662 | auto cb_context = GetAccessContext(commandBuffer); |
| 3663 | assert(cb_context); |
| 3664 | auto cb_state = cb_context->GetCommandBufferState(); |
| 3665 | if (!cb_state) return; |
| 3666 | |
| 3667 | auto rp_state = cb_state->activeRenderPass; |
| 3668 | if (!rp_state) return; |
| 3669 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3670 | cb_context->RecordNextSubpass(*rp_state, command); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 3674 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 3675 | auto subpass_begin_info = LvlInitStruct<VkSubpassBeginInfo>(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3676 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3677 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3681 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3682 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3683 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3687 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3688 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3689 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3690 | } |
| 3691 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3692 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3693 | const char *func_name) const { |
| 3694 | bool skip = false; |
| 3695 | |
| 3696 | auto cb_context = GetAccessContext(commandBuffer); |
| 3697 | assert(cb_context); |
| 3698 | auto cb_state = cb_context->GetCommandBufferState(); |
| 3699 | if (!cb_state) return skip; |
| 3700 | |
| 3701 | auto rp_state = cb_state->activeRenderPass; |
| 3702 | if (!rp_state) return skip; |
| 3703 | |
| 3704 | skip |= cb_context->ValidateEndRenderpass(func_name); |
| 3705 | return skip; |
| 3706 | } |
| 3707 | |
| 3708 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 3709 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
| 3710 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, "vkEndRenderPass"); |
| 3711 | return skip; |
| 3712 | } |
| 3713 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3714 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3715 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
| 3716 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, "vkEndRenderPass2"); |
| 3717 | return skip; |
| 3718 | } |
| 3719 | |
| 3720 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3721 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3722 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
| 3723 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, "vkEndRenderPass2KHR"); |
| 3724 | return skip; |
| 3725 | } |
| 3726 | |
| 3727 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
| 3728 | CMD_TYPE command) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3729 | // Resolve the all subpass contexts to the command buffer contexts |
| 3730 | auto cb_context = GetAccessContext(commandBuffer); |
| 3731 | assert(cb_context); |
| 3732 | auto cb_state = cb_context->GetCommandBufferState(); |
| 3733 | if (!cb_state) return; |
| 3734 | |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 3735 | const auto *rp_state = cb_state->activeRenderPass.get(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3736 | if (!rp_state) return; |
| 3737 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3738 | cb_context->RecordEndRenderPass(*rp_state, command); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3739 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3740 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 3741 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 3742 | // updates to a resource which do not conflict at the byte level. |
| 3743 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 3744 | // TODO: Add programatic control over suppression heuristics |
| 3745 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 3746 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 3747 | } |
| 3748 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3749 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3750 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3751 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3755 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3756 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3760 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3761 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3762 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3763 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3764 | template <typename BufferImageCopyRegionType> |
| 3765 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3766 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3767 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3768 | bool skip = false; |
| 3769 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3770 | assert(cb_access_context); |
| 3771 | if (!cb_access_context) return skip; |
| 3772 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3773 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3774 | const char *func_name = is_2khr ? "vkCmdCopyBufferToImage2KHR()" : "vkCmdCopyBufferToImage()"; |
| 3775 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3776 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3777 | assert(context); |
| 3778 | if (!context) return skip; |
| 3779 | |
| 3780 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3781 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3782 | |
| 3783 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3784 | const auto ©_region = pRegions[region]; |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3785 | HazardResult hazard; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3786 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3787 | if (src_buffer) { |
| 3788 | ResourceAccessRange src_range = |
| 3789 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
| 3790 | hazard = context->DetectHazard(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range); |
| 3791 | if (hazard.hazard) { |
| 3792 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 3793 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3794 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3795 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3796 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3797 | } |
| 3798 | } |
| 3799 | |
| 3800 | hazard = context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, copy_region.imageSubresource, |
| 3801 | copy_region.imageOffset, copy_region.imageExtent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3802 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3803 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3804 | "%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] | 3805 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3806 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3807 | } |
| 3808 | if (skip) break; |
| 3809 | } |
| 3810 | if (skip) break; |
| 3811 | } |
| 3812 | return skip; |
| 3813 | } |
| 3814 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3815 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3816 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3817 | const VkBufferImageCopy *pRegions) const { |
| 3818 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
| 3819 | COPY_COMMAND_VERSION_1); |
| 3820 | } |
| 3821 | |
| 3822 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3823 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 3824 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3825 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3826 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3827 | } |
| 3828 | |
| 3829 | template <typename BufferImageCopyRegionType> |
| 3830 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3831 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3832 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3833 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3834 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3835 | |
| 3836 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3837 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYBUFFERTOIMAGE2KHR : CMD_COPYBUFFERTOIMAGE; |
| 3838 | |
| 3839 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3840 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3841 | assert(context); |
| 3842 | |
| 3843 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3844 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3845 | |
| 3846 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3847 | const auto ©_region = pRegions[region]; |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3848 | if (dst_image) { |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3849 | if (src_buffer) { |
| 3850 | ResourceAccessRange src_range = |
| 3851 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
| 3852 | context->UpdateAccessState(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, SyncOrdering::kNonAttachment, src_range, tag); |
| 3853 | } |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3854 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
| 3855 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3856 | } |
| 3857 | } |
| 3858 | } |
| 3859 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3860 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3861 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3862 | const VkBufferImageCopy *pRegions) { |
| 3863 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
| 3864 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3865 | } |
| 3866 | |
| 3867 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3868 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 3869 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 3870 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3871 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3872 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3873 | } |
| 3874 | |
| 3875 | template <typename BufferImageCopyRegionType> |
| 3876 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3877 | VkBuffer dstBuffer, uint32_t regionCount, |
| 3878 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3879 | bool skip = false; |
| 3880 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3881 | assert(cb_access_context); |
| 3882 | if (!cb_access_context) return skip; |
| 3883 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3884 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3885 | const char *func_name = is_2khr ? "vkCmdCopyImageToBuffer2KHR()" : "vkCmdCopyImageToBuffer()"; |
| 3886 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3887 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3888 | assert(context); |
| 3889 | if (!context) return skip; |
| 3890 | |
| 3891 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3892 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3893 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->binding.mem_state->mem : VK_NULL_HANDLE; |
| 3894 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3895 | const auto ©_region = pRegions[region]; |
| 3896 | if (src_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3897 | auto hazard = context->DetectHazard(*src_image, SYNC_TRANSFER_TRANSFER_READ, copy_region.imageSubresource, |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3898 | copy_region.imageOffset, copy_region.imageExtent); |
| 3899 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3900 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3901 | "%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] | 3902 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3903 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3904 | } |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3905 | if (dst_mem) { |
| 3906 | ResourceAccessRange dst_range = |
| 3907 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
| 3908 | hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range); |
| 3909 | if (hazard.hazard) { |
| 3910 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3911 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
| 3912 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 3913 | cb_access_context->FormatUsage(hazard).c_str()); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3914 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3915 | } |
| 3916 | } |
| 3917 | if (skip) break; |
| 3918 | } |
| 3919 | return skip; |
| 3920 | } |
| 3921 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3922 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 3923 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 3924 | const VkBufferImageCopy *pRegions) const { |
| 3925 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
| 3926 | COPY_COMMAND_VERSION_1); |
| 3927 | } |
| 3928 | |
| 3929 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3930 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 3931 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3932 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3933 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3934 | } |
| 3935 | |
| 3936 | template <typename BufferImageCopyRegionType> |
| 3937 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3938 | VkBuffer dstBuffer, uint32_t regionCount, const BufferImageCopyRegionType *pRegions, |
| 3939 | CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3940 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3941 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3942 | |
| 3943 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3944 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYIMAGETOBUFFER2KHR : CMD_COPYIMAGETOBUFFER; |
| 3945 | |
| 3946 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3947 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3948 | assert(context); |
| 3949 | |
| 3950 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3951 | auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3952 | 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] | 3953 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3954 | |
| 3955 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3956 | const auto ©_region = pRegions[region]; |
| 3957 | if (src_image) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 3958 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, SyncOrdering::kNonAttachment, |
| 3959 | copy_region.imageSubresource, copy_region.imageOffset, copy_region.imageExtent, tag); |
John Zulauf | 477700e | 2021-01-06 11:41:49 -0700 | [diff] [blame] | 3960 | if (dst_buffer) { |
| 3961 | ResourceAccessRange dst_range = |
| 3962 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
| 3963 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, dst_range, tag); |
| 3964 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3965 | } |
| 3966 | } |
| 3967 | } |
| 3968 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3969 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3970 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 3971 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
| 3972 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3973 | } |
| 3974 | |
| 3975 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3976 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 3977 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 3978 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3979 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3980 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3981 | } |
| 3982 | |
| 3983 | template <typename RegionType> |
| 3984 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3985 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3986 | const RegionType *pRegions, VkFilter filter, const char *apiName) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3987 | bool skip = false; |
| 3988 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3989 | assert(cb_access_context); |
| 3990 | if (!cb_access_context) return skip; |
| 3991 | |
| 3992 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3993 | assert(context); |
| 3994 | if (!context) return skip; |
| 3995 | |
| 3996 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3997 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3998 | |
| 3999 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4000 | const auto &blit_region = pRegions[region]; |
| 4001 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4002 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4003 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4004 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4005 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4006 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4007 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].z - blit_region.srcOffsets[0].z))}; |
| 4008 | auto hazard = |
| 4009 | context->DetectHazard(*src_image, SYNC_TRANSFER_TRANSFER_READ, blit_region.srcSubresource, offset, extent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4010 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4011 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4012 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4013 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4014 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4015 | } |
| 4016 | } |
| 4017 | |
| 4018 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4019 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4020 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4021 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4022 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4023 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4024 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].z - blit_region.dstOffsets[0].z))}; |
| 4025 | auto hazard = |
| 4026 | context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, blit_region.dstSubresource, offset, extent); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4027 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 4028 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4029 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4030 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4031 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4032 | } |
| 4033 | if (skip) break; |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | return skip; |
| 4038 | } |
| 4039 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4040 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4041 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4042 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 4043 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
| 4044 | "vkCmdBlitImage"); |
| 4045 | } |
| 4046 | |
| 4047 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 4048 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 4049 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4050 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4051 | pBlitImageInfo->filter, "vkCmdBlitImage2KHR"); |
| 4052 | } |
| 4053 | |
| 4054 | template <typename RegionType> |
| 4055 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4056 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4057 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4058 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4059 | assert(cb_access_context); |
| 4060 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4061 | assert(context); |
| 4062 | |
| 4063 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4064 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4065 | |
| 4066 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4067 | const auto &blit_region = pRegions[region]; |
| 4068 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4069 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 4070 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 4071 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 4072 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 4073 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 4074 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].z - blit_region.srcOffsets[0].z))}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4075 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, SyncOrdering::kNonAttachment, |
| 4076 | blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4077 | } |
| 4078 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 4079 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 4080 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 4081 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 4082 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 4083 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 4084 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].z - blit_region.dstOffsets[0].z))}; |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4085 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
| 4086 | blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 4087 | } |
| 4088 | } |
| 4089 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4090 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4091 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4092 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4093 | const VkImageBlit *pRegions, VkFilter filter) { |
| 4094 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4095 | assert(cb_access_context); |
| 4096 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 4097 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4098 | pRegions, filter); |
| 4099 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 4100 | } |
| 4101 | |
| 4102 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 4103 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 4104 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4105 | assert(cb_access_context); |
| 4106 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 4107 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 4108 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 4109 | pBlitImageInfo->filter, tag); |
| 4110 | } |
| 4111 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4112 | bool SyncValidator::ValidateIndirectBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4113 | VkCommandBuffer commandBuffer, const VkDeviceSize struct_size, const VkBuffer buffer, |
| 4114 | const VkDeviceSize offset, const uint32_t drawCount, const uint32_t stride, |
| 4115 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4116 | bool skip = false; |
| 4117 | if (drawCount == 0) return skip; |
| 4118 | |
| 4119 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 4120 | VkDeviceSize size = struct_size; |
| 4121 | if (drawCount == 1 || stride == size) { |
| 4122 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4123 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4124 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4125 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4126 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4127 | "%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] | 4128 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4129 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4130 | } |
| 4131 | } else { |
| 4132 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4133 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4134 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4135 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4136 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4137 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
| 4138 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4139 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4140 | break; |
| 4141 | } |
| 4142 | } |
| 4143 | } |
| 4144 | return skip; |
| 4145 | } |
| 4146 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4147 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag &tag, const VkDeviceSize struct_size, |
| 4148 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 4149 | uint32_t stride) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4150 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 4151 | VkDeviceSize size = struct_size; |
| 4152 | if (drawCount == 1 || stride == size) { |
| 4153 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4154 | const ResourceAccessRange range = MakeRange(offset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4155 | 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] | 4156 | } else { |
| 4157 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4158 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4159 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, SyncOrdering::kNonAttachment, range, |
| 4160 | tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4161 | } |
| 4162 | } |
| 4163 | } |
| 4164 | |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4165 | bool SyncValidator::ValidateCountBuffer(const CommandBufferAccessContext &cb_context, const AccessContext &context, |
| 4166 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4167 | const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4168 | bool skip = false; |
| 4169 | |
| 4170 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4171 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4172 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 4173 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4174 | skip |= LogError(count_buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4175 | "%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] | 4176 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4177 | cb_context.FormatUsage(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4178 | } |
| 4179 | return skip; |
| 4180 | } |
| 4181 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4182 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag &tag, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4183 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4184 | const ResourceAccessRange range = MakeRange(offset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4185 | 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] | 4186 | } |
| 4187 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4188 | 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] | 4189 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4190 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4191 | assert(cb_access_context); |
| 4192 | if (!cb_access_context) return skip; |
| 4193 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4194 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4195 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | 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] | 4199 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4200 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4201 | assert(cb_access_context); |
| 4202 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4203 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4204 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 4205 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4206 | |
| 4207 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4208 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4209 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4210 | assert(cb_access_context); |
| 4211 | if (!cb_access_context) return skip; |
| 4212 | |
| 4213 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4214 | assert(context); |
| 4215 | if (!context) return skip; |
| 4216 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4217 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4218 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, |
| 4219 | 1, sizeof(VkDispatchIndirectCommand), "vkCmdDispatchIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4220 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4224 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4225 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4226 | assert(cb_access_context); |
| 4227 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 4228 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4229 | assert(context); |
| 4230 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4231 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 4232 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4236 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4237 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4238 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4239 | assert(cb_access_context); |
| 4240 | if (!cb_access_context) return skip; |
| 4241 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4242 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw"); |
| 4243 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, "vkCmdDraw"); |
| 4244 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDraw"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4245 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4249 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4250 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4251 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4252 | assert(cb_access_context); |
| 4253 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4254 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4255 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4256 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 4257 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4261 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4262 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4263 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4264 | assert(cb_access_context); |
| 4265 | if (!cb_access_context) return skip; |
| 4266 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4267 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed"); |
| 4268 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, "vkCmdDrawIndexed"); |
| 4269 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexed"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 4270 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 4274 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4275 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4276 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4277 | assert(cb_access_context); |
| 4278 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4279 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4280 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4281 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 4282 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4286 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4287 | bool skip = false; |
| 4288 | if (drawCount == 0) return skip; |
| 4289 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4290 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4291 | assert(cb_access_context); |
| 4292 | if (!cb_access_context) return skip; |
| 4293 | |
| 4294 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4295 | assert(context); |
| 4296 | if (!context) return skip; |
| 4297 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4298 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect"); |
| 4299 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4300 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4301 | drawCount, stride, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4302 | |
| 4303 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4304 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4305 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4306 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4307 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4311 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4312 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4313 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4314 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4315 | assert(cb_access_context); |
| 4316 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 4317 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4318 | assert(context); |
| 4319 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4320 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4321 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4322 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4323 | |
| 4324 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4325 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4326 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4327 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4331 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4332 | bool skip = false; |
| 4333 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4334 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4335 | assert(cb_access_context); |
| 4336 | if (!cb_access_context) return skip; |
| 4337 | |
| 4338 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4339 | assert(context); |
| 4340 | if (!context) return skip; |
| 4341 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4342 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect"); |
| 4343 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexedIndirect"); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4344 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4345 | offset, drawCount, stride, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4346 | |
| 4347 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4348 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4349 | // 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] | 4350 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4351 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4355 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4356 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4357 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4358 | assert(cb_access_context); |
| 4359 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 4360 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4361 | assert(context); |
| 4362 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4363 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4364 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4365 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4366 | |
| 4367 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4368 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4369 | // 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] | 4370 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4374 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4375 | uint32_t stride, const char *function) const { |
| 4376 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4377 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4378 | assert(cb_access_context); |
| 4379 | if (!cb_access_context) return skip; |
| 4380 | |
| 4381 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4382 | assert(context); |
| 4383 | if (!context) return skip; |
| 4384 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4385 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4386 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4387 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, |
| 4388 | maxDrawCount, stride, function); |
| 4389 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4390 | |
| 4391 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 4392 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4393 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4394 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4395 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4399 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4400 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4401 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4402 | "vkCmdDrawIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4406 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4407 | uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4408 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4409 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4410 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4411 | assert(cb_access_context); |
| 4412 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECTCOUNT); |
| 4413 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4414 | assert(context); |
| 4415 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4416 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4417 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4418 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 4419 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4420 | |
| 4421 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 4422 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 4423 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4424 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4425 | } |
| 4426 | |
| 4427 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4428 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4429 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4430 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4431 | "vkCmdDrawIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4435 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4436 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4437 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4438 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4439 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4443 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4444 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4445 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4446 | "vkCmdDrawIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4450 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4451 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4452 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 4453 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4454 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4455 | } |
| 4456 | |
| 4457 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4458 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4459 | uint32_t stride, const char *function) const { |
| 4460 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4461 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4462 | assert(cb_access_context); |
| 4463 | if (!cb_access_context) return skip; |
| 4464 | |
| 4465 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4466 | assert(context); |
| 4467 | if (!context) return skip; |
| 4468 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4469 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 4470 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4471 | skip |= ValidateIndirectBuffer(*cb_access_context, *context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, |
| 4472 | offset, maxDrawCount, stride, function); |
| 4473 | skip |= ValidateCountBuffer(*cb_access_context, *context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4474 | |
| 4475 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 4476 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 4477 | // 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] | 4478 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4479 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4483 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4484 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4485 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4486 | "vkCmdDrawIndexedIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4490 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4491 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4492 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4493 | maxDrawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4494 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4495 | assert(cb_access_context); |
| 4496 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 4497 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4498 | assert(context); |
| 4499 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4500 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 4501 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 4502 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 4503 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4504 | |
| 4505 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 4506 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 4507 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 4508 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4509 | } |
| 4510 | |
| 4511 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4512 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4513 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4514 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4515 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4516 | "vkCmdDrawIndexedIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4520 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4521 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4522 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4523 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4524 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4525 | } |
| 4526 | |
| 4527 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4528 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4529 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4530 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4531 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4532 | "vkCmdDrawIndexedIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4536 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4537 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4538 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 4539 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4540 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 4541 | } |
| 4542 | |
| 4543 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4544 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4545 | const VkImageSubresourceRange *pRanges) const { |
| 4546 | bool skip = false; |
| 4547 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4548 | assert(cb_access_context); |
| 4549 | if (!cb_access_context) return skip; |
| 4550 | |
| 4551 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4552 | assert(context); |
| 4553 | if (!context) return skip; |
| 4554 | |
| 4555 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4556 | |
| 4557 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4558 | const auto &range = pRanges[index]; |
| 4559 | if (image_state) { |
| 4560 | auto hazard = |
| 4561 | context->DetectHazard(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent); |
| 4562 | if (hazard.hazard) { |
| 4563 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4564 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4565 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4566 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4567 | } |
| 4568 | } |
| 4569 | } |
| 4570 | return skip; |
| 4571 | } |
| 4572 | |
| 4573 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4574 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4575 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4576 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4577 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4578 | assert(cb_access_context); |
| 4579 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 4580 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4581 | assert(context); |
| 4582 | |
| 4583 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4584 | |
| 4585 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4586 | const auto &range = pRanges[index]; |
| 4587 | if (image_state) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4588 | context->UpdateAccessState(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, {0, 0, 0}, |
| 4589 | image_state->createInfo.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4590 | } |
| 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 4595 | VkImageLayout imageLayout, |
| 4596 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4597 | const VkImageSubresourceRange *pRanges) const { |
| 4598 | bool skip = false; |
| 4599 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4600 | assert(cb_access_context); |
| 4601 | if (!cb_access_context) return skip; |
| 4602 | |
| 4603 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4604 | assert(context); |
| 4605 | if (!context) return skip; |
| 4606 | |
| 4607 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4608 | |
| 4609 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4610 | const auto &range = pRanges[index]; |
| 4611 | if (image_state) { |
| 4612 | auto hazard = |
| 4613 | context->DetectHazard(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent); |
| 4614 | if (hazard.hazard) { |
| 4615 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4616 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4617 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4618 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4619 | } |
| 4620 | } |
| 4621 | } |
| 4622 | return skip; |
| 4623 | } |
| 4624 | |
| 4625 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4626 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4627 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4628 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4629 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4630 | assert(cb_access_context); |
| 4631 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 4632 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4633 | assert(context); |
| 4634 | |
| 4635 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4636 | |
| 4637 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4638 | const auto &range = pRanges[index]; |
| 4639 | if (image_state) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4640 | context->UpdateAccessState(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, {0, 0, 0}, |
| 4641 | image_state->createInfo.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4642 | } |
| 4643 | } |
| 4644 | } |
| 4645 | |
| 4646 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4647 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 4648 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 4649 | VkQueryResultFlags flags) const { |
| 4650 | bool skip = false; |
| 4651 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4652 | assert(cb_access_context); |
| 4653 | if (!cb_access_context) return skip; |
| 4654 | |
| 4655 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4656 | assert(context); |
| 4657 | if (!context) return skip; |
| 4658 | |
| 4659 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4660 | |
| 4661 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4662 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4663 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 4664 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4665 | skip |= |
| 4666 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4667 | "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] | 4668 | 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] | 4669 | } |
| 4670 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4671 | |
| 4672 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4673 | return skip; |
| 4674 | } |
| 4675 | |
| 4676 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 4677 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4678 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4679 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 4680 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4681 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4682 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4683 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4684 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4685 | assert(context); |
| 4686 | |
| 4687 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4688 | |
| 4689 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4690 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4691 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4692 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4693 | |
| 4694 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4698 | VkDeviceSize size, uint32_t data) const { |
| 4699 | bool skip = false; |
| 4700 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4701 | assert(cb_access_context); |
| 4702 | if (!cb_access_context) return skip; |
| 4703 | |
| 4704 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4705 | assert(context); |
| 4706 | if (!context) return skip; |
| 4707 | |
| 4708 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4709 | |
| 4710 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4711 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4712 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 4713 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4714 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4715 | "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] | 4716 | 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] | 4717 | } |
| 4718 | } |
| 4719 | return skip; |
| 4720 | } |
| 4721 | |
| 4722 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4723 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4724 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4725 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4726 | assert(cb_access_context); |
| 4727 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 4728 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4729 | assert(context); |
| 4730 | |
| 4731 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4732 | |
| 4733 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4734 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4735 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4736 | } |
| 4737 | } |
| 4738 | |
| 4739 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4740 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4741 | const VkImageResolve *pRegions) const { |
| 4742 | bool skip = false; |
| 4743 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4744 | assert(cb_access_context); |
| 4745 | if (!cb_access_context) return skip; |
| 4746 | |
| 4747 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4748 | assert(context); |
| 4749 | if (!context) return skip; |
| 4750 | |
| 4751 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4752 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4753 | |
| 4754 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4755 | const auto &resolve_region = pRegions[region]; |
| 4756 | if (src_image) { |
| 4757 | auto hazard = context->DetectHazard(*src_image, SYNC_TRANSFER_TRANSFER_READ, resolve_region.srcSubresource, |
| 4758 | resolve_region.srcOffset, resolve_region.extent); |
| 4759 | if (hazard.hazard) { |
| 4760 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4761 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4762 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4763 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4764 | } |
| 4765 | } |
| 4766 | |
| 4767 | if (dst_image) { |
| 4768 | auto hazard = context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, resolve_region.dstSubresource, |
| 4769 | resolve_region.dstOffset, resolve_region.extent); |
| 4770 | if (hazard.hazard) { |
| 4771 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4772 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4773 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4774 | cb_access_context->FormatUsage(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4775 | } |
| 4776 | if (skip) break; |
| 4777 | } |
| 4778 | } |
| 4779 | |
| 4780 | return skip; |
| 4781 | } |
| 4782 | |
| 4783 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4784 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4785 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4786 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4787 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4788 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4789 | assert(cb_access_context); |
| 4790 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 4791 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4792 | assert(context); |
| 4793 | |
| 4794 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4795 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4796 | |
| 4797 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4798 | const auto &resolve_region = pRegions[region]; |
| 4799 | if (src_image) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4800 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, SyncOrdering::kNonAttachment, |
| 4801 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4802 | } |
| 4803 | if (dst_image) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4804 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
| 4805 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4806 | } |
| 4807 | } |
| 4808 | } |
| 4809 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4810 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4811 | const VkResolveImageInfo2KHR *pResolveImageInfo) const { |
| 4812 | bool skip = false; |
| 4813 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4814 | assert(cb_access_context); |
| 4815 | if (!cb_access_context) return skip; |
| 4816 | |
| 4817 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4818 | assert(context); |
| 4819 | if (!context) return skip; |
| 4820 | |
| 4821 | const auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4822 | const auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4823 | |
| 4824 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4825 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4826 | if (src_image) { |
| 4827 | auto hazard = context->DetectHazard(*src_image, SYNC_TRANSFER_TRANSFER_READ, resolve_region.srcSubresource, |
| 4828 | resolve_region.srcOffset, resolve_region.extent); |
| 4829 | if (hazard.hazard) { |
| 4830 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 4831 | "vkCmdResolveImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 4832 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4833 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4834 | } |
| 4835 | } |
| 4836 | |
| 4837 | if (dst_image) { |
| 4838 | auto hazard = context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, resolve_region.dstSubresource, |
| 4839 | resolve_region.dstOffset, resolve_region.extent); |
| 4840 | if (hazard.hazard) { |
| 4841 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 4842 | "vkCmdResolveImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 4843 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
John Zulauf | faea0ee | 2021-01-14 14:01:32 -0700 | [diff] [blame] | 4844 | region, cb_access_context->FormatUsage(hazard).c_str()); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4845 | } |
| 4846 | if (skip) break; |
| 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | return skip; |
| 4851 | } |
| 4852 | |
| 4853 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4854 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 4855 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 4856 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4857 | assert(cb_access_context); |
| 4858 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE2KHR); |
| 4859 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4860 | assert(context); |
| 4861 | |
| 4862 | auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4863 | auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4864 | |
| 4865 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4866 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4867 | if (src_image) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4868 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, SyncOrdering::kNonAttachment, |
| 4869 | resolve_region.srcSubresource, resolve_region.srcOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4870 | } |
| 4871 | if (dst_image) { |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4872 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, |
| 4873 | resolve_region.dstSubresource, resolve_region.dstOffset, resolve_region.extent, tag); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4874 | } |
| 4875 | } |
| 4876 | } |
| 4877 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4878 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4879 | VkDeviceSize dataSize, const void *pData) const { |
| 4880 | bool skip = false; |
| 4881 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4882 | assert(cb_access_context); |
| 4883 | if (!cb_access_context) return skip; |
| 4884 | |
| 4885 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4886 | assert(context); |
| 4887 | if (!context) return skip; |
| 4888 | |
| 4889 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4890 | |
| 4891 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4892 | // VK_WHOLE_SIZE not allowed |
| 4893 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4894 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 4895 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4896 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4897 | "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] | 4898 | 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] | 4899 | } |
| 4900 | } |
| 4901 | return skip; |
| 4902 | } |
| 4903 | |
| 4904 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4905 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4906 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4907 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4908 | assert(cb_access_context); |
| 4909 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 4910 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4911 | assert(context); |
| 4912 | |
| 4913 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4914 | |
| 4915 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4916 | // VK_WHOLE_SIZE not allowed |
| 4917 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4918 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4919 | } |
| 4920 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4921 | |
| 4922 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4923 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 4924 | bool skip = false; |
| 4925 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4926 | assert(cb_access_context); |
| 4927 | if (!cb_access_context) return skip; |
| 4928 | |
| 4929 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4930 | assert(context); |
| 4931 | if (!context) return skip; |
| 4932 | |
| 4933 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4934 | |
| 4935 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4936 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4937 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 4938 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4939 | skip |= |
| 4940 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4941 | "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] | 4942 | 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] | 4943 | } |
| 4944 | } |
| 4945 | return skip; |
| 4946 | } |
| 4947 | |
| 4948 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4949 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4950 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4951 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4952 | assert(cb_access_context); |
| 4953 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 4954 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4955 | assert(context); |
| 4956 | |
| 4957 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4958 | |
| 4959 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4960 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
John Zulauf | 8e3c3e9 | 2021-01-06 11:19:36 -0700 | [diff] [blame] | 4961 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, SyncOrdering::kNonAttachment, range, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4962 | } |
| 4963 | } |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4964 | |
| 4965 | bool SyncValidator::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
| 4966 | bool skip = false; |
| 4967 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4968 | assert(cb_context); |
| 4969 | if (!cb_context) return skip; |
| 4970 | |
| 4971 | return cb_context->ValidateSetEvent(commandBuffer, event, stageMask); |
| 4972 | } |
| 4973 | |
| 4974 | void SyncValidator::PostCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 4975 | StateTracker::PostCallRecordCmdSetEvent(commandBuffer, event, stageMask); |
| 4976 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4977 | assert(cb_context); |
| 4978 | if (!cb_context) return; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 4979 | const auto tag = cb_context->NextCommandTag(CMD_SETEVENT); |
| 4980 | cb_context->RecordSetEvent(commandBuffer, event, stageMask, tag); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 4981 | } |
| 4982 | |
| 4983 | bool SyncValidator::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4984 | VkPipelineStageFlags stageMask) const { |
| 4985 | bool skip = false; |
| 4986 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 4987 | assert(cb_context); |
| 4988 | if (!cb_context) return skip; |
| 4989 | |
| 4990 | return cb_context->ValidateResetEvent(commandBuffer, event, stageMask); |
| 4991 | } |
| 4992 | |
| 4993 | void SyncValidator::PostCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 4994 | StateTracker::PostCallRecordCmdResetEvent(commandBuffer, event, stageMask); |
| 4995 | auto *cb_context = GetAccessContext(commandBuffer); |
| 4996 | assert(cb_context); |
| 4997 | if (!cb_context) return; |
| 4998 | |
| 4999 | cb_context->RecordResetEvent(commandBuffer, event, stageMask); |
| 5000 | } |
| 5001 | |
| 5002 | bool SyncValidator::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5003 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5004 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5005 | uint32_t bufferMemoryBarrierCount, |
| 5006 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5007 | uint32_t imageMemoryBarrierCount, |
| 5008 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 5009 | bool skip = false; |
| 5010 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 5011 | assert(cb_context); |
| 5012 | if (!cb_context) return skip; |
| 5013 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5014 | SyncOpWaitEvents wait_events_op(*this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, dstStageMask, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5015 | memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 5016 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 5017 | return wait_events_op.Validate(*cb_context); |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | void SyncValidator::PostCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 5021 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5022 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5023 | uint32_t bufferMemoryBarrierCount, |
| 5024 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5025 | uint32_t imageMemoryBarrierCount, |
| 5026 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 5027 | StateTracker::PostCallRecordCmdWaitEvents(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, |
| 5028 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 5029 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 5030 | |
| 5031 | auto *cb_context = GetAccessContext(commandBuffer); |
| 5032 | assert(cb_context); |
| 5033 | if (!cb_context) return; |
| 5034 | |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5035 | const auto tag = cb_context->NextCommandTag(CMD_WAITEVENTS); |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5036 | SyncOpWaitEvents wait_events_op(*this, cb_context->GetQueueFlags(), eventCount, pEvents, srcStageMask, dstStageMask, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5037 | memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 5038 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 5039 | return wait_events_op.Record(cb_context, tag); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | void SyncEventState::ResetFirstScope() { |
| 5043 | for (const auto address_type : kAddressTypes) { |
| 5044 | first_scope[static_cast<size_t>(address_type)].clear(); |
| 5045 | } |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 5046 | scope = SyncExecScope(); |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
| 5049 | // Keep the "ignore this event" logic in same place for ValidateWait and RecordWait to use |
| 5050 | SyncEventState::IgnoreReason SyncEventState::IsIgnoredByWait(VkPipelineStageFlags srcStageMask) const { |
| 5051 | IgnoreReason reason = NotIgnored; |
| 5052 | |
| 5053 | if (last_command == CMD_RESETEVENT && !HasBarrier(0U, 0U)) { |
| 5054 | reason = ResetWaitRace; |
| 5055 | } else if (unsynchronized_set) { |
| 5056 | reason = SetRace; |
| 5057 | } else { |
Jeremy Gebben | 9893daf | 2021-01-04 10:40:50 -0700 | [diff] [blame] | 5058 | const VkPipelineStageFlags missing_bits = scope.mask_param & ~srcStageMask; |
John Zulauf | 4a6105a | 2020-11-17 15:11:05 -0700 | [diff] [blame] | 5059 | if (missing_bits) reason = MissingStageBits; |
| 5060 | } |
| 5061 | |
| 5062 | return reason; |
| 5063 | } |
| 5064 | |
| 5065 | bool SyncEventState::HasBarrier(VkPipelineStageFlags stageMask, VkPipelineStageFlags exec_scope_arg) const { |
| 5066 | bool has_barrier = (last_command == CMD_NONE) || (stageMask & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) || |
| 5067 | (barriers & exec_scope_arg) || (barriers & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 5068 | return has_barrier; |
John Zulauf | 49beb11 | 2020-11-04 16:06:31 -0700 | [diff] [blame] | 5069 | } |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5070 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5071 | SyncOpBarriers::SyncOpBarriers(const SyncValidator &sync_state, VkQueueFlags queue_flags, VkPipelineStageFlags srcStageMask, |
| 5072 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 5073 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5074 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5075 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5076 | : dependency_flags_(dependencyFlags), |
| 5077 | src_exec_scope_(SyncExecScope::MakeSrc(queue_flags, srcStageMask)), |
| 5078 | dst_exec_scope_(SyncExecScope::MakeDst(queue_flags, dstStageMask)) { |
| 5079 | // Translate the API parameters into structures SyncVal understands directly, and dehandle for safer/faster replay. |
| 5080 | MakeMemoryBarriers(src_exec_scope_, dst_exec_scope_, dependencyFlags, memoryBarrierCount, pMemoryBarriers); |
| 5081 | MakeBufferMemoryBarriers(sync_state, src_exec_scope_, dst_exec_scope_, dependencyFlags, bufferMemoryBarrierCount, |
| 5082 | pBufferMemoryBarriers); |
| 5083 | MakeImageMemoryBarriers(sync_state, src_exec_scope_, dst_exec_scope_, dependencyFlags, imageMemoryBarrierCount, |
| 5084 | pImageMemoryBarriers); |
| 5085 | } |
| 5086 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5087 | SyncOpPipelineBarrier::SyncOpPipelineBarrier(const SyncValidator &sync_state, VkQueueFlags queue_flags, |
| 5088 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5089 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, |
| 5090 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 5091 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 5092 | const VkImageMemoryBarrier *pImageMemoryBarriers) |
| 5093 | : SyncOpBarriers(sync_state, queue_flags, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, |
| 5094 | bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers) {} |
| 5095 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5096 | bool SyncOpPipelineBarrier::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5097 | bool skip = false; |
| 5098 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5099 | assert(context); |
| 5100 | if (!context) return skip; |
| 5101 | // Validate Image Layout transitions |
Nathaniel Cesario | e3025c6 | 2021-02-03 16:36:22 -0700 | [diff] [blame] | 5102 | for (const auto &image_barrier : image_memory_barriers_) { |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5103 | if (image_barrier.new_layout == image_barrier.old_layout) continue; // Only interested in layout transitions at this point. |
| 5104 | const auto *image_state = image_barrier.image.get(); |
| 5105 | if (!image_state) continue; |
| 5106 | const auto hazard = context->DetectImageBarrierHazard(image_barrier); |
| 5107 | if (hazard.hazard) { |
| 5108 | // PHASE1 TODO -- add tag information to log msg when useful. |
| 5109 | const auto &sync_state = cb_context.GetSyncState(); |
| 5110 | const auto image_handle = image_state->image; |
| 5111 | skip |= sync_state.LogError(image_handle, string_SyncHazardVUID(hazard.hazard), |
| 5112 | "vkCmdPipelineBarrier: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", |
| 5113 | string_SyncHazard(hazard.hazard), image_barrier.index, |
| 5114 | sync_state.report_data->FormatHandle(image_handle).c_str(), |
| 5115 | cb_context.FormatUsage(hazard).c_str()); |
| 5116 | } |
| 5117 | } |
| 5118 | |
| 5119 | return skip; |
| 5120 | } |
| 5121 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5122 | struct SyncOpPipelineBarrierFunctorFactory { |
| 5123 | using BarrierOpFunctor = PipelineBarrierOp; |
| 5124 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5125 | using GlobalBarrierOpFunctor = PipelineBarrierOp; |
| 5126 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5127 | using BufferRange = ResourceAccessRange; |
| 5128 | using ImageRange = subresource_adapter::ImageRangeGenerator; |
| 5129 | using GlobalRange = ResourceAccessRange; |
| 5130 | |
| 5131 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier, bool layout_transition) const { |
| 5132 | return ApplyFunctor(BarrierOpFunctor(barrier, layout_transition)); |
| 5133 | } |
| 5134 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, const ResourceUsageTag &tag) const { |
| 5135 | return GlobalApplyFunctor(true /* resolve */, size_hint, tag); |
| 5136 | } |
| 5137 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier) const { |
| 5138 | return GlobalBarrierOpFunctor(barrier, false); |
| 5139 | } |
| 5140 | |
| 5141 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range) const { |
| 5142 | if (!SimpleBinding(buffer)) return ResourceAccessRange(); |
| 5143 | const auto base_address = ResourceBaseAddress(buffer); |
| 5144 | return (range + base_address); |
| 5145 | } |
| 5146 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const SyncImageMemoryBarrier::SubImageRange &range) const { |
| 5147 | if (!SimpleBinding(image)) subresource_adapter::ImageRangeGenerator(); |
| 5148 | |
| 5149 | const auto base_address = ResourceBaseAddress(image); |
| 5150 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), range.subresource_range, range.offset, |
| 5151 | range.extent, base_address); |
| 5152 | return range_gen; |
| 5153 | } |
| 5154 | GlobalRange MakeGlobalRangeGen(AccessAddressType) const { return kFullRange; } |
| 5155 | }; |
| 5156 | |
| 5157 | template <typename Barriers, typename FunctorFactory> |
| 5158 | void SyncOpBarriers::ApplyBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag &tag, |
| 5159 | AccessContext *context) { |
| 5160 | for (const auto &barrier : barriers) { |
| 5161 | const auto *state = barrier.GetState(); |
| 5162 | if (state) { |
| 5163 | auto *const accesses = &context->GetAccessStateMap(GetAccessAddressType(*state)); |
| 5164 | auto update_action = factory.MakeApplyFunctor(barrier.barrier, barrier.IsLayoutTransition()); |
| 5165 | auto range_gen = factory.MakeRangeGen(*state, barrier.Range()); |
| 5166 | UpdateMemoryAccessState(accesses, update_action, &range_gen); |
| 5167 | } |
| 5168 | } |
| 5169 | } |
| 5170 | |
| 5171 | template <typename Barriers, typename FunctorFactory> |
| 5172 | void SyncOpBarriers::ApplyGlobalBarriers(const Barriers &barriers, const FunctorFactory &factory, const ResourceUsageTag &tag, |
| 5173 | AccessContext *access_context) { |
| 5174 | auto barriers_functor = factory.MakeGlobalApplyFunctor(barriers.size(), tag); |
| 5175 | for (const auto &barrier : barriers) { |
| 5176 | barriers_functor.EmplaceBack(factory.MakeGlobalBarrierOpFunctor(barrier)); |
| 5177 | } |
| 5178 | for (const auto address_type : kAddressTypes) { |
| 5179 | auto range_gen = factory.MakeGlobalRangeGen(address_type); |
| 5180 | UpdateMemoryAccessState(&(access_context->GetAccessStateMap(address_type)), barriers_functor, &range_gen); |
| 5181 | } |
| 5182 | } |
| 5183 | |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5184 | void SyncOpPipelineBarrier::Record(CommandBufferAccessContext *cb_context, const ResourceUsageTag &tag) const { |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5185 | SyncOpPipelineBarrierFunctorFactory factory; |
| 5186 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5187 | ApplyBarriers(buffer_memory_barriers_, factory, tag, access_context); |
| 5188 | ApplyBarriers(image_memory_barriers_, factory, tag, access_context); |
| 5189 | ApplyGlobalBarriers(memory_barriers_, factory, tag, access_context); |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5190 | |
| 5191 | cb_context->ApplyGlobalBarriersToEvents(src_exec_scope_, dst_exec_scope_); |
| 5192 | } |
| 5193 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5194 | void SyncOpBarriers::MakeMemoryBarriers(const SyncExecScope &src, const SyncExecScope &dst, VkDependencyFlags dependency_flags, |
| 5195 | uint32_t memory_barrier_count, const VkMemoryBarrier *memory_barriers) { |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5196 | memory_barriers_.reserve(std::min<uint32_t>(1, memory_barrier_count)); |
| 5197 | for (uint32_t barrier_index = 0; barrier_index < memory_barrier_count; barrier_index++) { |
| 5198 | const auto &barrier = memory_barriers[barrier_index]; |
| 5199 | SyncBarrier sync_barrier(barrier, src, dst); |
| 5200 | memory_barriers_.emplace_back(sync_barrier); |
| 5201 | } |
| 5202 | if (0 == memory_barrier_count) { |
| 5203 | // If there are no global memory barriers, force an exec barrier |
| 5204 | memory_barriers_.emplace_back(SyncBarrier(src, dst)); |
| 5205 | } |
| 5206 | } |
| 5207 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5208 | void SyncOpBarriers::MakeBufferMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, const SyncExecScope &dst, |
| 5209 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5210 | const VkBufferMemoryBarrier *barriers) { |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5211 | buffer_memory_barriers_.reserve(barrier_count); |
| 5212 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5213 | const auto &barrier = barriers[index]; |
| 5214 | auto buffer = sync_state.GetShared<BUFFER_STATE>(barrier.buffer); |
| 5215 | if (buffer) { |
| 5216 | const auto barrier_size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 5217 | const auto range = MakeRange(barrier.offset, barrier_size); |
| 5218 | const SyncBarrier sync_barrier(barrier, src, dst); |
| 5219 | buffer_memory_barriers_.emplace_back(buffer, sync_barrier, range); |
| 5220 | } else { |
| 5221 | buffer_memory_barriers_.emplace_back(); |
| 5222 | } |
| 5223 | } |
| 5224 | } |
| 5225 | |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5226 | void SyncOpBarriers::MakeImageMemoryBarriers(const SyncValidator &sync_state, const SyncExecScope &src, const SyncExecScope &dst, |
| 5227 | VkDependencyFlags dependencyFlags, uint32_t barrier_count, |
| 5228 | const VkImageMemoryBarrier *barriers) { |
John Zulauf | e7f6a5e | 2021-01-16 14:31:18 -0700 | [diff] [blame] | 5229 | image_memory_barriers_.reserve(barrier_count); |
| 5230 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 5231 | const auto &barrier = barriers[index]; |
| 5232 | const auto image = sync_state.GetShared<IMAGE_STATE>(barrier.image); |
| 5233 | if (image) { |
| 5234 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
| 5235 | const SyncBarrier sync_barrier(barrier, src, dst); |
| 5236 | image_memory_barriers_.emplace_back(image, index, sync_barrier, barrier.oldLayout, barrier.newLayout, |
| 5237 | subresource_range); |
| 5238 | } else { |
| 5239 | image_memory_barriers_.emplace_back(); |
| 5240 | image_memory_barriers_.back().index = index; // Just in case we're interested in the ones we skipped. |
| 5241 | } |
| 5242 | } |
| 5243 | } |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5244 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5245 | SyncOpWaitEvents::SyncOpWaitEvents(const SyncValidator &sync_state, VkQueueFlags queue_flags, uint32_t eventCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5246 | const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 5247 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 5248 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 5249 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5250 | : SyncOpBarriers(sync_state, queue_flags, srcStageMask, dstStageMask, VkDependencyFlags(0U), memoryBarrierCount, |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5251 | pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, |
| 5252 | pImageMemoryBarriers) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5253 | MakeEventsList(sync_state, eventCount, pEvents); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5254 | } |
| 5255 | |
| 5256 | bool SyncOpWaitEvents::Validate(const CommandBufferAccessContext &cb_context) const { |
| 5257 | const auto cmd = CMD_WAITEVENTS; |
| 5258 | const char *const ignored = "Wait operation is ignored for this event."; |
| 5259 | bool skip = false; |
| 5260 | const auto &sync_state = cb_context.GetSyncState(); |
| 5261 | const auto command_buffer_handle = cb_context.GetCBState().commandBuffer; |
| 5262 | |
| 5263 | if (src_exec_scope_.mask_param & VK_PIPELINE_STAGE_HOST_BIT) { |
| 5264 | const char *const cmd_name = CommandTypeString(cmd); |
| 5265 | const char *const vuid = "SYNC-vkCmdWaitEvents-hostevent-unsupported"; |
| 5266 | skip = sync_state.LogInfo(command_buffer_handle, vuid, |
| 5267 | "%s, srcStageMask includes %s, unsupported by synchronization validaton.", cmd_name, |
| 5268 | string_VkPipelineStageFlagBits(VK_PIPELINE_STAGE_HOST_BIT), ignored); |
| 5269 | } |
| 5270 | |
| 5271 | VkPipelineStageFlags event_stage_masks = 0U; |
| 5272 | bool events_not_found = false; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5273 | const auto *events_context = cb_context.GetCurrentEventsContext(); |
| 5274 | assert(events_context); |
| 5275 | for (const auto &sync_event_pair : *events_context) { |
| 5276 | const auto *sync_event = sync_event_pair.second.get(); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5277 | if (!sync_event) { |
| 5278 | // NOTE PHASE2: This is where we'll need queue submit time validation to come back and check the srcStageMask bits |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5279 | // or solve this with replay creating the SyncEventState in the queue context... also this will be a |
| 5280 | // new validation error... wait without previously submitted set event... |
| 5281 | events_not_found = true; // Demote "extra_stage_bits" error to warning, to avoid false positives at *record time* |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5282 | |
| 5283 | continue; // Core, Lifetimes, or Param check needs to catch invalid events. |
| 5284 | } |
| 5285 | const auto event = sync_event->event->event; |
| 5286 | // TODO add "destroyed" checks |
| 5287 | |
| 5288 | event_stage_masks |= sync_event->scope.mask_param; |
| 5289 | const auto ignore_reason = sync_event->IsIgnoredByWait(src_exec_scope_.mask_param); |
| 5290 | if (ignore_reason) { |
| 5291 | switch (ignore_reason) { |
| 5292 | case SyncEventState::ResetWaitRace: { |
| 5293 | const char *const cmd_name = CommandTypeString(cmd); |
| 5294 | const char *const vuid = "SYNC-vkCmdWaitEvents-missingbarrier-reset"; |
| 5295 | const char *const message = |
| 5296 | "%s: %s %s operation following %s without intervening execution barrier, may cause race condition. %s"; |
| 5297 | skip |= sync_state.LogError(event, vuid, message, cmd_name, sync_state.report_data->FormatHandle(event).c_str(), |
| 5298 | cmd_name, CommandTypeString(sync_event->last_command), ignored); |
| 5299 | break; |
| 5300 | } |
| 5301 | case SyncEventState::SetRace: { |
| 5302 | // Issue error message that Wait is waiting on an signal subject to race condition, and is thus ignored for this |
| 5303 | // event |
| 5304 | const char *const cmd_name = CommandTypeString(cmd); |
| 5305 | const char *const vuid = "SYNC-vkCmdWaitEvents-unsynchronized-setops"; |
| 5306 | const char *const message = |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 5307 | "%s: %s Unsychronized %s calls result in race conditions w.r.t. event signalling, %s %s"; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5308 | const char *const reason = "First synchronization scope is undefined."; |
| 5309 | skip |= sync_state.LogError(event, vuid, message, cmd_name, sync_state.report_data->FormatHandle(event).c_str(), |
| 5310 | CommandTypeString(sync_event->last_command), reason, ignored); |
| 5311 | break; |
| 5312 | } |
| 5313 | case SyncEventState::MissingStageBits: { |
| 5314 | const VkPipelineStageFlags missing_bits = sync_event->scope.mask_param & ~src_exec_scope_.mask_param; |
| 5315 | // Issue error message that event waited for is not in wait events scope |
| 5316 | const char *const cmd_name = CommandTypeString(cmd); |
| 5317 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 5318 | const char *const message = |
| 5319 | "%s: %s stageMask 0x%" PRIx32 " includes bits not present in srcStageMask 0x%" PRIx32 |
| 5320 | ". Bits missing from srcStageMask %s. %s"; |
| 5321 | skip |= sync_state.LogError(event, vuid, message, cmd_name, sync_state.report_data->FormatHandle(event).c_str(), |
| 5322 | sync_event->scope.mask_param, src_exec_scope_.mask_param, |
| 5323 | string_VkPipelineStageFlags(missing_bits).c_str(), ignored); |
| 5324 | break; |
| 5325 | } |
| 5326 | default: |
| 5327 | assert(ignore_reason == SyncEventState::NotIgnored); |
| 5328 | } |
| 5329 | } else if (image_memory_barriers_.size()) { |
| 5330 | const auto *context = cb_context.GetCurrentAccessContext(); |
| 5331 | assert(context); |
| 5332 | for (const auto &image_memory_barrier : image_memory_barriers_) { |
| 5333 | if (image_memory_barrier.old_layout == image_memory_barrier.new_layout) continue; |
| 5334 | const auto *image_state = image_memory_barrier.image.get(); |
| 5335 | if (!image_state) continue; |
| 5336 | const auto &subresource_range = image_memory_barrier.range.subresource_range; |
| 5337 | const auto &src_access_scope = image_memory_barrier.barrier.src_access_scope; |
| 5338 | const auto hazard = |
| 5339 | context->DetectImageBarrierHazard(*image_state, sync_event->scope.exec_scope, src_access_scope, |
| 5340 | subresource_range, *sync_event, AccessContext::DetectOptions::kDetectAll); |
| 5341 | if (hazard.hazard) { |
| 5342 | const char *const cmd_name = CommandTypeString(cmd); |
| 5343 | skip |= sync_state.LogError(image_state->image, string_SyncHazardVUID(hazard.hazard), |
| 5344 | "%s: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", cmd_name, |
| 5345 | string_SyncHazard(hazard.hazard), image_memory_barrier.index, |
| 5346 | sync_state.report_data->FormatHandle(image_state->image).c_str(), |
| 5347 | cb_context.FormatUsage(hazard).c_str()); |
| 5348 | break; |
| 5349 | } |
| 5350 | } |
| 5351 | } |
| 5352 | } |
| 5353 | |
| 5354 | // Note that we can't check for HOST in pEvents as we don't track that set event type |
| 5355 | const auto extra_stage_bits = (src_exec_scope_.mask_param & ~VK_PIPELINE_STAGE_HOST_BIT) & ~event_stage_masks; |
| 5356 | if (extra_stage_bits) { |
| 5357 | // Issue error message that event waited for is not in wait events scope |
| 5358 | const char *const cmd_name = CommandTypeString(cmd); |
| 5359 | const char *const vuid = "VUID-vkCmdWaitEvents-srcStageMask-01158"; |
| 5360 | const char *const message = |
| 5361 | "%s: srcStageMask 0x%" PRIx32 " contains stages not present in pEvents stageMask. Extra stages are %s.%s"; |
| 5362 | if (events_not_found) { |
| 5363 | skip |= sync_state.LogInfo(command_buffer_handle, vuid, message, cmd_name, src_exec_scope_.mask_param, |
| 5364 | string_VkPipelineStageFlags(extra_stage_bits).c_str(), |
| 5365 | " vkCmdSetEvent may be in previously submitted command buffer."); |
| 5366 | } else { |
| 5367 | skip |= sync_state.LogError(command_buffer_handle, vuid, message, cmd_name, src_exec_scope_.mask_param, |
| 5368 | string_VkPipelineStageFlags(extra_stage_bits).c_str(), ""); |
| 5369 | } |
| 5370 | } |
| 5371 | return skip; |
| 5372 | } |
| 5373 | |
| 5374 | struct SyncOpWaitEventsFunctorFactory { |
| 5375 | using BarrierOpFunctor = WaitEventBarrierOp; |
| 5376 | using ApplyFunctor = ApplyBarrierFunctor<BarrierOpFunctor>; |
| 5377 | using GlobalBarrierOpFunctor = WaitEventBarrierOp; |
| 5378 | using GlobalApplyFunctor = ApplyBarrierOpsFunctor<GlobalBarrierOpFunctor>; |
| 5379 | using BufferRange = EventSimpleRangeGenerator; |
| 5380 | using ImageRange = EventImageRangeGenerator; |
| 5381 | using GlobalRange = EventSimpleRangeGenerator; |
| 5382 | |
| 5383 | // Need to restrict to only valid exec and access scope for this event |
| 5384 | // Pass by value is intentional to get a copy we can change without modifying the passed barrier |
| 5385 | SyncBarrier RestrictToEvent(SyncBarrier barrier) const { |
| 5386 | barrier.src_exec_scope = sync_event->scope.exec_scope & barrier.src_exec_scope; |
| 5387 | barrier.src_access_scope = sync_event->scope.valid_accesses & barrier.src_access_scope; |
| 5388 | return barrier; |
| 5389 | } |
| 5390 | ApplyFunctor MakeApplyFunctor(const SyncBarrier &barrier_arg, bool layout_transition) const { |
| 5391 | auto barrier = RestrictToEvent(barrier_arg); |
| 5392 | return ApplyFunctor(BarrierOpFunctor(sync_event->first_scope_tag, barrier, layout_transition)); |
| 5393 | } |
| 5394 | GlobalApplyFunctor MakeGlobalApplyFunctor(size_t size_hint, const ResourceUsageTag &tag) const { |
| 5395 | return GlobalApplyFunctor(false /* don't resolve */, size_hint, tag); |
| 5396 | } |
| 5397 | GlobalBarrierOpFunctor MakeGlobalBarrierOpFunctor(const SyncBarrier &barrier_arg) const { |
| 5398 | auto barrier = RestrictToEvent(barrier_arg); |
| 5399 | return GlobalBarrierOpFunctor(sync_event->first_scope_tag, barrier, false); |
| 5400 | } |
| 5401 | |
| 5402 | BufferRange MakeRangeGen(const BUFFER_STATE &buffer, const ResourceAccessRange &range_arg) const { |
| 5403 | const AccessAddressType address_type = GetAccessAddressType(buffer); |
| 5404 | const auto base_address = ResourceBaseAddress(buffer); |
| 5405 | ResourceAccessRange range = SimpleBinding(buffer) ? (range_arg + base_address) : ResourceAccessRange(); |
| 5406 | EventSimpleRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), range); |
| 5407 | return filtered_range_gen; |
| 5408 | } |
| 5409 | ImageRange MakeRangeGen(const IMAGE_STATE &image, const SyncImageMemoryBarrier::SubImageRange &range) const { |
| 5410 | if (!SimpleBinding(image)) return ImageRange(); |
| 5411 | const auto address_type = GetAccessAddressType(image); |
| 5412 | const auto base_address = ResourceBaseAddress(image); |
| 5413 | subresource_adapter::ImageRangeGenerator image_range_gen(*image.fragment_encoder.get(), range.subresource_range, |
| 5414 | range.offset, range.extent, base_address); |
| 5415 | EventImageRangeGenerator filtered_range_gen(sync_event->FirstScope(address_type), image_range_gen); |
| 5416 | |
| 5417 | return filtered_range_gen; |
| 5418 | } |
| 5419 | GlobalRange MakeGlobalRangeGen(AccessAddressType address_type) const { |
| 5420 | return EventSimpleRangeGenerator(sync_event->FirstScope(address_type), kFullRange); |
| 5421 | } |
| 5422 | SyncOpWaitEventsFunctorFactory(SyncEventState *sync_event_) : sync_event(sync_event_) { assert(sync_event); } |
| 5423 | SyncEventState *sync_event; |
| 5424 | }; |
| 5425 | |
| 5426 | void SyncOpWaitEvents::Record(CommandBufferAccessContext *cb_context, const ResourceUsageTag &tag) const { |
| 5427 | auto *access_context = cb_context->GetCurrentAccessContext(); |
| 5428 | assert(access_context); |
| 5429 | if (!access_context) return; |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5430 | auto *events_context = cb_context->GetCurrentEventsContext(); |
| 5431 | assert(events_context); |
| 5432 | if (!events_context) return; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5433 | |
| 5434 | // Unlike PipelineBarrier, WaitEvent is *not* limited to accesses within the current subpass (if any) and thus needs to import |
| 5435 | // all accesses. Can instead import for all first_scopes, or a union of them, if this becomes a performance/memory issue, |
| 5436 | // but with no idea of the performance of the union, nor of whether it even matters... take the simplest approach here, |
| 5437 | access_context->ResolvePreviousAccesses(); |
| 5438 | |
| 5439 | const auto &dst = dst_exec_scope_; |
| 5440 | // TODO... this needs change the SyncEventContext it's using depending on whether this is replay... the recorded |
| 5441 | // sync_event will be in the recorded context, but we need to update the sync_events in the current context.... |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5442 | for (auto &event_shared : events_) { |
| 5443 | if (!event_shared.get()) continue; |
| 5444 | auto *sync_event = events_context->GetFromShared(event_shared); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5445 | |
| 5446 | sync_event->last_command = CMD_WAITEVENTS; |
| 5447 | |
| 5448 | if (!sync_event->IsIgnoredByWait(src_exec_scope_.mask_param)) { |
| 5449 | // These apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 5450 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 5451 | // of the barriers is maintained. |
| 5452 | SyncOpWaitEventsFunctorFactory factory(sync_event); |
| 5453 | ApplyBarriers(buffer_memory_barriers_, factory, tag, access_context); |
| 5454 | ApplyBarriers(image_memory_barriers_, factory, tag, access_context); |
| 5455 | ApplyGlobalBarriers(memory_barriers_, factory, tag, access_context); |
| 5456 | |
| 5457 | // Apply the global barrier to the event itself (for race condition tracking) |
| 5458 | // Events don't happen at a stage, so we need to store the unexpanded ALL_COMMANDS if set for inter-event-calls |
| 5459 | sync_event->barriers = dst.mask_param & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 5460 | sync_event->barriers |= dst.exec_scope; |
| 5461 | } else { |
| 5462 | // We ignored this wait, so we don't have any effective synchronization barriers for it. |
| 5463 | sync_event->barriers = 0U; |
| 5464 | } |
| 5465 | } |
| 5466 | |
| 5467 | // Apply the pending barriers |
| 5468 | ResolvePendingBarrierFunctor apply_pending_action(tag); |
| 5469 | access_context->ApplyToContext(apply_pending_action); |
| 5470 | } |
| 5471 | |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5472 | 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] | 5473 | events_.reserve(event_count); |
| 5474 | for (uint32_t event_index = 0; event_index < event_count; event_index++) { |
John Zulauf | 669dfd5 | 2021-01-27 17:15:28 -0700 | [diff] [blame] | 5475 | events_.emplace_back(sync_state.GetShared<EVENT_STATE>(events[event_index])); |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5476 | } |
| 5477 | } |