locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2019-2020 The Khronos Group Inc. |
| 2 | * Copyright (c) 2019-2020 Valve Corporation |
| 3 | * Copyright (c) 2019-2020 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> |
| 18 | */ |
| 19 | |
| 20 | #include <limits> |
| 21 | #include <vector> |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 22 | #include <memory> |
| 23 | #include <bitset> |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 24 | #include "synchronization_validation.h" |
| 25 | |
| 26 | static const char *string_SyncHazardVUID(SyncHazard hazard) { |
| 27 | switch (hazard) { |
| 28 | case SyncHazard::NONE: |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 29 | return "SYNC-HAZARD-NONE"; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 30 | break; |
| 31 | case SyncHazard::READ_AFTER_WRITE: |
| 32 | return "SYNC-HAZARD-READ_AFTER_WRITE"; |
| 33 | break; |
| 34 | case SyncHazard::WRITE_AFTER_READ: |
| 35 | return "SYNC-HAZARD-WRITE_AFTER_READ"; |
| 36 | break; |
| 37 | case SyncHazard::WRITE_AFTER_WRITE: |
| 38 | return "SYNC-HAZARD-WRITE_AFTER_WRITE"; |
| 39 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 40 | case SyncHazard::READ_RACING_WRITE: |
| 41 | return "SYNC-HAZARD-READ-RACING-WRITE"; |
| 42 | break; |
| 43 | case SyncHazard::WRITE_RACING_WRITE: |
| 44 | return "SYNC-HAZARD-WRITE-RACING-WRITE"; |
| 45 | break; |
| 46 | case SyncHazard::WRITE_RACING_READ: |
| 47 | return "SYNC-HAZARD-WRITE-RACING-READ"; |
| 48 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 49 | default: |
| 50 | assert(0); |
| 51 | } |
| 52 | return "SYNC-HAZARD-INVALID"; |
| 53 | } |
| 54 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 55 | static bool IsHazardVsRead(SyncHazard hazard) { |
| 56 | switch (hazard) { |
| 57 | case SyncHazard::NONE: |
| 58 | return false; |
| 59 | break; |
| 60 | case SyncHazard::READ_AFTER_WRITE: |
| 61 | return false; |
| 62 | break; |
| 63 | case SyncHazard::WRITE_AFTER_READ: |
| 64 | return true; |
| 65 | break; |
| 66 | case SyncHazard::WRITE_AFTER_WRITE: |
| 67 | return false; |
| 68 | break; |
| 69 | case SyncHazard::READ_RACING_WRITE: |
| 70 | return false; |
| 71 | break; |
| 72 | case SyncHazard::WRITE_RACING_WRITE: |
| 73 | return false; |
| 74 | break; |
| 75 | case SyncHazard::WRITE_RACING_READ: |
| 76 | return true; |
| 77 | break; |
| 78 | default: |
| 79 | assert(0); |
| 80 | } |
| 81 | return false; |
| 82 | } |
| 83 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 84 | static const char *string_SyncHazard(SyncHazard hazard) { |
| 85 | switch (hazard) { |
| 86 | case SyncHazard::NONE: |
| 87 | return "NONR"; |
| 88 | break; |
| 89 | case SyncHazard::READ_AFTER_WRITE: |
| 90 | return "READ_AFTER_WRITE"; |
| 91 | break; |
| 92 | case SyncHazard::WRITE_AFTER_READ: |
| 93 | return "WRITE_AFTER_READ"; |
| 94 | break; |
| 95 | case SyncHazard::WRITE_AFTER_WRITE: |
| 96 | return "WRITE_AFTER_WRITE"; |
| 97 | break; |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 98 | case SyncHazard::READ_RACING_WRITE: |
| 99 | return "READ_RACING_WRITE"; |
| 100 | break; |
| 101 | case SyncHazard::WRITE_RACING_WRITE: |
| 102 | return "WRITE_RACING_WRITE"; |
| 103 | break; |
| 104 | case SyncHazard::WRITE_RACING_READ: |
| 105 | return "WRITE_RACING_READ"; |
| 106 | break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 107 | default: |
| 108 | assert(0); |
| 109 | } |
| 110 | return "INVALID HAZARD"; |
| 111 | } |
| 112 | |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 113 | static const SyncStageAccessInfoType *SyncStageAccessInfoFromMask(SyncStageAccessFlags flags) { |
| 114 | // Return the info for the first bit found |
| 115 | const SyncStageAccessInfoType *info = nullptr; |
| 116 | uint32_t index = 0; |
| 117 | while (flags) { |
| 118 | if (flags & 0x1) { |
| 119 | flags = 0; |
| 120 | info = &syncStageAccessInfoByStageAccessIndex[index]; |
| 121 | } else { |
| 122 | flags = flags >> 1; |
| 123 | index++; |
| 124 | } |
| 125 | } |
| 126 | return info; |
| 127 | } |
| 128 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 129 | static std::string string_SyncStageAccessFlags(SyncStageAccessFlags flags, const char *sep = "|") { |
| 130 | std::string out_str; |
| 131 | uint32_t index = 0; |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 132 | if (0 == flags) { |
| 133 | out_str = "0"; |
| 134 | } |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 135 | while (flags) { |
| 136 | const auto &info = syncStageAccessInfoByStageAccessIndex[index]; |
| 137 | if (flags & info.stage_access_bit) { |
| 138 | if (!out_str.empty()) { |
| 139 | out_str.append(sep); |
| 140 | } |
| 141 | out_str.append(info.name); |
| 142 | flags = flags & ~info.stage_access_bit; |
| 143 | } |
| 144 | index++; |
| 145 | assert(index < syncStageAccessInfoByStageAccessIndex.size()); |
| 146 | } |
| 147 | if (out_str.length() == 0) { |
| 148 | out_str.append("Unhandled SyncStageAccess"); |
| 149 | } |
| 150 | return out_str; |
| 151 | } |
| 152 | |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 153 | static std::string string_UsageTag(const HazardResult &hazard) { |
| 154 | const auto &tag = hazard.tag; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 155 | assert(hazard.usage_index < static_cast<SyncStageAccessIndex>(syncStageAccessInfoByStageAccessIndex.size())); |
| 156 | const auto &usage_info = syncStageAccessInfoByStageAccessIndex[hazard.usage_index]; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 157 | std::stringstream out; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 158 | const auto *info = SyncStageAccessInfoFromMask(hazard.prior_access); |
| 159 | const char *stage_access_name = info ? info->name : "INVALID_STAGE_ACCESS"; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 160 | out << "(usage: " << usage_info.name << ", prior_usage: " << stage_access_name; |
| 161 | if (IsHazardVsRead(hazard.hazard)) { |
| 162 | const auto barriers = hazard.access_state->GetReadBarriers(hazard.prior_access); |
| 163 | out << ", read_barriers: " << string_VkPipelineStageFlags(barriers); |
| 164 | } else { |
| 165 | SyncStageAccessFlags write_barrier = hazard.access_state->GetWriteBarriers(); |
| 166 | out << ", write_barriers: " << string_SyncStageAccessFlags(write_barrier); |
| 167 | } |
| 168 | |
| 169 | out << ", command: " << CommandTypeString(tag.command); |
| 170 | out << ", seq_no: " << (tag.index & 0xFFFFFFFF) << ", reset_no: " << (tag.index >> 32) << ")"; |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 171 | return out.str(); |
| 172 | } |
| 173 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 174 | // NOTE: the attachement read flag is put *only* in the access scope and not in the exect scope, since the ordering |
| 175 | // rules apply only to this specific access for this stage, and not the stage as a whole. The ordering detection |
| 176 | // 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] | 177 | static constexpr VkPipelineStageFlags kColorAttachmentExecScope = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
| 178 | static constexpr SyncStageAccessFlags kColorAttachmentAccessScope = |
| 179 | SyncStageAccessFlagBits::SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_BIT | |
| 180 | SyncStageAccessFlagBits::SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 181 | SyncStageAccessFlagBits::SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE_BIT | |
| 182 | SyncStageAccessFlagBits::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] | 183 | static constexpr VkPipelineStageFlags kDepthStencilAttachmentExecScope = |
| 184 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; |
| 185 | static constexpr SyncStageAccessFlags kDepthStencilAttachmentAccessScope = |
| 186 | SyncStageAccessFlagBits::SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | |
| 187 | SyncStageAccessFlagBits::SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 188 | SyncStageAccessFlagBits::SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 189 | SyncStageAccessFlagBits::SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 190 | SyncStageAccessFlagBits::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] | 191 | |
| 192 | static constexpr SyncOrderingBarrier kColorAttachmentRasterOrder = {kColorAttachmentExecScope, kColorAttachmentAccessScope}; |
| 193 | static constexpr SyncOrderingBarrier kDepthStencilAttachmentRasterOrder = {kDepthStencilAttachmentExecScope, |
| 194 | kDepthStencilAttachmentAccessScope}; |
| 195 | static constexpr SyncOrderingBarrier kAttachmentRasterOrder = {kDepthStencilAttachmentExecScope | kColorAttachmentExecScope, |
| 196 | kDepthStencilAttachmentAccessScope | kColorAttachmentAccessScope}; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 197 | // Sometimes we have an internal access conflict, and we using the kCurrentCommandTag to set and detect in temporary/proxy contexts |
John Zulauf | cc6fecb | 2020-06-17 15:24:54 -0600 | [diff] [blame] | 198 | static const ResourceUsageTag kCurrentCommandTag(ResourceUsageTag::kMaxIndex, CMD_NONE); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 199 | |
locke-lunarg | 3c03800 | 2020-04-30 23:08:08 -0600 | [diff] [blame] | 200 | inline VkDeviceSize GetRealWholeSize(VkDeviceSize offset, VkDeviceSize size, VkDeviceSize whole_size) { |
| 201 | if (size == VK_WHOLE_SIZE) { |
| 202 | return (whole_size - offset); |
| 203 | } |
| 204 | return size; |
| 205 | } |
| 206 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 207 | static inline VkDeviceSize GetBufferWholeSize(const BUFFER_STATE &buf_state, VkDeviceSize offset, VkDeviceSize size) { |
| 208 | return GetRealWholeSize(offset, size, buf_state.createInfo.size); |
| 209 | } |
| 210 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 211 | template <typename T> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 212 | static ResourceAccessRange MakeRange(const T &has_offset_and_size) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 213 | return ResourceAccessRange(has_offset_and_size.offset, (has_offset_and_size.offset + has_offset_and_size.size)); |
| 214 | } |
| 215 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 216 | static ResourceAccessRange MakeRange(VkDeviceSize start, VkDeviceSize size) { return ResourceAccessRange(start, (start + size)); } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 217 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 218 | static inline ResourceAccessRange MakeRange(const BUFFER_STATE &buffer, VkDeviceSize offset, VkDeviceSize size) { |
| 219 | return MakeRange(offset, GetBufferWholeSize(buffer, offset, size)); |
| 220 | } |
| 221 | |
| 222 | static inline ResourceAccessRange MakeRange(const BUFFER_VIEW_STATE &buf_view_state) { |
| 223 | return MakeRange(*buf_view_state.buffer_state.get(), buf_view_state.create_info.offset, buf_view_state.create_info.range); |
| 224 | } |
| 225 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 226 | // Expand the pipeline stage without regard to whether the are valid w.r.t. queue or extension |
| 227 | VkPipelineStageFlags ExpandPipelineStages(VkQueueFlags queue_flags, VkPipelineStageFlags stage_mask) { |
| 228 | VkPipelineStageFlags expanded = stage_mask; |
| 229 | if (VK_PIPELINE_STAGE_ALL_COMMANDS_BIT & stage_mask) { |
| 230 | expanded = expanded & ~VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 231 | for (const auto &all_commands : syncAllCommandStagesByQueueFlags) { |
| 232 | if (all_commands.first & queue_flags) { |
| 233 | expanded |= all_commands.second; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | if (VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT & stage_mask) { |
| 238 | expanded = expanded & ~VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT; |
| 239 | expanded |= syncAllCommandStagesByQueueFlags.at(VK_QUEUE_GRAPHICS_BIT) & ~VK_PIPELINE_STAGE_HOST_BIT; |
| 240 | } |
| 241 | return expanded; |
| 242 | } |
| 243 | |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 244 | VkPipelineStageFlags RelatedPipelineStages(VkPipelineStageFlags stage_mask, |
| 245 | std::map<VkPipelineStageFlagBits, VkPipelineStageFlags> &map) { |
| 246 | VkPipelineStageFlags unscanned = stage_mask; |
| 247 | VkPipelineStageFlags related = 0; |
Jonah Ryan-Davis | 185189c | 2020-07-14 10:28:52 -0400 | [diff] [blame] | 248 | for (const auto &entry : map) { |
| 249 | const auto &stage = entry.first; |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 250 | if (stage & unscanned) { |
| 251 | related = related | entry.second; |
| 252 | unscanned = unscanned & ~stage; |
| 253 | if (!unscanned) break; |
| 254 | } |
| 255 | } |
| 256 | return related; |
| 257 | } |
| 258 | |
| 259 | VkPipelineStageFlags WithEarlierPipelineStages(VkPipelineStageFlags stage_mask) { |
| 260 | return stage_mask | RelatedPipelineStages(stage_mask, syncLogicallyEarlierStages); |
| 261 | } |
| 262 | |
| 263 | VkPipelineStageFlags WithLaterPipelineStages(VkPipelineStageFlags stage_mask) { |
| 264 | return stage_mask | RelatedPipelineStages(stage_mask, syncLogicallyLaterStages); |
| 265 | } |
| 266 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 267 | static const ResourceAccessRange full_range(std::numeric_limits<VkDeviceSize>::min(), std::numeric_limits<VkDeviceSize>::max()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 268 | |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 269 | ResourceAccessRange GetBufferRange(VkDeviceSize offset, VkDeviceSize buf_whole_size, uint32_t first_index, uint32_t count, |
| 270 | VkDeviceSize stride) { |
| 271 | VkDeviceSize range_start = offset + first_index * stride; |
| 272 | VkDeviceSize range_size = 0; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 273 | if (count == UINT32_MAX) { |
| 274 | range_size = buf_whole_size - range_start; |
| 275 | } else { |
| 276 | range_size = count * stride; |
| 277 | } |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 278 | return MakeRange(range_start, range_size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 279 | } |
| 280 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 281 | SyncStageAccessIndex GetSyncStageAccessIndexsByDescriptorSet(VkDescriptorType descriptor_type, const interface_var &descriptor_data, |
| 282 | VkShaderStageFlagBits stage_flag) { |
| 283 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 284 | assert(stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT); |
| 285 | return SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ; |
| 286 | } |
| 287 | auto stage_access = syncStageAccessMaskByShaderStage.find(stage_flag); |
| 288 | if (stage_access == syncStageAccessMaskByShaderStage.end()) { |
| 289 | assert(0); |
| 290 | } |
| 291 | if (descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) { |
| 292 | return stage_access->second.uniform_read; |
| 293 | } |
| 294 | |
| 295 | // If the desriptorSet is writable, we don't need to care SHADER_READ. SHADER_WRITE is enough. |
| 296 | // Because if write hazard happens, read hazard might or might not happen. |
| 297 | // But if write hazard doesn't happen, read hazard is impossible to happen. |
| 298 | if (descriptor_data.is_writable) { |
| 299 | return stage_access->second.shader_write; |
| 300 | } |
| 301 | return stage_access->second.shader_read; |
| 302 | } |
| 303 | |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 304 | bool IsImageLayoutDepthWritable(VkImageLayout image_layout) { |
| 305 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 306 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL || |
| 307 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) |
| 308 | ? true |
| 309 | : false; |
| 310 | } |
| 311 | |
| 312 | bool IsImageLayoutStencilWritable(VkImageLayout image_layout) { |
| 313 | return (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 314 | image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL || |
| 315 | image_layout == VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL) |
| 316 | ? true |
| 317 | : false; |
| 318 | } |
| 319 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 320 | // Class AccessContext stores the state of accesses specific to a Command, Subpass, or Queue |
| 321 | const std::array<AccessContext::AddressType, AccessContext::kAddressTypeCount> AccessContext::kAddressTypes = { |
| 322 | AccessContext::AddressType::kLinearAddress, AccessContext::AddressType::kIdealizedAddress}; |
| 323 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 324 | // Tranverse the attachment resolves for this a specific subpass, and do action() to them. |
| 325 | // Used by both validation and record operations |
| 326 | // |
| 327 | // The signature for Action() reflect the needs of both uses. |
| 328 | template <typename Action> |
| 329 | void ResolveOperation(Action &action, const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 330 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass) { |
| 331 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 332 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 333 | const auto &rp_ci = rp_state.createInfo; |
| 334 | const auto *attachment_ci = rp_ci.pAttachments; |
| 335 | const auto &subpass_ci = rp_ci.pSubpasses[subpass]; |
| 336 | |
| 337 | // Color resolves -- require an inuse color attachment and a matching inuse resolve attachment |
| 338 | const auto *color_attachments = subpass_ci.pColorAttachments; |
| 339 | const auto *color_resolve = subpass_ci.pResolveAttachments; |
| 340 | if (color_resolve && color_attachments) { |
| 341 | for (uint32_t i = 0; i < subpass_ci.colorAttachmentCount; i++) { |
| 342 | const auto &color_attach = color_attachments[i].attachment; |
| 343 | const auto &resolve_attach = subpass_ci.pResolveAttachments[i].attachment; |
| 344 | if ((color_attach != VK_ATTACHMENT_UNUSED) && (resolve_attach != VK_ATTACHMENT_UNUSED)) { |
| 345 | action("color", "resolve read", color_attach, resolve_attach, attachment_views[color_attach], |
| 346 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, kColorAttachmentRasterOrder, offset, extent, 0); |
| 347 | action("color", "resolve write", color_attach, resolve_attach, attachment_views[resolve_attach], |
| 348 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, kColorAttachmentRasterOrder, offset, extent, 0); |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | // Depth stencil resolve only if the extension is present |
| 354 | const auto ds_resolve = lvl_find_in_chain<VkSubpassDescriptionDepthStencilResolve>(subpass_ci.pNext); |
| 355 | if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment && |
| 356 | (ds_resolve->pDepthStencilResolveAttachment->attachment != VK_ATTACHMENT_UNUSED) && subpass_ci.pDepthStencilAttachment && |
| 357 | (subpass_ci.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) { |
| 358 | const auto src_at = subpass_ci.pDepthStencilAttachment->attachment; |
| 359 | const auto src_ci = attachment_ci[src_at]; |
| 360 | // The formats are required to match so we can pick either |
| 361 | const bool resolve_depth = (ds_resolve->depthResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasDepth(src_ci.format); |
| 362 | const bool resolve_stencil = (ds_resolve->stencilResolveMode != VK_RESOLVE_MODE_NONE) && FormatHasStencil(src_ci.format); |
| 363 | const auto dst_at = ds_resolve->pDepthStencilResolveAttachment->attachment; |
| 364 | VkImageAspectFlags aspect_mask = 0u; |
| 365 | |
| 366 | // Figure out which aspects are actually touched during resolve operations |
| 367 | const char *aspect_string = nullptr; |
| 368 | if (resolve_depth && resolve_stencil) { |
| 369 | // Validate all aspects together |
| 370 | aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 371 | aspect_string = "depth/stencil"; |
| 372 | } else if (resolve_depth) { |
| 373 | // Validate depth only |
| 374 | aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 375 | aspect_string = "depth"; |
| 376 | } else if (resolve_stencil) { |
| 377 | // Validate all stencil only |
| 378 | aspect_mask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 379 | aspect_string = "stencil"; |
| 380 | } |
| 381 | |
| 382 | if (aspect_mask) { |
| 383 | action(aspect_string, "resolve read", src_at, dst_at, attachment_views[src_at], |
| 384 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, kDepthStencilAttachmentRasterOrder, offset, extent, |
| 385 | aspect_mask); |
| 386 | action(aspect_string, "resolve write", src_at, dst_at, attachment_views[dst_at], |
| 387 | SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, kAttachmentRasterOrder, offset, extent, aspect_mask); |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | // Action for validating resolve operations |
| 393 | class ValidateResolveAction { |
| 394 | public: |
| 395 | ValidateResolveAction(VkRenderPass render_pass, uint32_t subpass, const AccessContext &context, const SyncValidator &sync_state, |
| 396 | const char *func_name) |
| 397 | : render_pass_(render_pass), |
| 398 | subpass_(subpass), |
| 399 | context_(context), |
| 400 | sync_state_(sync_state), |
| 401 | func_name_(func_name), |
| 402 | skip_(false) {} |
| 403 | void operator()(const char *aspect_name, const char *attachment_name, uint32_t src_at, uint32_t dst_at, |
| 404 | const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, const SyncOrderingBarrier &ordering, |
| 405 | const VkOffset3D &offset, const VkExtent3D &extent, VkImageAspectFlags aspect_mask) { |
| 406 | HazardResult hazard; |
| 407 | hazard = context_.DetectHazard(view, current_usage, ordering, offset, extent, aspect_mask); |
| 408 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 409 | skip_ |= sync_state_.LogError(render_pass_, string_SyncHazardVUID(hazard.hazard), |
| 410 | "%s: Hazard %s in subpass %" PRIu32 "during %s %s, from attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 411 | " to resolve attachment %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 412 | func_name_, string_SyncHazard(hazard.hazard), subpass_, aspect_name, attachment_name, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 413 | src_at, dst_at, string_UsageTag(hazard).c_str()); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | // Providing a mechanism for the constructing caller to get the result of the validation |
| 417 | bool GetSkip() const { return skip_; } |
| 418 | |
| 419 | private: |
| 420 | VkRenderPass render_pass_; |
| 421 | const uint32_t subpass_; |
| 422 | const AccessContext &context_; |
| 423 | const SyncValidator &sync_state_; |
| 424 | const char *func_name_; |
| 425 | bool skip_; |
| 426 | }; |
| 427 | |
| 428 | // Update action for resolve operations |
| 429 | class UpdateStateResolveAction { |
| 430 | public: |
| 431 | UpdateStateResolveAction(AccessContext &context, const ResourceUsageTag &tag) : context_(context), tag_(tag) {} |
| 432 | void operator()(const char *aspect_name, const char *attachment_name, uint32_t src_at, uint32_t dst_at, |
| 433 | const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, const SyncOrderingBarrier &ordering, |
| 434 | const VkOffset3D &offset, const VkExtent3D &extent, VkImageAspectFlags aspect_mask) { |
| 435 | // Ignores validation only arguments... |
| 436 | context_.UpdateAccessState(view, current_usage, offset, extent, aspect_mask, tag_); |
| 437 | } |
| 438 | |
| 439 | private: |
| 440 | AccessContext &context_; |
| 441 | const ResourceUsageTag &tag_; |
| 442 | }; |
| 443 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 444 | void HazardResult::Set(const ResourceAccessState *access_state_, SyncStageAccessIndex usage_index_, SyncHazard hazard_, |
| 445 | SyncStageAccessFlags prior_, const ResourceUsageTag &tag_) { |
| 446 | access_state = std::unique_ptr<const ResourceAccessState>(new ResourceAccessState(*access_state_)); |
| 447 | usage_index = usage_index_; |
| 448 | hazard = hazard_; |
| 449 | prior_access = prior_; |
| 450 | tag = tag_; |
| 451 | } |
| 452 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 453 | AccessContext::AccessContext(uint32_t subpass, VkQueueFlags queue_flags, |
| 454 | const std::vector<SubpassDependencyGraphNode> &dependencies, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 455 | const std::vector<AccessContext> &contexts, const AccessContext *external_context) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 456 | Reset(); |
| 457 | const auto &subpass_dep = dependencies[subpass]; |
| 458 | prev_.reserve(subpass_dep.prev.size()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 459 | 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] | 460 | for (const auto &prev_dep : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 461 | const auto prev_pass = prev_dep.first->pass; |
| 462 | const auto &prev_barriers = prev_dep.second; |
| 463 | assert(prev_dep.second.size()); |
| 464 | prev_.emplace_back(&contexts[prev_pass], queue_flags, prev_barriers); |
| 465 | prev_by_subpass_[prev_pass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 466 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 467 | |
| 468 | async_.reserve(subpass_dep.async.size()); |
| 469 | for (const auto async_subpass : subpass_dep.async) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 470 | // TODO -- review why async is storing non-const |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 471 | async_.emplace_back(const_cast<AccessContext *>(&contexts[async_subpass])); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 472 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 473 | if (subpass_dep.barrier_from_external.size()) { |
| 474 | src_external_ = TrackBack(external_context, queue_flags, subpass_dep.barrier_from_external); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 475 | } |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 476 | if (subpass_dep.barrier_to_external.size()) { |
| 477 | dst_external_ = TrackBack(this, queue_flags, subpass_dep.barrier_to_external); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 478 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 479 | } |
| 480 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 481 | template <typename Detector> |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 482 | HazardResult AccessContext::DetectPreviousHazard(AddressType type, const Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 483 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 484 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 485 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 486 | |
| 487 | HazardResult hazard; |
| 488 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 489 | hazard = detector.Detect(prev); |
| 490 | } |
| 491 | return hazard; |
| 492 | } |
| 493 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 494 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 495 | // the DAG of the contexts (for example subpasses) |
| 496 | template <typename Detector> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 497 | HazardResult AccessContext::DetectHazard(AddressType type, const Detector &detector, const ResourceAccessRange &range, |
| 498 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 499 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 500 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 501 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 502 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 503 | // so we'll check these first |
| 504 | for (const auto &async_context : async_) { |
| 505 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 506 | if (hazard.hazard) return hazard; |
| 507 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 508 | } |
| 509 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 510 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 511 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 512 | const auto &accesses = GetAccessStateMap(type); |
| 513 | const auto from = accesses.lower_bound(range); |
| 514 | const auto to = accesses.upper_bound(range); |
| 515 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 516 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 517 | for (auto pos = from; pos != to; ++pos) { |
| 518 | // Cover any leading gap, or gap between entries |
| 519 | if (detect_prev) { |
| 520 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 521 | // Cover any leading gap, or gap between entries |
| 522 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 523 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 524 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 525 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 526 | if (hazard.hazard) return hazard; |
| 527 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 528 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 529 | gap.begin = pos->first.end; |
| 530 | } |
| 531 | |
| 532 | hazard = detector.Detect(pos); |
| 533 | if (hazard.hazard) return hazard; |
| 534 | } |
| 535 | |
| 536 | if (detect_prev) { |
| 537 | // Detect in the trailing empty as needed |
| 538 | gap.end = range.end; |
| 539 | if (gap.non_empty()) { |
| 540 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 541 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | return hazard; |
| 545 | } |
| 546 | |
| 547 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 548 | template <typename Detector> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 549 | HazardResult AccessContext::DetectAsyncHazard(AddressType type, const Detector &detector, const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 550 | auto &accesses = GetAccessStateMap(type); |
| 551 | const auto from = accesses.lower_bound(range); |
| 552 | const auto to = accesses.upper_bound(range); |
| 553 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 554 | HazardResult hazard; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 555 | for (auto pos = from; pos != to && !hazard.hazard; ++pos) { |
| 556 | hazard = detector.DetectAsync(pos); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 557 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 558 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 559 | return hazard; |
| 560 | } |
| 561 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 562 | // Returns the last resolved entry |
| 563 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 564 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 565 | const std::vector<SyncBarrier> &barriers) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 566 | auto at = entry; |
| 567 | for (auto pos = first; pos != last; ++pos) { |
| 568 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 569 | assert(at->first.includes(pos->first)); |
| 570 | assert(at != dest->end()); |
| 571 | // Trim up at to the same size as the entry to resolve |
| 572 | at = sparse_container::split(at, *dest, pos->first); |
| 573 | auto access = pos->second; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 574 | if (barriers.size()) { |
| 575 | access.ApplyBarriers(barriers); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 576 | } |
| 577 | at->second.Resolve(access); |
| 578 | ++at; // Go to the remaining unused section of entry |
| 579 | } |
| 580 | } |
| 581 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 582 | static SyncBarrier MergeBarriers(const std::vector<SyncBarrier> &barriers) { |
| 583 | SyncBarrier merged = {}; |
| 584 | for (const auto &barrier : barriers) { |
| 585 | merged.Merge(barrier); |
| 586 | } |
| 587 | return merged; |
| 588 | } |
| 589 | |
| 590 | void AccessContext::ResolveAccessRange(AddressType type, const ResourceAccessRange &range, const std::vector<SyncBarrier> &barriers, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 591 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 592 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 593 | if (!range.non_empty()) return; |
| 594 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 595 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 596 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 597 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 598 | if (current->pos_B->valid) { |
| 599 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 600 | auto access = src_pos->second; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 601 | if (barriers.size()) { |
| 602 | access.ApplyBarriers(barriers); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 603 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 604 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 605 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 606 | trimmed->second.Resolve(access); |
| 607 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 608 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 609 | 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] | 610 | 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] | 611 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 612 | } else { |
| 613 | // we have to descend to fill this gap |
| 614 | if (recur_to_infill) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 615 | if (current->pos_A->valid) { |
| 616 | // Dest is valid, so we need to accumulate along the DAG and then resolve... in an N-to-1 resolve operation |
| 617 | ResourceAccessRangeMap gap_map; |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 618 | ResolvePreviousAccess(type, current_range, &gap_map, infill_state); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 619 | ResolveMapToEntry(resolve_map, current->pos_A->lower_bound, gap_map.begin(), gap_map.end(), barriers); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 620 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 621 | // There isn't anything in dest in current)range, so we can accumulate directly into it. |
| 622 | ResolvePreviousAccess(type, current_range, resolve_map, infill_state); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 623 | if (barriers.size()) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 624 | // Need to apply the barrier to the accesses we accumulated, noting that we haven't updated current |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 625 | for (auto pos = resolve_map->lower_bound(current_range); pos != current->pos_A->lower_bound; ++pos) { |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 626 | pos->second.ApplyBarriers(barriers); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | } |
| 630 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 631 | // iterator of the outer while. |
| 632 | |
| 633 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 634 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 635 | // we stepped on the dest map |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 636 | const auto seek_to = current_range.end - 1; // The subtraction is safe as range can't be empty (loop condition) |
| 637 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 638 | current.seek(seek_to); |
| 639 | } else if (!current->pos_A->valid && infill_state) { |
| 640 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 641 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 642 | 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] | 643 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 644 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 645 | ++current; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 646 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 647 | |
| 648 | // Infill if range goes passed both the current and resolve map prior contents |
| 649 | if (recur_to_infill && (current->range.end < range.end)) { |
| 650 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
| 651 | ResourceAccessRangeMap gap_map; |
| 652 | const auto the_end = resolve_map->end(); |
| 653 | ResolvePreviousAccess(type, trailing_fill_range, &gap_map, infill_state); |
| 654 | for (auto &access : gap_map) { |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 655 | access.second.ApplyBarriers(barriers); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 656 | resolve_map->insert(the_end, access); |
| 657 | } |
| 658 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 659 | } |
| 660 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 661 | void AccessContext::ResolvePreviousAccess(AddressType type, const ResourceAccessRange &range, ResourceAccessRangeMap *descent_map, |
| 662 | const ResourceAccessState *infill_state) const { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 663 | if ((prev_.size() == 0) && (src_external_.context == nullptr)) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 664 | if (range.non_empty() && infill_state) { |
| 665 | descent_map->insert(std::make_pair(range, *infill_state)); |
| 666 | } |
| 667 | } else { |
| 668 | // Look for something to fill the gap further along. |
| 669 | for (const auto &prev_dep : prev_) { |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 670 | prev_dep.context->ResolveAccessRange(type, range, prev_dep.barriers, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 671 | } |
| 672 | |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 673 | if (src_external_.context) { |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 674 | src_external_.context->ResolveAccessRange(type, range, src_external_.barriers, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 675 | } |
| 676 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 677 | } |
| 678 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 679 | AccessContext::AddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
locke-lunarg | 3f6978b | 2020-04-16 16:51:35 -0600 | [diff] [blame] | 680 | return (image.fragment_encoder->IsLinearImage()) ? AddressType::kLinearAddress : AddressType::kIdealizedAddress; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | VkDeviceSize AccessContext::ResourceBaseAddress(const BINDABLE &bindable) { |
| 684 | return bindable.binding.offset + bindable.binding.mem_state->fake_base_address; |
| 685 | } |
| 686 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 687 | static bool SimpleBinding(const BINDABLE &bindable) { return !bindable.sparse && bindable.binding.mem_state; } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 688 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 689 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
| 690 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 691 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE; |
| 692 | return stage_access; |
| 693 | } |
| 694 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
| 695 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 696 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE; |
| 697 | return stage_access; |
| 698 | } |
| 699 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 700 | // Caller must manage returned pointer |
| 701 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
| 702 | uint32_t subpass, const VkRect2D &render_area, |
| 703 | std::vector<const IMAGE_VIEW_STATE *> attachment_views) { |
| 704 | auto *proxy = new AccessContext(context); |
| 705 | proxy->UpdateAttachmentResolveAccess(rp_state, render_area, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 706 | proxy->UpdateAttachmentStoreAccess(rp_state, render_area, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 707 | return proxy; |
| 708 | } |
| 709 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 710 | void AccessContext::ResolvePreviousAccess(const IMAGE_STATE &image_state, const VkImageSubresourceRange &subresource_range_arg, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 711 | AddressType address_type, ResourceAccessRangeMap *descent_map, |
| 712 | const ResourceAccessState *infill_state) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 713 | if (!SimpleBinding(image_state)) return; |
| 714 | |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 715 | auto subresource_range = NormalizeSubresourceRange(image_state.createInfo, subresource_range_arg); |
locke-lunarg | ae26eac | 2020-04-16 15:29:05 -0600 | [diff] [blame] | 716 | subresource_adapter::ImageRangeGenerator range_gen(*image_state.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
locke-lunarg | 5f7d3c6 | 2020-04-07 00:10:39 -0600 | [diff] [blame] | 717 | image_state.createInfo.extent); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 718 | const auto base_address = ResourceBaseAddress(image_state); |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 719 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 720 | ResolvePreviousAccess(address_type, (*range_gen + base_address), descent_map, infill_state); |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 724 | // Layout transitions are handled as if the were occuring in the beginning of the next subpass |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 725 | bool AccessContext::ValidateLayoutTransitions(const SyncValidator &sync_state, const RENDER_PASS_STATE &rp_state, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 726 | const VkRect2D &render_area, uint32_t subpass, |
| 727 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 728 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 729 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 730 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 731 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 732 | // those affects have not been recorded yet. |
| 733 | // |
| 734 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 735 | // to apply and only copy then, if this proves a hot spot. |
| 736 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 737 | TrackBack proxy_track_back; |
| 738 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 739 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 740 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 741 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 742 | |
| 743 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
| 744 | if (prev_needs_proxy) { |
| 745 | if (!proxy_for_prev) { |
| 746 | proxy_for_prev.reset(CreateStoreResolveProxyContext(*track_back->context, rp_state, transition.prev_pass, |
| 747 | render_area, attachment_views)); |
| 748 | proxy_track_back = *track_back; |
| 749 | proxy_track_back.context = proxy_for_prev.get(); |
| 750 | } |
| 751 | track_back = &proxy_track_back; |
| 752 | } |
| 753 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 754 | if (hazard.hazard) { |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 755 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 756 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 757 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 758 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 759 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
| 760 | string_UsageTag(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | return skip; |
| 764 | } |
| 765 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 766 | bool AccessContext::ValidateLoadOperation(const SyncValidator &sync_state, const RENDER_PASS_STATE &rp_state, |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 767 | const VkRect2D &render_area, uint32_t subpass, |
| 768 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 769 | const char *func_name) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 770 | bool skip = false; |
| 771 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 772 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 773 | VkOffset3D offset = CastTo3D(render_area.offset); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 774 | |
| 775 | SyncStageAccessFlags accumulate_access_scope = 0; |
| 776 | for (const auto &barrier : src_external_.barriers) { |
| 777 | accumulate_access_scope |= barrier.dst_access_scope; |
| 778 | } |
| 779 | const auto external_access_scope = accumulate_access_scope; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 780 | |
| 781 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 782 | if (subpass == rp_state.attachment_first_subpass[i]) { |
| 783 | if (attachment_views[i] == nullptr) continue; |
| 784 | const IMAGE_VIEW_STATE &view = *attachment_views[i]; |
| 785 | const IMAGE_STATE *image = view.image_state.get(); |
| 786 | if (image == nullptr) continue; |
| 787 | const auto &ci = attachment_ci[i]; |
| 788 | const bool is_transition = rp_state.attachment_first_is_transition[i]; |
| 789 | |
| 790 | // Need check in the following way |
| 791 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 792 | // vs. transition |
| 793 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 794 | // for each aspect loaded. |
| 795 | |
| 796 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 797 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 798 | const bool is_color = !(has_depth || has_stencil); |
| 799 | |
| 800 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
| 801 | const SyncStageAccessFlags load_mask = (has_depth || is_color) ? SyncStageAccess::Flags(load_index) : 0U; |
| 802 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
| 803 | const SyncStageAccessFlags stencil_mask = has_stencil ? SyncStageAccess::Flags(stencil_load_index) : 0U; |
| 804 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 805 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 806 | const char *aspect = nullptr; |
| 807 | if (is_transition) { |
| 808 | // For transition w |
| 809 | SyncHazard transition_hazard = SyncHazard::NONE; |
| 810 | bool checked_stencil = false; |
| 811 | if (load_mask) { |
| 812 | if ((load_mask & external_access_scope) != load_mask) { |
| 813 | transition_hazard = |
| 814 | SyncStageAccess::HasWrite(load_mask) ? SyncHazard::WRITE_AFTER_WRITE : SyncHazard::READ_AFTER_WRITE; |
| 815 | aspect = is_color ? "color" : "depth"; |
| 816 | } |
| 817 | if (!transition_hazard && stencil_mask) { |
| 818 | if ((stencil_mask & external_access_scope) != stencil_mask) { |
| 819 | transition_hazard = SyncStageAccess::HasWrite(stencil_mask) ? SyncHazard::WRITE_AFTER_WRITE |
| 820 | : SyncHazard::READ_AFTER_WRITE; |
| 821 | aspect = "stencil"; |
| 822 | checked_stencil = true; |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | if (transition_hazard) { |
| 827 | // Hazard vs. ILT |
| 828 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
| 829 | skip |= |
locke-lunarg | 54379cf | 2020-08-05 12:25:29 -0600 | [diff] [blame] | 830 | sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(transition_hazard), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 831 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 832 | " aspect %s during load with loadOp %s.", |
| 833 | func_name, string_SyncHazard(transition_hazard), subpass, i, aspect, load_op_string); |
| 834 | } |
| 835 | } else { |
| 836 | auto hazard_range = view.normalized_subresource_range; |
| 837 | bool checked_stencil = false; |
| 838 | if (is_color) { |
| 839 | hazard = DetectHazard(*image, load_index, view.normalized_subresource_range, offset, extent); |
| 840 | aspect = "color"; |
| 841 | } else { |
| 842 | if (has_depth) { |
| 843 | hazard_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 844 | hazard = DetectHazard(*image, load_index, hazard_range, offset, extent); |
| 845 | aspect = "depth"; |
| 846 | } |
| 847 | if (!hazard.hazard && has_stencil) { |
| 848 | hazard_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 849 | hazard = DetectHazard(*image, stencil_load_index, hazard_range, offset, extent); |
| 850 | aspect = "stencil"; |
| 851 | checked_stencil = true; |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | if (hazard.hazard) { |
| 856 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
| 857 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 858 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 859 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 860 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 861 | string_UsageTag(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | return skip; |
| 867 | } |
| 868 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 869 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 870 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 871 | // store is part of the same Next/End operation. |
| 872 | // The latter is handled in layout transistion validation directly |
| 873 | bool AccessContext::ValidateStoreOperation(const SyncValidator &sync_state, const RENDER_PASS_STATE &rp_state, |
| 874 | const VkRect2D &render_area, uint32_t subpass, |
| 875 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 876 | const char *func_name) const { |
| 877 | bool skip = false; |
| 878 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 879 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 880 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 881 | |
| 882 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 883 | if (subpass == rp_state.attachment_last_subpass[i]) { |
| 884 | if (attachment_views[i] == nullptr) continue; |
| 885 | const IMAGE_VIEW_STATE &view = *attachment_views[i]; |
| 886 | const IMAGE_STATE *image = view.image_state.get(); |
| 887 | if (image == nullptr) continue; |
| 888 | const auto &ci = attachment_ci[i]; |
| 889 | |
| 890 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 891 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 892 | // sake, we treat DONT_CARE as writing. |
| 893 | const bool has_depth = FormatHasDepth(ci.format); |
| 894 | const bool has_stencil = FormatHasStencil(ci.format); |
| 895 | const bool is_color = !(has_depth || has_stencil); |
| 896 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 897 | if (!has_stencil && !store_op_stores) continue; |
| 898 | |
| 899 | HazardResult hazard; |
| 900 | const char *aspect = nullptr; |
| 901 | bool checked_stencil = false; |
| 902 | if (is_color) { |
| 903 | hazard = DetectHazard(*image, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 904 | view.normalized_subresource_range, kAttachmentRasterOrder, offset, extent); |
| 905 | aspect = "color"; |
| 906 | } else { |
| 907 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 908 | auto hazard_range = view.normalized_subresource_range; |
| 909 | if (has_depth && store_op_stores) { |
| 910 | hazard_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 911 | hazard = DetectHazard(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, hazard_range, |
| 912 | kAttachmentRasterOrder, offset, extent); |
| 913 | aspect = "depth"; |
| 914 | } |
| 915 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
| 916 | hazard_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 917 | hazard = DetectHazard(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, hazard_range, |
| 918 | kAttachmentRasterOrder, offset, extent); |
| 919 | aspect = "stencil"; |
| 920 | checked_stencil = true; |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | if (hazard.hazard) { |
| 925 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 926 | const char *const store_op_string = string_VkAttachmentStoreOp(checked_stencil ? ci.stencilStoreOp : ci.storeOp); |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 927 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 928 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 929 | " %s aspect during store with %s %s. Access info %s", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 930 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, op_type_string, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 931 | store_op_string, string_UsageTag(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | } |
| 935 | return skip; |
| 936 | } |
| 937 | |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 938 | bool AccessContext::ValidateResolveOperations(const SyncValidator &sync_state, const RENDER_PASS_STATE &rp_state, |
| 939 | const VkRect2D &render_area, |
| 940 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, const char *func_name, |
| 941 | uint32_t subpass) const { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 942 | ValidateResolveAction validate_action(rp_state.renderPass, subpass, *this, sync_state, func_name); |
| 943 | ResolveOperation(validate_action, rp_state, render_area, attachment_views, subpass); |
| 944 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 945 | } |
| 946 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 947 | class HazardDetector { |
| 948 | SyncStageAccessIndex usage_index_; |
| 949 | |
| 950 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 951 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { return pos->second.DetectHazard(usage_index_); } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 952 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 953 | return pos->second.DetectAsyncHazard(usage_index_); |
| 954 | } |
| 955 | HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
| 956 | }; |
| 957 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 958 | class HazardDetectorWithOrdering { |
| 959 | const SyncStageAccessIndex usage_index_; |
| 960 | const SyncOrderingBarrier &ordering_; |
| 961 | |
| 962 | public: |
| 963 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 964 | return pos->second.DetectHazard(usage_index_, ordering_); |
| 965 | } |
| 966 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 967 | return pos->second.DetectAsyncHazard(usage_index_); |
| 968 | } |
| 969 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, const SyncOrderingBarrier &ordering) |
| 970 | : usage_index_(usage), ordering_(ordering) {} |
| 971 | }; |
| 972 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 973 | HazardResult AccessContext::DetectHazard(AddressType type, SyncStageAccessIndex usage_index, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 974 | const ResourceAccessRange &range) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 975 | HazardDetector detector(usage_index); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 976 | return DetectHazard(type, detector, range, DetectOptions::kDetectAll); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 977 | } |
| 978 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 979 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 980 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 981 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 982 | return DetectHazard(AddressType::kLinearAddress, usage_index, range + ResourceBaseAddress(buffer)); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 983 | } |
| 984 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 985 | template <typename Detector> |
| 986 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 987 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 988 | const VkExtent3D &extent, DetectOptions options) const { |
| 989 | if (!SimpleBinding(image)) return HazardResult(); |
| 990 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent); |
| 991 | const auto address_type = ImageAddressType(image); |
| 992 | const auto base_address = ResourceBaseAddress(image); |
| 993 | for (; range_gen->non_empty(); ++range_gen) { |
| 994 | HazardResult hazard = DetectHazard(address_type, detector, (*range_gen + base_address), options); |
| 995 | if (hazard.hazard) return hazard; |
| 996 | } |
| 997 | return HazardResult(); |
| 998 | } |
| 999 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1000 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1001 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1002 | const VkExtent3D &extent) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1003 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1004 | subresource.layerCount}; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1005 | return DetectHazard(image, current_usage, subresource_range, offset, extent); |
| 1006 | } |
| 1007 | |
| 1008 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1009 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 1010 | const VkExtent3D &extent) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1011 | HazardDetector detector(current_usage); |
| 1012 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
| 1013 | } |
| 1014 | |
| 1015 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1016 | const VkImageSubresourceRange &subresource_range, const SyncOrderingBarrier &ordering, |
| 1017 | const VkOffset3D &offset, const VkExtent3D &extent) const { |
| 1018 | HazardDetectorWithOrdering detector(current_usage, ordering); |
| 1019 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1020 | } |
| 1021 | |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1022 | // Some common code for looking at attachments, if there's anything wrong, we return no hazard, core validation |
| 1023 | // should have reported the issue regarding an invalid attachment entry |
| 1024 | HazardResult AccessContext::DetectHazard(const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, |
| 1025 | const SyncOrderingBarrier &ordering, const VkOffset3D &offset, const VkExtent3D &extent, |
| 1026 | VkImageAspectFlags aspect_mask) const { |
| 1027 | if (view != nullptr) { |
| 1028 | const IMAGE_STATE *image = view->image_state.get(); |
| 1029 | if (image != nullptr) { |
| 1030 | auto *detect_range = &view->normalized_subresource_range; |
| 1031 | VkImageSubresourceRange masked_range; |
| 1032 | if (aspect_mask) { // If present and non-zero, restrict the normalized range to aspects present in aspect_mask |
| 1033 | masked_range = view->normalized_subresource_range; |
| 1034 | masked_range.aspectMask = aspect_mask & masked_range.aspectMask; |
| 1035 | detect_range = &masked_range; |
| 1036 | } |
| 1037 | |
| 1038 | // NOTE: The range encoding code is not robust to invalid ranges, so we protect it from our change |
| 1039 | if (detect_range->aspectMask) { |
| 1040 | return DetectHazard(*image, current_usage, *detect_range, ordering, offset, extent); |
| 1041 | } |
| 1042 | } |
| 1043 | } |
| 1044 | return HazardResult(); |
| 1045 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1046 | class BarrierHazardDetector { |
| 1047 | public: |
| 1048 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags src_exec_scope, |
| 1049 | SyncStageAccessFlags src_access_scope) |
| 1050 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1051 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1052 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1053 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1054 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1055 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1056 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1057 | return pos->second.DetectAsyncHazard(usage_index_); |
| 1058 | } |
| 1059 | |
| 1060 | private: |
| 1061 | SyncStageAccessIndex usage_index_; |
| 1062 | VkPipelineStageFlags src_exec_scope_; |
| 1063 | SyncStageAccessFlags src_access_scope_; |
| 1064 | }; |
| 1065 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1066 | HazardResult AccessContext::DetectBarrierHazard(AddressType type, SyncStageAccessIndex current_usage, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1067 | VkPipelineStageFlags src_exec_scope, SyncStageAccessFlags src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1068 | const ResourceAccessRange &range, DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1069 | BarrierHazardDetector detector(current_usage, src_exec_scope, src_access_scope); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1070 | return DetectHazard(type, detector, range, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1073 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags src_exec_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1074 | SyncStageAccessFlags src_access_scope, |
| 1075 | const VkImageSubresourceRange &subresource_range, |
| 1076 | DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1077 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope); |
| 1078 | VkOffset3D zero_offset = {0, 0, 0}; |
| 1079 | return DetectHazard(detector, image, subresource_range, zero_offset, image.createInfo.extent, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1082 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags src_exec_scope, |
| 1083 | SyncStageAccessFlags src_stage_accesses, |
| 1084 | const VkImageMemoryBarrier &barrier) const { |
| 1085 | auto subresource_range = NormalizeSubresourceRange(image.createInfo, barrier.subresourceRange); |
| 1086 | const auto src_access_scope = SyncStageAccess::AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 1087 | return DetectImageBarrierHazard(image, src_exec_scope, src_access_scope, subresource_range, kDetectAll); |
| 1088 | } |
| 1089 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1090 | template <typename Flags, typename Map> |
| 1091 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1092 | SyncStageAccessFlags scope = 0; |
| 1093 | for (const auto &bit_scope : map) { |
| 1094 | if (flag_mask < bit_scope.first) break; |
| 1095 | |
| 1096 | if (flag_mask & bit_scope.first) { |
| 1097 | scope |= bit_scope.second; |
| 1098 | } |
| 1099 | } |
| 1100 | return scope; |
| 1101 | } |
| 1102 | |
| 1103 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags stages) { |
| 1104 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1105 | } |
| 1106 | |
| 1107 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags accesses) { |
| 1108 | return AccessScopeImpl(accesses, syncStageAccessMaskByAccessBit); |
| 1109 | } |
| 1110 | |
| 1111 | // Getting from stage mask and access mask to stage/acess masks is something we need to be good at... |
| 1112 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags stages, VkAccessFlags accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1113 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1114 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1115 | // 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] | 1116 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1117 | } |
| 1118 | |
| 1119 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1120 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1121 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1122 | // that do incrementalupdates |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1123 | auto pos = accesses->lower_bound(range); |
| 1124 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1125 | // The range is empty, fill it with a default value. |
| 1126 | pos = action.Infill(accesses, pos, range); |
| 1127 | } else if (range.begin < pos->first.begin) { |
| 1128 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1129 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1130 | } else if (pos->first.begin < range.begin) { |
| 1131 | // Trim the beginning if needed |
| 1132 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1133 | ++pos; |
| 1134 | } |
| 1135 | |
| 1136 | const auto the_end = accesses->end(); |
| 1137 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1138 | if (pos->first.end > range.end) { |
| 1139 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1140 | } |
| 1141 | |
| 1142 | pos = action(accesses, pos); |
| 1143 | if (pos == the_end) break; |
| 1144 | |
| 1145 | auto next = pos; |
| 1146 | ++next; |
| 1147 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1148 | // Need to infill if next is disjoint |
| 1149 | 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] | 1150 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1151 | next = action.Infill(accesses, next, new_range); |
| 1152 | } |
| 1153 | pos = next; |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1158 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1159 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1160 | // this is only called on gaps, and never returns a gap. |
| 1161 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1162 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1163 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1164 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1165 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1166 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1167 | auto &access_state = pos->second; |
| 1168 | access_state.Update(usage, tag); |
| 1169 | return pos; |
| 1170 | } |
| 1171 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1172 | UpdateMemoryAccessStateFunctor(AccessContext::AddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1173 | const ResourceUsageTag &tag_) |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1174 | : type(type_), context(context_), usage(usage_), tag(tag_) {} |
| 1175 | const AccessContext::AddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1176 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1177 | const SyncStageAccessIndex usage; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1178 | const ResourceUsageTag &tag; |
| 1179 | }; |
| 1180 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1181 | // This functor applies a single barrier, updating the "pending state" in each touched memory range, but does not |
| 1182 | // resolve the pendinging state. Suitable for processing Image and Buffer barriers from PipelineBarriers or Events |
| 1183 | class ApplyBarrierFunctor { |
| 1184 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1185 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1186 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1187 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1188 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1189 | auto &access_state = pos->second; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1190 | access_state.ApplyBarrier(barrier_, layout_transition_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1191 | return pos; |
| 1192 | } |
| 1193 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1194 | ApplyBarrierFunctor(const SyncBarrier &barrier, bool layout_transition) |
| 1195 | : barrier_(barrier), layout_transition_(layout_transition) {} |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1196 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1197 | private: |
| 1198 | const SyncBarrier barrier_; |
| 1199 | const bool layout_transition_; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1200 | }; |
| 1201 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1202 | // This functor applies a collection of barriers, updating the "pending state" in each touched memory range, and optionally |
| 1203 | // resolves the pending state. Suitable for processing Global memory barriers, or Subpass Barriers when the "final" barrier |
| 1204 | // of a collection is known/present. |
| 1205 | class ApplyBarrierOpsFunctor { |
| 1206 | public: |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1207 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1208 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1209 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1210 | struct BarrierOp { |
| 1211 | SyncBarrier barrier; |
| 1212 | bool layout_transition; |
| 1213 | BarrierOp(const SyncBarrier &barrier_, bool layout_transition_) |
| 1214 | : barrier(barrier_), layout_transition(layout_transition_) {} |
| 1215 | BarrierOp() = default; |
| 1216 | }; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1217 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1218 | auto &access_state = pos->second; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1219 | for (const auto op : barrier_ops_) { |
| 1220 | access_state.ApplyBarrier(op.barrier, op.layout_transition); |
| 1221 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1222 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1223 | if (resolve_) { |
| 1224 | // If this is the last (or only) batch, we can do the pending resolve as the last step in this operation to avoid |
| 1225 | // another walk |
| 1226 | access_state.ApplyPendingBarriers(tag_); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1227 | } |
| 1228 | return pos; |
| 1229 | } |
| 1230 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1231 | // A valid tag is required IFF any of the barriers ops are a layout transition, as transitions are write ops |
| 1232 | ApplyBarrierOpsFunctor(bool resolve, size_t size_hint, const ResourceUsageTag &tag) |
| 1233 | : resolve_(resolve), barrier_ops_(), tag_(tag) { |
| 1234 | if (size_hint) { |
| 1235 | barrier_ops_.reserve(size_hint); |
| 1236 | } |
| 1237 | }; |
| 1238 | |
| 1239 | // A valid tag is required IFF layout_transition is true, as transitions are write ops |
| 1240 | ApplyBarrierOpsFunctor(bool resolve, const std::vector<SyncBarrier> &barriers, bool layout_transition, |
| 1241 | const ResourceUsageTag &tag) |
| 1242 | : resolve_(resolve), barrier_ops_(barriers.size()), tag_(tag) { |
| 1243 | for (const auto &barrier : barriers) { |
| 1244 | barrier_ops_.emplace_back(barrier, layout_transition); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1245 | } |
| 1246 | } |
| 1247 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1248 | void PushBack(const SyncBarrier &barrier, bool layout_transition) { barrier_ops_.emplace_back(barrier, layout_transition); } |
| 1249 | |
| 1250 | void PushBack(const std::vector<SyncBarrier> &barriers, bool layout_transition) { |
| 1251 | barrier_ops_.reserve(barrier_ops_.size() + barriers.size()); |
| 1252 | for (const auto &barrier : barriers) { |
| 1253 | barrier_ops_.emplace_back(barrier, layout_transition); |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | private: |
| 1258 | bool resolve_; |
| 1259 | std::vector<BarrierOp> barrier_ops_; |
| 1260 | const ResourceUsageTag &tag_; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1261 | }; |
| 1262 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1263 | void AccessContext::UpdateAccessState(AddressType type, SyncStageAccessIndex current_usage, const ResourceAccessRange &range, |
| 1264 | const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1265 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, tag); |
| 1266 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1267 | } |
| 1268 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1269 | void AccessContext::UpdateAccessState(const BUFFER_STATE &buffer, SyncStageAccessIndex current_usage, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1270 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1271 | if (!SimpleBinding(buffer)) return; |
| 1272 | const auto base_address = ResourceBaseAddress(buffer); |
| 1273 | UpdateAccessState(AddressType::kLinearAddress, current_usage, range + base_address, tag); |
| 1274 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1275 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1276 | void AccessContext::UpdateAccessState(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1277 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1278 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1279 | if (!SimpleBinding(image)) return; |
locke-lunarg | ae26eac | 2020-04-16 15:29:05 -0600 | [diff] [blame] | 1280 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1281 | const auto address_type = ImageAddressType(image); |
| 1282 | const auto base_address = ResourceBaseAddress(image); |
| 1283 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, tag); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1284 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1285 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), (*range_gen + base_address), action); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1286 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1287 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1288 | void AccessContext::UpdateAccessState(const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, const VkOffset3D &offset, |
| 1289 | const VkExtent3D &extent, VkImageAspectFlags aspect_mask, const ResourceUsageTag &tag) { |
| 1290 | if (view != nullptr) { |
| 1291 | const IMAGE_STATE *image = view->image_state.get(); |
| 1292 | if (image != nullptr) { |
| 1293 | auto *update_range = &view->normalized_subresource_range; |
| 1294 | VkImageSubresourceRange masked_range; |
| 1295 | if (aspect_mask) { // If present and non-zero, restrict the normalized range to aspects present in aspect_mask |
| 1296 | masked_range = view->normalized_subresource_range; |
| 1297 | masked_range.aspectMask = aspect_mask & masked_range.aspectMask; |
| 1298 | update_range = &masked_range; |
| 1299 | } |
| 1300 | UpdateAccessState(*image, current_usage, *update_range, offset, extent, tag); |
| 1301 | } |
| 1302 | } |
| 1303 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1304 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1305 | void AccessContext::UpdateAccessState(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1306 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1307 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1308 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1309 | subresource.layerCount}; |
| 1310 | UpdateAccessState(image, current_usage, subresource_range, offset, extent, tag); |
| 1311 | } |
| 1312 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1313 | template <typename Action> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1314 | 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] | 1315 | if (!SimpleBinding(buffer)) return; |
| 1316 | const auto base_address = ResourceBaseAddress(buffer); |
| 1317 | UpdateMemoryAccessState(&GetAccessStateMap(AddressType::kLinearAddress), (range + base_address), action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | template <typename Action> |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 1321 | void AccessContext::UpdateResourceAccess(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range, |
| 1322 | const Action action) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1323 | if (!SimpleBinding(image)) return; |
| 1324 | const auto address_type = ImageAddressType(image); |
| 1325 | auto *accesses = &GetAccessStateMap(address_type); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1326 | |
locke-lunarg | ae26eac | 2020-04-16 15:29:05 -0600 | [diff] [blame] | 1327 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, {0, 0, 0}, |
locke-lunarg | 5f7d3c6 | 2020-04-07 00:10:39 -0600 | [diff] [blame] | 1328 | image.createInfo.extent); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1329 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1330 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1331 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1332 | UpdateMemoryAccessState(accesses, (*range_gen + base_address), action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1336 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 1337 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass, |
| 1338 | const ResourceUsageTag &tag) { |
| 1339 | UpdateStateResolveAction update(*this, tag); |
| 1340 | ResolveOperation(update, rp_state, render_area, attachment_views, subpass); |
| 1341 | } |
| 1342 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1343 | void AccessContext::UpdateAttachmentStoreAccess(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 1344 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass, |
| 1345 | const ResourceUsageTag &tag) { |
| 1346 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 1347 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1348 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 1349 | |
| 1350 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1351 | if (rp_state.attachment_last_subpass[i] == subpass) { |
| 1352 | if (attachment_views[i] == nullptr) continue; // UNUSED |
| 1353 | const auto &view = *attachment_views[i]; |
| 1354 | const IMAGE_STATE *image = view.image_state.get(); |
| 1355 | if (image == nullptr) continue; |
| 1356 | |
| 1357 | const auto &ci = attachment_ci[i]; |
| 1358 | const bool has_depth = FormatHasDepth(ci.format); |
| 1359 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1360 | const bool is_color = !(has_depth || has_stencil); |
| 1361 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1362 | |
| 1363 | if (is_color && store_op_stores) { |
| 1364 | UpdateAccessState(*image, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, view.normalized_subresource_range, |
| 1365 | offset, extent, tag); |
| 1366 | } else { |
| 1367 | auto update_range = view.normalized_subresource_range; |
| 1368 | if (has_depth && store_op_stores) { |
| 1369 | update_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 1370 | UpdateAccessState(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, update_range, offset, extent, |
| 1371 | tag); |
| 1372 | } |
| 1373 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1374 | if (has_stencil && stencil_op_stores) { |
| 1375 | update_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 1376 | UpdateAccessState(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, update_range, offset, extent, |
| 1377 | tag); |
| 1378 | } |
| 1379 | } |
| 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1384 | template <typename Action> |
| 1385 | void AccessContext::ApplyGlobalBarriers(const Action &barrier_action) { |
| 1386 | // 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] | 1387 | for (const auto address_type : kAddressTypes) { |
| 1388 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), full_range, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1393 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1394 | auto &context = contexts[subpass_index]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1395 | for (const auto address_type : kAddressTypes) { |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1396 | context.ResolveAccessRange(address_type, full_range, context.GetDstExternalTrackBack().barriers, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1397 | &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1398 | } |
| 1399 | } |
| 1400 | } |
| 1401 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1402 | // Suitable only for *subpass* access contexts |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1403 | 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] | 1404 | if (!attach_view) return HazardResult(); |
| 1405 | const auto image_state = attach_view->image_state.get(); |
| 1406 | if (!image_state) return HazardResult(); |
| 1407 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1408 | // 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] | 1409 | assert(track_back.context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1410 | |
| 1411 | // 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] | 1412 | // Hazard detection for the transition can be against the merged of the barriers (it only uses src_...) |
| 1413 | const auto merged_barrier = MergeBarriers(track_back.barriers); |
| 1414 | HazardResult hazard = |
| 1415 | track_back.context->DetectImageBarrierHazard(*image_state, merged_barrier.src_exec_scope, merged_barrier.src_access_scope, |
| 1416 | attach_view->normalized_subresource_range, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1417 | if (!hazard.hazard) { |
| 1418 | // The Async hazard check is against the current context's async set. |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1419 | 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] | 1420 | attach_view->normalized_subresource_range, kDetectAsync); |
| 1421 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 1422 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1423 | return hazard; |
| 1424 | } |
| 1425 | |
| 1426 | // Class CommandBufferAccessContext: Keep track of resource access state information for a specific command buffer |
| 1427 | bool CommandBufferAccessContext::ValidateBeginRenderPass(const RENDER_PASS_STATE &rp_state, |
| 1428 | |
| 1429 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 1430 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo, |
| 1431 | const char *func_name) const { |
| 1432 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 1433 | bool skip = false; |
| 1434 | uint32_t subpass = 0; |
| 1435 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 1436 | if (transitions.size()) { |
| 1437 | const std::vector<AccessContext> empty_context_vector; |
| 1438 | // Create context we can use to validate against... |
| 1439 | AccessContext temp_context(subpass, queue_flags_, rp_state.subpass_dependencies, empty_context_vector, |
| 1440 | const_cast<AccessContext *>(&cb_access_context_)); |
| 1441 | |
| 1442 | assert(pRenderPassBegin); |
| 1443 | if (nullptr == pRenderPassBegin) return skip; |
| 1444 | |
| 1445 | const auto fb_state = sync_state_->Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
| 1446 | assert(fb_state); |
| 1447 | if (nullptr == fb_state) return skip; |
| 1448 | |
| 1449 | // Create a limited array of views (which we'll need to toss |
| 1450 | std::vector<const IMAGE_VIEW_STATE *> views; |
| 1451 | const auto count_attachment = GetFramebufferAttachments(*pRenderPassBegin, *fb_state); |
| 1452 | const auto attachment_count = count_attachment.first; |
| 1453 | const auto *attachments = count_attachment.second; |
| 1454 | views.resize(attachment_count, nullptr); |
| 1455 | for (const auto &transition : transitions) { |
| 1456 | assert(transition.attachment < attachment_count); |
| 1457 | views[transition.attachment] = sync_state_->Get<IMAGE_VIEW_STATE>(attachments[transition.attachment]); |
| 1458 | } |
| 1459 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1460 | skip |= temp_context.ValidateLayoutTransitions(*sync_state_, rp_state, pRenderPassBegin->renderArea, 0, views, func_name); |
| 1461 | skip |= temp_context.ValidateLoadOperation(*sync_state_, rp_state, pRenderPassBegin->renderArea, 0, views, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1462 | } |
| 1463 | return skip; |
| 1464 | } |
| 1465 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1466 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1467 | const char *func_name) const { |
| 1468 | bool skip = false; |
| 1469 | const PIPELINE_STATE *pPipe = nullptr; |
| 1470 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
| 1471 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pPipe, &per_sets); |
| 1472 | if (!pPipe || !per_sets) { |
| 1473 | return skip; |
| 1474 | } |
| 1475 | |
| 1476 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1477 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1478 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1479 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1480 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1481 | |
| 1482 | for (const auto &stage_state : pPipe->stage_state) { |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1483 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pPipe->graphicsPipelineCI.pRasterizationState && |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1484 | pPipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) |
| 1485 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1486 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1487 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1488 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1489 | set_binding.first.second); |
| 1490 | const auto descriptor_type = binding_it.GetType(); |
| 1491 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1492 | auto array_idx = 0; |
| 1493 | |
| 1494 | if (binding_it.IsVariableDescriptorCount()) { |
| 1495 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1496 | } |
| 1497 | SyncStageAccessIndex sync_index = |
| 1498 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1499 | |
| 1500 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1501 | uint32_t index = i - index_range.start; |
| 1502 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1503 | switch (descriptor->GetClass()) { |
| 1504 | case DescriptorClass::ImageSampler: |
| 1505 | case DescriptorClass::Image: { |
| 1506 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1507 | VkImageLayout image_layout; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1508 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1509 | const auto image_sampler_descriptor = static_cast<const ImageSamplerDescriptor *>(descriptor); |
| 1510 | img_view_state = image_sampler_descriptor->GetImageViewState(); |
| 1511 | image_layout = image_sampler_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1512 | } else { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1513 | const auto image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 1514 | img_view_state = image_descriptor->GetImageViewState(); |
| 1515 | image_layout = image_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1516 | } |
| 1517 | if (!img_view_state) continue; |
| 1518 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
| 1519 | VkExtent3D extent = {}; |
| 1520 | VkOffset3D offset = {}; |
| 1521 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1522 | extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1523 | offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1524 | } else { |
| 1525 | extent = img_state->createInfo.extent; |
| 1526 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1527 | HazardResult hazard; |
| 1528 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
| 1529 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 1530 | // Input attachments are subject to raster ordering rules |
| 1531 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
| 1532 | kAttachmentRasterOrder, offset, extent); |
| 1533 | } else { |
| 1534 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, offset, extent); |
| 1535 | } |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1536 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1537 | skip |= sync_state_->LogError( |
| 1538 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1539 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 1540 | ", index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1541 | func_name, string_SyncHazard(hazard.hazard), |
| 1542 | sync_state_->report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1543 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
| 1544 | sync_state_->report_data->FormatHandle(pPipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1545 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1546 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
| 1547 | set_binding.first.second, index, string_UsageTag(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1548 | } |
| 1549 | break; |
| 1550 | } |
| 1551 | case DescriptorClass::TexelBuffer: { |
| 1552 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1553 | if (!buf_view_state) continue; |
| 1554 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1555 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1556 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1557 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1558 | skip |= sync_state_->LogError( |
| 1559 | buf_view_state->buffer_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1560 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1561 | func_name, string_SyncHazard(hazard.hazard), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1562 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view).c_str(), |
| 1563 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
| 1564 | sync_state_->report_data->FormatHandle(pPipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1565 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1566 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
| 1567 | string_UsageTag(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1568 | } |
| 1569 | break; |
| 1570 | } |
| 1571 | case DescriptorClass::GeneralBuffer: { |
| 1572 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1573 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1574 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1575 | const ResourceAccessRange range = |
| 1576 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1577 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 1578 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1579 | skip |= sync_state_->LogError( |
| 1580 | buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1581 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1582 | func_name, string_SyncHazard(hazard.hazard), |
| 1583 | sync_state_->report_data->FormatHandle(buf_state->buffer).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1584 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
| 1585 | sync_state_->report_data->FormatHandle(pPipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1586 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1587 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
| 1588 | string_UsageTag(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1589 | } |
| 1590 | break; |
| 1591 | } |
| 1592 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1593 | default: |
| 1594 | break; |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | return skip; |
| 1600 | } |
| 1601 | |
| 1602 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1603 | const ResourceUsageTag &tag) { |
| 1604 | const PIPELINE_STATE *pPipe = nullptr; |
| 1605 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
| 1606 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pPipe, &per_sets); |
| 1607 | if (!pPipe || !per_sets) { |
| 1608 | return; |
| 1609 | } |
| 1610 | |
| 1611 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1612 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1613 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1614 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1615 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1616 | |
| 1617 | for (const auto &stage_state : pPipe->stage_state) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1618 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pPipe->graphicsPipelineCI.pRasterizationState && |
| 1619 | pPipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) |
| 1620 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1621 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1622 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1623 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1624 | set_binding.first.second); |
| 1625 | const auto descriptor_type = binding_it.GetType(); |
| 1626 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1627 | auto array_idx = 0; |
| 1628 | |
| 1629 | if (binding_it.IsVariableDescriptorCount()) { |
| 1630 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1631 | } |
| 1632 | SyncStageAccessIndex sync_index = |
| 1633 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1634 | |
| 1635 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1636 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1637 | switch (descriptor->GetClass()) { |
| 1638 | case DescriptorClass::ImageSampler: |
| 1639 | case DescriptorClass::Image: { |
| 1640 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
| 1641 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
| 1642 | img_view_state = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetImageViewState(); |
| 1643 | } else { |
| 1644 | img_view_state = static_cast<const ImageDescriptor *>(descriptor)->GetImageViewState(); |
| 1645 | } |
| 1646 | if (!img_view_state) continue; |
| 1647 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
| 1648 | VkExtent3D extent = {}; |
| 1649 | VkOffset3D offset = {}; |
| 1650 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1651 | extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1652 | offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1653 | } else { |
| 1654 | extent = img_state->createInfo.extent; |
| 1655 | } |
| 1656 | current_context_->UpdateAccessState(*img_state, sync_index, img_view_state->normalized_subresource_range, |
| 1657 | offset, extent, tag); |
| 1658 | break; |
| 1659 | } |
| 1660 | case DescriptorClass::TexelBuffer: { |
| 1661 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1662 | if (!buf_view_state) continue; |
| 1663 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1664 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1665 | current_context_->UpdateAccessState(*buf_state, sync_index, range, tag); |
| 1666 | break; |
| 1667 | } |
| 1668 | case DescriptorClass::GeneralBuffer: { |
| 1669 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1670 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1671 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1672 | const ResourceAccessRange range = |
| 1673 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1674 | current_context_->UpdateAccessState(*buf_state, sync_index, range, tag); |
| 1675 | break; |
| 1676 | } |
| 1677 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1678 | default: |
| 1679 | break; |
| 1680 | } |
| 1681 | } |
| 1682 | } |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const char *func_name) const { |
| 1687 | bool skip = false; |
| 1688 | const auto *pPipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1689 | if (!pPipe) { |
| 1690 | return skip; |
| 1691 | } |
| 1692 | |
| 1693 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 1694 | const auto &binding_buffers_size = binding_buffers.size(); |
| 1695 | const auto &binding_descriptions_size = pPipe->vertex_binding_descriptions_.size(); |
| 1696 | |
| 1697 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
| 1698 | const auto &binding_description = pPipe->vertex_binding_descriptions_[i]; |
| 1699 | if (binding_description.binding < binding_buffers_size) { |
| 1700 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
| 1701 | if (binding_buffer.buffer == VK_NULL_HANDLE) continue; |
| 1702 | |
| 1703 | auto *buf_state = sync_state_->Get<BUFFER_STATE>(binding_buffer.buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1704 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 1705 | vertexCount, binding_description.stride); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1706 | auto hazard = current_context_->DetectHazard(*buf_state, SYNC_VERTEX_INPUT_VERTEX_ATTRIBUTE_READ, range); |
| 1707 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1708 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1709 | 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] | 1710 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(buf_state->buffer).c_str(), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 1711 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), string_UsageTag(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1712 | } |
| 1713 | } |
| 1714 | } |
| 1715 | return skip; |
| 1716 | } |
| 1717 | |
| 1718 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag &tag) { |
| 1719 | const auto *pPipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1720 | if (!pPipe) { |
| 1721 | return; |
| 1722 | } |
| 1723 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 1724 | const auto &binding_buffers_size = binding_buffers.size(); |
| 1725 | const auto &binding_descriptions_size = pPipe->vertex_binding_descriptions_.size(); |
| 1726 | |
| 1727 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
| 1728 | const auto &binding_description = pPipe->vertex_binding_descriptions_[i]; |
| 1729 | if (binding_description.binding < binding_buffers_size) { |
| 1730 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
| 1731 | if (binding_buffer.buffer == VK_NULL_HANDLE) continue; |
| 1732 | |
| 1733 | auto *buf_state = sync_state_->Get<BUFFER_STATE>(binding_buffer.buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1734 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 1735 | vertexCount, binding_description.stride); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1736 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_INPUT_VERTEX_ATTRIBUTE_READ, range, tag); |
| 1737 | } |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const char *func_name) const { |
| 1742 | bool skip = false; |
| 1743 | if (cb_state_->index_buffer_binding.buffer == VK_NULL_HANDLE) return skip; |
| 1744 | |
| 1745 | auto *index_buf_state = sync_state_->Get<BUFFER_STATE>(cb_state_->index_buffer_binding.buffer); |
| 1746 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1747 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 1748 | firstIndex, indexCount, index_size); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1749 | auto hazard = current_context_->DetectHazard(*index_buf_state, SYNC_VERTEX_INPUT_INDEX_READ, range); |
| 1750 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1751 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1752 | 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] | 1753 | func_name, string_SyncHazard(hazard.hazard), sync_state_->report_data->FormatHandle(index_buf_state->buffer).c_str(), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 1754 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), string_UsageTag(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 1758 | // We will detect more accurate range in the future. |
| 1759 | skip |= ValidateDrawVertex(UINT32_MAX, 0, func_name); |
| 1760 | return skip; |
| 1761 | } |
| 1762 | |
| 1763 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag &tag) { |
| 1764 | if (cb_state_->index_buffer_binding.buffer == VK_NULL_HANDLE) return; |
| 1765 | |
| 1766 | auto *index_buf_state = sync_state_->Get<BUFFER_STATE>(cb_state_->index_buffer_binding.buffer); |
| 1767 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 1768 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 1769 | firstIndex, indexCount, index_size); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1770 | current_context_->UpdateAccessState(*index_buf_state, SYNC_VERTEX_INPUT_INDEX_READ, range, tag); |
| 1771 | |
| 1772 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 1773 | // We will detect more accurate range in the future. |
| 1774 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 1775 | } |
| 1776 | |
| 1777 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(const char *func_name) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 1778 | bool skip = false; |
| 1779 | if (!current_renderpass_context_) return skip; |
| 1780 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(*sync_state_, *cb_state_.get(), |
| 1781 | cb_state_->activeRenderPassBeginInfo.renderArea, func_name); |
| 1782 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag &tag) { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 1786 | if (current_renderpass_context_) |
| 1787 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), cb_state_->activeRenderPassBeginInfo.renderArea, |
| 1788 | tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1789 | } |
| 1790 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1791 | bool CommandBufferAccessContext::ValidateNextSubpass(const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1792 | bool skip = false; |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 1793 | if (!current_renderpass_context_) return skip; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1794 | skip |= |
| 1795 | current_renderpass_context_->ValidateNextSubpass(*sync_state_, cb_state_->activeRenderPassBeginInfo.renderArea, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1796 | |
| 1797 | return skip; |
| 1798 | } |
| 1799 | |
| 1800 | bool CommandBufferAccessContext::ValidateEndRenderpass(const char *func_name) const { |
| 1801 | // TODO: Things to add here. |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1802 | // Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1803 | bool skip = false; |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 1804 | if (!current_renderpass_context_) return skip; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1805 | skip |= current_renderpass_context_->ValidateEndRenderPass(*sync_state_, cb_state_->activeRenderPassBeginInfo.renderArea, |
| 1806 | func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1807 | |
| 1808 | return skip; |
| 1809 | } |
| 1810 | |
| 1811 | void CommandBufferAccessContext::RecordBeginRenderPass(const ResourceUsageTag &tag) { |
| 1812 | assert(sync_state_); |
| 1813 | if (!cb_state_) return; |
| 1814 | |
| 1815 | // Create an access context the current renderpass. |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1816 | render_pass_contexts_.emplace_back(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1817 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1818 | 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] | 1819 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1820 | } |
| 1821 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1822 | void CommandBufferAccessContext::RecordNextSubpass(const RENDER_PASS_STATE &rp_state, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1823 | assert(current_renderpass_context_); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1824 | current_renderpass_context_->RecordNextSubpass(cb_state_->activeRenderPassBeginInfo.renderArea, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1825 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
| 1826 | } |
| 1827 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1828 | void CommandBufferAccessContext::RecordEndRenderPass(const RENDER_PASS_STATE &render_pass, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1829 | assert(current_renderpass_context_); |
| 1830 | if (!current_renderpass_context_) return; |
| 1831 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1832 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, cb_state_->activeRenderPassBeginInfo.renderArea, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1833 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1834 | current_renderpass_context_ = nullptr; |
| 1835 | } |
| 1836 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1837 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const SyncValidator &sync_state, const CMD_BUFFER_STATE &cmd, |
| 1838 | const VkRect2D &render_area, const char *func_name) const { |
| 1839 | bool skip = false; |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1840 | const auto *pPipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1841 | if (!pPipe || |
| 1842 | (pPipe->graphicsPipelineCI.pRasterizationState && pPipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1843 | return skip; |
| 1844 | } |
| 1845 | const auto &list = pPipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1846 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
| 1847 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1848 | VkOffset3D offset = CastTo3D(render_area.offset); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1849 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1850 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 1851 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1852 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 1853 | for (const auto location : list) { |
| 1854 | if (location >= subpass.colorAttachmentCount || subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) |
| 1855 | continue; |
| 1856 | 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] | 1857 | HazardResult hazard = current_context.DetectHazard(img_view_state, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 1858 | kColorAttachmentRasterOrder, offset, extent); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1859 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1860 | 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] | 1861 | "%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] | 1862 | func_name, string_SyncHazard(hazard.hazard), |
| 1863 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1864 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 1865 | location, string_UsageTag(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1866 | } |
| 1867 | } |
| 1868 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1869 | |
| 1870 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 1871 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
| 1872 | if (pPipe->graphicsPipelineCI.pDepthStencilState && subpass.pDepthStencilAttachment && |
| 1873 | subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1874 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pDepthStencilAttachment->attachment]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1875 | bool depth_write = false, stencil_write = false; |
| 1876 | |
| 1877 | // PHASE1 TODO: These validation should be in core_checks. |
| 1878 | if (!FormatIsStencilOnly(img_view_state->create_info.format) && |
| 1879 | pPipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 1880 | pPipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
| 1881 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 1882 | depth_write = true; |
| 1883 | } |
| 1884 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 1885 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 1886 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 1887 | // PHASE1 TODO: These validation should be in core_checks. |
| 1888 | if (!FormatIsDepthOnly(img_view_state->create_info.format) && |
| 1889 | pPipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
| 1890 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 1891 | stencil_write = true; |
| 1892 | } |
| 1893 | |
| 1894 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 1895 | if (depth_write) { |
| 1896 | HazardResult hazard = |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1897 | current_context.DetectHazard(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 1898 | kDepthStencilAttachmentRasterOrder, offset, extent, VK_IMAGE_ASPECT_DEPTH_BIT); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1899 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1900 | skip |= sync_state.LogError( |
| 1901 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1902 | "%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] | 1903 | func_name, string_SyncHazard(hazard.hazard), |
| 1904 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1905 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 1906 | string_UsageTag(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | if (stencil_write) { |
| 1910 | HazardResult hazard = |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1911 | current_context.DetectHazard(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 1912 | kDepthStencilAttachmentRasterOrder, offset, extent, VK_IMAGE_ASPECT_STENCIL_BIT); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1913 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1914 | skip |= sync_state.LogError( |
| 1915 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1916 | "%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] | 1917 | func_name, string_SyncHazard(hazard.hazard), |
| 1918 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1919 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 1920 | string_UsageTag(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1921 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1922 | } |
| 1923 | } |
| 1924 | return skip; |
| 1925 | } |
| 1926 | |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1927 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd, const VkRect2D &render_area, |
| 1928 | const ResourceUsageTag &tag) { |
| 1929 | const auto *pPipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1930 | if (!pPipe || |
| 1931 | (pPipe->graphicsPipelineCI.pRasterizationState && pPipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1932 | return; |
| 1933 | } |
| 1934 | const auto &list = pPipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1935 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
| 1936 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1937 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 1938 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1939 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 1940 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1941 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 1942 | for (const auto location : list) { |
| 1943 | if (location >= subpass.colorAttachmentCount || subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) |
| 1944 | continue; |
| 1945 | 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] | 1946 | current_context.UpdateAccessState(img_view_state, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, offset, extent, |
| 1947 | 0, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1948 | } |
| 1949 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1950 | |
| 1951 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 1952 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
| 1953 | if (pPipe->graphicsPipelineCI.pDepthStencilState && subpass.pDepthStencilAttachment && |
| 1954 | subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1955 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pDepthStencilAttachment->attachment]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1956 | bool depth_write = false, stencil_write = false; |
| 1957 | |
| 1958 | // PHASE1 TODO: These validation should be in core_checks. |
| 1959 | if (!FormatIsStencilOnly(img_view_state->create_info.format) && |
| 1960 | pPipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 1961 | pPipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
| 1962 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 1963 | depth_write = true; |
| 1964 | } |
| 1965 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 1966 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 1967 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 1968 | // PHASE1 TODO: These validation should be in core_checks. |
| 1969 | if (!FormatIsDepthOnly(img_view_state->create_info.format) && |
| 1970 | pPipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
| 1971 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 1972 | stencil_write = true; |
| 1973 | } |
| 1974 | |
| 1975 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 1976 | if (depth_write) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1977 | current_context.UpdateAccessState(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, offset, |
| 1978 | extent, VK_IMAGE_ASPECT_DEPTH_BIT, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1979 | } |
| 1980 | if (stencil_write) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1981 | current_context.UpdateAccessState(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, offset, |
| 1982 | extent, VK_IMAGE_ASPECT_STENCIL_BIT, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1983 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1984 | } |
| 1985 | } |
| 1986 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1987 | bool RenderPassAccessContext::ValidateNextSubpass(const SyncValidator &sync_state, const VkRect2D &render_area, |
| 1988 | const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1989 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1990 | bool skip = false; |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1991 | skip |= CurrentContext().ValidateResolveOperations(sync_state, *rp_state_, render_area, attachment_views_, func_name, |
| 1992 | current_subpass_); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1993 | skip |= CurrentContext().ValidateStoreOperation(sync_state, *rp_state_, render_area, current_subpass_, attachment_views_, |
| 1994 | func_name); |
| 1995 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1996 | const auto next_subpass = current_subpass_ + 1; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1997 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1998 | skip |= next_context.ValidateLayoutTransitions(sync_state, *rp_state_, render_area, next_subpass, attachment_views_, func_name); |
| 1999 | skip |= next_context.ValidateLoadOperation(sync_state, *rp_state_, render_area, next_subpass, attachment_views_, func_name); |
| 2000 | return skip; |
| 2001 | } |
| 2002 | bool RenderPassAccessContext::ValidateEndRenderPass(const SyncValidator &sync_state, const VkRect2D &render_area, |
| 2003 | const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2004 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2005 | bool skip = false; |
| 2006 | skip |= CurrentContext().ValidateResolveOperations(sync_state, *rp_state_, render_area, attachment_views_, func_name, |
| 2007 | current_subpass_); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2008 | skip |= CurrentContext().ValidateStoreOperation(sync_state, *rp_state_, render_area, current_subpass_, attachment_views_, |
| 2009 | func_name); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2010 | skip |= ValidateFinalSubpassLayoutTransitions(sync_state, render_area, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2011 | return skip; |
| 2012 | } |
| 2013 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2014 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy(const VkRect2D &render_area) const { |
| 2015 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, render_area, attachment_views_); |
| 2016 | } |
| 2017 | |
| 2018 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const SyncValidator &sync_state, const VkRect2D &render_area, |
| 2019 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2020 | bool skip = false; |
| 2021 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2022 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2023 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2024 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2025 | // to apply and only copy then, if this proves a hot spot. |
| 2026 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2027 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2028 | // Validate the "finalLayout" transitions to external |
| 2029 | // Get them from where there we're hidding in the extra entry. |
| 2030 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2031 | for (const auto &transition : final_transitions) { |
| 2032 | const auto &attach_view = attachment_views_[transition.attachment]; |
| 2033 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
| 2034 | 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] | 2035 | auto *context = trackback.context; |
| 2036 | |
| 2037 | if (transition.prev_pass == current_subpass_) { |
| 2038 | if (!proxy_for_current) { |
| 2039 | // We haven't recorded resolve ofor the current_subpass, so we need to copy current and update it *as if* |
| 2040 | proxy_for_current.reset(CreateStoreResolveProxy(render_area)); |
| 2041 | } |
| 2042 | context = proxy_for_current.get(); |
| 2043 | } |
| 2044 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2045 | // Use the merged barrier for the hazard check (safe since it just considers the src (first) scope. |
| 2046 | const auto merged_barrier = MergeBarriers(trackback.barriers); |
| 2047 | auto hazard = context->DetectImageBarrierHazard(*attach_view->image_state, merged_barrier.src_exec_scope, |
| 2048 | merged_barrier.src_access_scope, attach_view->normalized_subresource_range, |
| 2049 | AccessContext::DetectOptions::kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2050 | if (hazard.hazard) { |
| 2051 | skip |= sync_state.LogError(rp_state_->renderPass, string_SyncHazardVUID(hazard.hazard), |
| 2052 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 2053 | " final image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2054 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 2055 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2056 | string_UsageTag(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2057 | } |
| 2058 | } |
| 2059 | return skip; |
| 2060 | } |
| 2061 | |
| 2062 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag &tag) { |
| 2063 | // Add layout transitions... |
| 2064 | const auto &transitions = rp_state_->subpass_transitions[current_subpass_]; |
| 2065 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2066 | std::unordered_map<const IMAGE_VIEW_STATE *, ApplyBarrierOpsFunctor> view_ops; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2067 | for (const auto &transition : transitions) { |
| 2068 | const auto attachment_view = attachment_views_[transition.attachment]; |
| 2069 | if (!attachment_view) continue; |
| 2070 | const auto image = attachment_view->image_state.get(); |
| 2071 | if (!image) continue; |
| 2072 | |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2073 | const auto *trackback = subpass_context.GetTrackBackFromSubpass(transition.prev_pass); |
| 2074 | assert(trackback); |
John Zulauf | c920122 | 2020-05-13 15:13:03 -0600 | [diff] [blame] | 2075 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2076 | // And the trackback barriers to the to the barriers for this view |
| 2077 | auto found = view_ops.find(attachment_view); |
| 2078 | if (found != view_ops.end()) { |
| 2079 | // Add this set of barriers to the list for this view |
| 2080 | found->second.PushBack(trackback->barriers, true /* layout transition */); |
John Zulauf | c920122 | 2020-05-13 15:13:03 -0600 | [diff] [blame] | 2081 | } else { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2082 | // TODO: Aliasing. When we clean up for aliasing support, may need to reassess using true -> resolve, below. |
| 2083 | view_ops.insert(std::make_pair(attachment_view, ApplyBarrierOpsFunctor(true /* resolve */, trackback->barriers, |
| 2084 | true /* layout transition */, tag))); |
John Zulauf | c920122 | 2020-05-13 15:13:03 -0600 | [diff] [blame] | 2085 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2086 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2087 | // For each view with a layout transition, apply the barriers |
| 2088 | for (const auto &op : view_ops) { |
| 2089 | const auto view = op.first; |
| 2090 | const auto image = view->image_state.get(); |
| 2091 | subpass_context.UpdateResourceAccess(*image, view->normalized_subresource_range, op.second); |
| 2092 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2093 | } |
| 2094 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2095 | void RenderPassAccessContext::RecordLoadOperations(const VkRect2D &render_area, const ResourceUsageTag &tag) { |
| 2096 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2097 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
| 2098 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2099 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2100 | |
| 2101 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2102 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
| 2103 | if (attachment_views_[i] == nullptr) continue; // UNUSED |
| 2104 | const auto &view = *attachment_views_[i]; |
| 2105 | const IMAGE_STATE *image = view.image_state.get(); |
| 2106 | if (image == nullptr) continue; |
| 2107 | |
| 2108 | const auto &ci = attachment_ci[i]; |
| 2109 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2110 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2111 | const bool is_color = !(has_depth || has_stencil); |
| 2112 | |
| 2113 | if (is_color) { |
| 2114 | subpass_context.UpdateAccessState(*image, ColorLoadUsage(ci.loadOp), view.normalized_subresource_range, offset, |
| 2115 | extent, tag); |
| 2116 | } else { |
| 2117 | auto update_range = view.normalized_subresource_range; |
| 2118 | if (has_depth) { |
| 2119 | update_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 2120 | subpass_context.UpdateAccessState(*image, DepthStencilLoadUsage(ci.loadOp), update_range, offset, extent, tag); |
| 2121 | } |
| 2122 | if (has_stencil) { |
| 2123 | update_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 2124 | subpass_context.UpdateAccessState(*image, DepthStencilLoadUsage(ci.stencilLoadOp), update_range, offset, extent, |
| 2125 | tag); |
| 2126 | } |
| 2127 | } |
| 2128 | } |
| 2129 | } |
| 2130 | } |
| 2131 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2132 | void RenderPassAccessContext::RecordBeginRenderPass(const SyncValidator &state, const CMD_BUFFER_STATE &cb_state, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2133 | const AccessContext *external_context, VkQueueFlags queue_flags, |
| 2134 | const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2135 | current_subpass_ = 0; |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 2136 | rp_state_ = cb_state.activeRenderPass.get(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2137 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
| 2138 | // Add this for all subpasses here so that they exsist during next subpass validation |
| 2139 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2140 | 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] | 2141 | } |
| 2142 | attachment_views_ = state.GetCurrentAttachmentViews(cb_state); |
| 2143 | |
| 2144 | RecordLayoutTransitions(tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2145 | RecordLoadOperations(cb_state.activeRenderPassBeginInfo.renderArea, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2146 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2147 | |
| 2148 | void RenderPassAccessContext::RecordNextSubpass(const VkRect2D &render_area, const ResourceUsageTag &tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2149 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
| 2150 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, render_area, attachment_views_, current_subpass_, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2151 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, render_area, attachment_views_, current_subpass_, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2152 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2153 | current_subpass_++; |
| 2154 | assert(current_subpass_ < subpass_contexts_.size()); |
| 2155 | RecordLayoutTransitions(tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2156 | RecordLoadOperations(render_area, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2157 | } |
| 2158 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2159 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const VkRect2D &render_area, |
| 2160 | const ResourceUsageTag &tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2161 | // Add the resolve and store accesses |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2162 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, render_area, attachment_views_, current_subpass_, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2163 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, render_area, attachment_views_, current_subpass_, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2164 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2165 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2166 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2167 | |
| 2168 | // Add the "finalLayout" transitions to external |
| 2169 | // Get them from where there we're hidding in the extra entry. |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2170 | // Not that since *final* always comes from *one* subpass per view, we don't have to accumulate the barriers |
| 2171 | // TODO Aliasing we may need to reconsider barrier accumulation... though I don't know that it would be valid for aliasing |
| 2172 | // that had mulitple final layout transistions from mulitple final subpasses. |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2173 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2174 | for (const auto &transition : final_transitions) { |
| 2175 | const auto &attachment = attachment_views_[transition.attachment]; |
| 2176 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | aa97d8b | 2020-07-14 10:58:13 -0600 | [diff] [blame] | 2177 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.context); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2178 | ApplyBarrierOpsFunctor barrier_ops(true /* resolve */, last_trackback.barriers, true /* layout transition */, tag); |
| 2179 | external_context->UpdateResourceAccess(*attachment->image_state, attachment->normalized_subresource_range, barrier_ops); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2180 | } |
| 2181 | } |
| 2182 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2183 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &barrier) { |
| 2184 | const auto src_stage_mask = ExpandPipelineStages(queue_flags, barrier.srcStageMask); |
| 2185 | src_exec_scope = WithEarlierPipelineStages(src_stage_mask); |
| 2186 | src_access_scope = SyncStageAccess::AccessScope(src_stage_mask, barrier.srcAccessMask); |
| 2187 | const auto dst_stage_mask = ExpandPipelineStages(queue_flags, barrier.dstStageMask); |
| 2188 | dst_exec_scope = WithLaterPipelineStages(dst_stage_mask); |
| 2189 | dst_access_scope = SyncStageAccess::AccessScope(dst_stage_mask, barrier.dstAccessMask); |
| 2190 | } |
| 2191 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2192 | // ApplyBarriers is design for *fully* inclusive barrier lists without layout tranistions. Designed use was for |
| 2193 | // inter-subpass barriers for lazy-evaluation of parent context memory ranges. Subpass layout transistions are *not* done |
| 2194 | // lazily, s.t. no previous access reports should need layout transitions. |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2195 | void ResourceAccessState::ApplyBarriers(const std::vector<SyncBarrier> &barriers) { |
| 2196 | for (const auto &barrier : barriers) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2197 | ApplyBarrier(barrier, false); |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2198 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2199 | ApplyPendingBarriers(kCurrentCommandTag); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2200 | } |
| 2201 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2202 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2203 | HazardResult hazard; |
| 2204 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2205 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2206 | if (IsRead(usage)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2207 | if (IsRAWHazard(usage_stage, usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2208 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2209 | } |
| 2210 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2211 | // Write operation: |
| 2212 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2213 | // If reads exists -- test only against them because either: |
| 2214 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2215 | // * 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 |
| 2216 | // the current write happens after the reads, so just test the write against the reades |
| 2217 | // Otherwise test against last_write |
| 2218 | // |
| 2219 | // Look for casus belli for WAR |
| 2220 | if (last_read_count) { |
| 2221 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
| 2222 | const auto &read_access = last_reads[read_index]; |
| 2223 | if (IsReadHazard(usage_stage, read_access)) { |
| 2224 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2225 | break; |
| 2226 | } |
| 2227 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2228 | } else if (last_write && IsWriteHazard(usage)) { |
| 2229 | // Write-After-Write check -- if we have a previous write to test against |
| 2230 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2231 | } |
| 2232 | } |
| 2233 | return hazard; |
| 2234 | } |
| 2235 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2236 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrderingBarrier &ordering) const { |
| 2237 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 2238 | HazardResult hazard; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2239 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2240 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2241 | const bool input_attachment_ordering = 0 != (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
| 2242 | const bool last_write_is_ordered = 0 != (last_write & ordering.access_scope); |
| 2243 | if (IsRead(usage_bit)) { |
| 2244 | // Exclude RAW if no write, or write not most "most recent" operation w.r.t. usage; |
| 2245 | bool is_raw_hazard = IsRAWHazard(usage_stage, usage_bit); |
| 2246 | if (is_raw_hazard) { |
| 2247 | // NOTE: we know last_write is non-zero |
| 2248 | // See if the ordering rules save us from the simple RAW check above |
| 2249 | // First check to see if the current usage is covered by the ordering rules |
| 2250 | const bool usage_is_input_attachment = (usage_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ); |
| 2251 | const bool usage_is_ordered = |
| 2252 | (input_attachment_ordering && usage_is_input_attachment) || (0 != (usage_stage & ordering.exec_scope)); |
| 2253 | if (usage_is_ordered) { |
| 2254 | // Now see of the most recent write (or a subsequent read) are ordered |
| 2255 | const bool most_recent_is_ordered = last_write_is_ordered || (0 != GetOrderedStages(ordering)); |
| 2256 | is_raw_hazard = !most_recent_is_ordered; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2257 | } |
| 2258 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2259 | if (is_raw_hazard) { |
| 2260 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 2261 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2262 | } else { |
| 2263 | // Only check for WAW if there are no reads since last_write |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2264 | bool usage_write_is_ordered = 0 != (usage_bit & ordering.access_scope); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2265 | if (last_read_count) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2266 | // Look for any WAR hazards outside the ordered set of stages |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2267 | VkPipelineStageFlags ordered_stages = 0; |
| 2268 | if (usage_write_is_ordered) { |
| 2269 | // If the usage is ordered, we can ignore all ordered read stages w.r.t. WAR) |
| 2270 | ordered_stages = GetOrderedStages(ordering); |
| 2271 | } |
| 2272 | // If we're tracking any reads that aren't ordered against the current write, got to check 'em all. |
| 2273 | if ((ordered_stages & last_read_stages) != last_read_stages) { |
| 2274 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
| 2275 | const auto &read_access = last_reads[read_index]; |
| 2276 | if (read_access.stage & ordered_stages) continue; // but we can skip the ordered ones |
| 2277 | if (IsReadHazard(usage_stage, read_access)) { |
| 2278 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2279 | break; |
| 2280 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2281 | } |
| 2282 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2283 | } else if (!(last_write_is_ordered && usage_write_is_ordered)) { |
| 2284 | if (last_write && IsWriteHazard(usage_bit)) { |
| 2285 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2286 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2287 | } |
| 2288 | } |
| 2289 | return hazard; |
| 2290 | } |
| 2291 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2292 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2293 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2294 | HazardResult hazard; |
| 2295 | auto usage = FlagBit(usage_index); |
| 2296 | if (IsRead(usage)) { |
| 2297 | if (last_write != 0) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2298 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2299 | } |
| 2300 | } else { |
| 2301 | if (last_write != 0) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2302 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2303 | } else if (last_read_count > 0) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2304 | // Any read could be reported, so we'll just pick the first one arbitrarily |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2305 | hazard.Set(this, usage_index, WRITE_RACING_READ, last_reads[0].access, last_reads[0].tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2306 | } |
| 2307 | } |
| 2308 | return hazard; |
| 2309 | } |
| 2310 | |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2311 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags src_exec_scope, |
| 2312 | SyncStageAccessFlags src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2313 | // Only supporting image layout transitions for now |
| 2314 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2315 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2316 | // only test for WAW if there no intervening read operations. |
| 2317 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 2318 | if (last_read_count) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2319 | // Look at the reads if any |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2320 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2321 | const auto &read_access = last_reads[read_index]; |
| 2322 | // If the read stage is not in the src sync sync |
| 2323 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 2324 | // then the barrier access is unsafe (R/W after R) |
| 2325 | if ((src_exec_scope & (read_access.stage | read_access.barriers)) == 0) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2326 | 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] | 2327 | break; |
| 2328 | } |
| 2329 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2330 | } else if (last_write) { |
| 2331 | // If the previous write is *not* in the 1st access scope |
| 2332 | // *AND* the current barrier is not in the dependency chain |
| 2333 | // *AND* the there is no prior memory barrier for the previous write in the dependency chain |
| 2334 | // then the barrier access is unsafe (R/W after W) |
| 2335 | if (((last_write & src_access_scope) == 0) && ((src_exec_scope & write_dependency_chain) == 0) && (write_barriers == 0)) { |
| 2336 | // TODO: Do we need a difference hazard name for this? |
| 2337 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2338 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2339 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2340 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2341 | return hazard; |
| 2342 | } |
| 2343 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2344 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 2345 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 2346 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 2347 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
| 2348 | if (write_tag.IsBefore(other.write_tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2349 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent |
| 2350 | // operation |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2351 | *this = other; |
| 2352 | } else if (!other.write_tag.IsBefore(write_tag)) { |
| 2353 | // This is the *equals* case for write operations, we merged the write barriers and the read state (but without the |
| 2354 | // dependency chaining logic or any stage expansion) |
| 2355 | write_barriers |= other.write_barriers; |
| 2356 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2357 | // Merge the read states |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2358 | const auto pre_merge_count = last_read_count; |
| 2359 | const auto pre_merge_stages = last_read_stages; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2360 | for (uint32_t other_read_index = 0; other_read_index < other.last_read_count; other_read_index++) { |
| 2361 | auto &other_read = other.last_reads[other_read_index]; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2362 | if (pre_merge_stages & other_read.stage) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2363 | // 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] | 2364 | // TODO: This is N^2 with stages... perhaps the ReadStates should be sorted by stage index. |
| 2365 | // but we should wait on profiling data for that. |
| 2366 | 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] | 2367 | auto &my_read = last_reads[my_read_index]; |
| 2368 | if (other_read.stage == my_read.stage) { |
| 2369 | if (my_read.tag.IsBefore(other_read.tag)) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2370 | // Other is more recent, copy in the state |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2371 | my_read.access = other_read.access; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2372 | my_read.tag = other_read.tag; |
| 2373 | if (my_read.stage == VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT) { |
| 2374 | // Since I'm overwriting the fragement stage read, also update the input attachment info |
| 2375 | // as this is the only stage that affects it. |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame^] | 2376 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2377 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2378 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2379 | // TODO: Phase 2 -- review the state merge logic to avoid false negative from the OR'ing of the barriers |
| 2380 | // May require tracking more than one access per stage. |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2381 | my_read.barriers |= other_read.barriers; |
| 2382 | break; |
| 2383 | } |
| 2384 | } |
| 2385 | } else { |
| 2386 | // The other read stage doesn't exist in this, so add it. |
| 2387 | last_reads[last_read_count] = other_read; |
| 2388 | last_read_count++; |
| 2389 | last_read_stages |= other_read.stage; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2390 | if (other_read.stage == VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame^] | 2391 | input_attachment_read = other.input_attachment_read; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2392 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2393 | } |
| 2394 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2395 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2396 | } // the else clause would be that other write is before this write... in which case we supercede the other state and |
| 2397 | // ignore it. |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2398 | } |
| 2399 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2400 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, const ResourceUsageTag &tag) { |
| 2401 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 2402 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2403 | if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2404 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 2405 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 2406 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2407 | uint32_t update_index = kStageCount; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2408 | if (usage_stage & last_read_stages) { |
| 2409 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2410 | if (last_reads[read_index].stage == usage_stage) { |
| 2411 | update_index = read_index; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2412 | break; |
| 2413 | } |
| 2414 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2415 | assert(update_index < last_read_count); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2416 | } else { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2417 | assert(last_read_count < last_reads.size()); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2418 | update_index = last_read_count++; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2419 | last_read_stages |= usage_stage; |
| 2420 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2421 | last_reads[update_index].Set(usage_stage, usage_bit, 0, tag); |
| 2422 | |
| 2423 | // Fragment shader reads come in two flavors, and we need to track if the one we're tracking is the special one. |
| 2424 | if (usage_stage == VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT) { |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame^] | 2425 | // TODO Revisit re: multiple reads for a given stage |
| 2426 | input_attachment_read = (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2427 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2428 | } else { |
| 2429 | // Assume write |
| 2430 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2431 | SetWrite(usage_bit, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2432 | } |
| 2433 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2434 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2435 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
| 2436 | // if the last_reads/last_write were unsafe, we've reported them, in either case the prior access is irrelevant. |
| 2437 | // We can overwrite them as *this* write is now after them. |
| 2438 | // |
| 2439 | // Note: intentionally ignore pending barriers and chains (i.e. don't apply or clear them), let ApplyPendingBarriers handle them. |
| 2440 | void ResourceAccessState::SetWrite(SyncStageAccessFlagBits usage_bit, const ResourceUsageTag &tag) { |
| 2441 | last_read_count = 0; |
| 2442 | last_read_stages = 0; |
| 2443 | read_execution_barriers = 0; |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame^] | 2444 | 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] | 2445 | |
| 2446 | write_barriers = 0; |
| 2447 | write_dependency_chain = 0; |
| 2448 | write_tag = tag; |
| 2449 | last_write = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2450 | } |
| 2451 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2452 | // Apply the memory barrier without updating the existing barriers. The execution barrier |
| 2453 | // changes the "chaining" state, but to keep barriers independent, we defer this until all barriers |
| 2454 | // of the batch have been processed. Also, depending on whether layout transition happens, we'll either |
| 2455 | // replace the current write barriers or add to them, so accumulate to pending as well. |
| 2456 | void ResourceAccessState::ApplyBarrier(const SyncBarrier &barrier, bool layout_transition) { |
| 2457 | // For independent barriers we need to track what the new barriers and dependency chain *will* be when we're done |
| 2458 | // applying the memory barriers |
| 2459 | if (InSourceScopeOrChain(barrier.src_exec_scope, barrier.src_access_scope)) { |
| 2460 | pending_write_barriers |= barrier.dst_access_scope; |
| 2461 | pending_write_dep_chain |= barrier.dst_exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2462 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2463 | // Track layout transistion as pending as we can't modify last_write until all barriers processed |
| 2464 | pending_layout_transition |= layout_transition; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2465 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2466 | if (!pending_layout_transition) { |
| 2467 | // Once we're dealing with a layout transition (which is modelled as a *write*) then the last reads/writes/chains |
| 2468 | // don't need to be tracked as we're just going to zero them. |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2469 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2470 | ReadState &access = last_reads[read_index]; |
| 2471 | // The | implements the "dependency chain" logic for this access, as the barriers field stores the second sync scope |
| 2472 | if (barrier.src_exec_scope & (access.stage | access.barriers)) { |
| 2473 | access.pending_dep_chain |= barrier.dst_exec_scope; |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2474 | } |
| 2475 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2476 | } |
John Zulauf | a0a9829 | 2020-09-18 09:30:10 -0600 | [diff] [blame] | 2477 | } |
| 2478 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2479 | void ResourceAccessState::ApplyPendingBarriers(const ResourceUsageTag &tag) { |
| 2480 | if (pending_layout_transition) { |
| 2481 | // Should only be true for valid tags -- barrier/subpass record not "resolve previous" traversals... |
| 2482 | assert(tag != kCurrentCommandTag); |
| 2483 | // SetWrite clobbers the read count, and thus we don't have to clear the read_state out. |
| 2484 | SetWrite(SYNC_IMAGE_LAYOUT_TRANSITION_BIT, tag); // Side effect notes below |
| 2485 | pending_layout_transition = false; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2486 | } |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2487 | |
| 2488 | // Apply the accumulate execution barriers (and thus update chaining information) |
| 2489 | // for layout transition, read count is zeroed by SetWrite, so this will be skipped. |
| 2490 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
| 2491 | ReadState &access = last_reads[read_index]; |
| 2492 | access.barriers |= access.pending_dep_chain; |
| 2493 | read_execution_barriers |= access.barriers; |
| 2494 | access.pending_dep_chain = 0; |
| 2495 | } |
| 2496 | |
| 2497 | // We OR in the accumulated write chain and barriers even in the case of a layout transition as SetWrite zeros them. |
| 2498 | write_dependency_chain |= pending_write_dep_chain; |
| 2499 | write_barriers |= pending_write_barriers; |
| 2500 | pending_write_dep_chain = 0; |
| 2501 | pending_write_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2502 | } |
| 2503 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2504 | // This should be just Bits or Index, but we don't have an invalid state for Index |
| 2505 | VkPipelineStageFlags ResourceAccessState::GetReadBarriers(SyncStageAccessFlags usage_bit) const { |
| 2506 | VkPipelineStageFlags barriers = 0U; |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2507 | |
| 2508 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
| 2509 | const auto &read_access = last_reads[read_index]; |
| 2510 | if (read_access.access & usage_bit) { |
| 2511 | barriers = read_access.barriers; |
| 2512 | break; |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2513 | } |
| 2514 | } |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2515 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2516 | return barriers; |
| 2517 | } |
| 2518 | |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2519 | inline bool ResourceAccessState::IsRAWHazard(VkPipelineStageFlagBits usage_stage, SyncStageAccessFlagBits usage) const { |
| 2520 | assert(IsRead(usage)); |
| 2521 | // Only RAW vs. last_write if it doesn't happen-after any other read because either: |
| 2522 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 2523 | // any reads that happen after. |
| 2524 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 2525 | // the current read will be also not be a hazard, thus reporting a hazard here adds no needed information. |
| 2526 | return (0 != last_write) && (0 == (read_execution_barriers & usage_stage)) && IsWriteHazard(usage); |
| 2527 | } |
| 2528 | |
| 2529 | bool ResourceAccessState::IsWARHazard(VkPipelineStageFlagBits usage_stage, SyncStageAccessFlagBits usage) const { return false; } |
| 2530 | |
| 2531 | VkPipelineStageFlags ResourceAccessState::GetOrderedStages(const SyncOrderingBarrier &ordering) const { |
| 2532 | // Whether the stage are in the ordering scope only matters if the current write is ordered |
| 2533 | VkPipelineStageFlags ordered_stages = last_read_stages & ordering.exec_scope; |
| 2534 | // Special input attachment handling as always (not encoded in exec_scop) |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2535 | const bool input_attachment_ordering = 0 != (ordering.access_scope & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT); |
John Zulauf | f51fbb6 | 2020-10-02 14:43:24 -0600 | [diff] [blame^] | 2536 | if (input_attachment_ordering && input_attachment_read) { |
John Zulauf | 4285ee9 | 2020-09-23 10:20:52 -0600 | [diff] [blame] | 2537 | // If we have an input attachment in last_reads and input attachments are ordered we all that stage |
| 2538 | ordered_stages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; |
| 2539 | } |
| 2540 | |
| 2541 | return ordered_stages; |
| 2542 | } |
| 2543 | |
| 2544 | inline ResourceAccessState::ReadState *ResourceAccessState::GetReadStateForStage(VkPipelineStageFlagBits stage, |
| 2545 | uint32_t search_limit) { |
| 2546 | ReadState *read_state = nullptr; |
| 2547 | search_limit = std::min(search_limit, last_read_count); |
| 2548 | for (uint32_t i = 0; i < search_limit; i++) { |
| 2549 | if (last_reads[i].stage == stage) { |
| 2550 | read_state = &last_reads[i]; |
| 2551 | break; |
| 2552 | } |
| 2553 | } |
| 2554 | return read_state; |
| 2555 | } |
| 2556 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 2557 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2558 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 2559 | if (access_context) { |
| 2560 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2561 | } |
| 2562 | } |
| 2563 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 2564 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 2565 | auto access_found = cb_access_state.find(command_buffer); |
| 2566 | if (access_found != cb_access_state.end()) { |
| 2567 | access_found->second->Reset(); |
| 2568 | cb_access_state.erase(access_found); |
| 2569 | } |
| 2570 | } |
| 2571 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2572 | void SyncValidator::ApplyGlobalBarriers(AccessContext *context, VkPipelineStageFlags src_exec_scope, |
| 2573 | VkPipelineStageFlags dst_exec_scope, SyncStageAccessFlags src_access_scope, |
| 2574 | SyncStageAccessFlags dst_access_scope, uint32_t memory_barrier_count, |
| 2575 | const VkMemoryBarrier *pMemoryBarriers, const ResourceUsageTag &tag) { |
| 2576 | ApplyBarrierOpsFunctor barriers_functor(true /* resolve */, std::min<uint32_t>(1, memory_barrier_count), tag); |
| 2577 | for (uint32_t barrier_index = 0; barrier_index < memory_barrier_count; barrier_index++) { |
| 2578 | const auto &barrier = pMemoryBarriers[barrier_index]; |
| 2579 | SyncBarrier sync_barrier(src_exec_scope, SyncStageAccess::AccessScope(src_access_scope, barrier.srcAccessMask), |
| 2580 | dst_exec_scope, SyncStageAccess::AccessScope(dst_access_scope, barrier.dstAccessMask)); |
| 2581 | barriers_functor.PushBack(sync_barrier, false); |
| 2582 | } |
| 2583 | if (0 == memory_barrier_count) { |
| 2584 | // If there are no global memory barriers, force an exec barrier |
| 2585 | barriers_functor.PushBack(SyncBarrier(src_exec_scope, 0, dst_exec_scope, 0), false); |
| 2586 | } |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2587 | context->ApplyGlobalBarriers(barriers_functor); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2588 | } |
| 2589 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2590 | void SyncValidator::ApplyBufferBarriers(AccessContext *context, VkPipelineStageFlags src_exec_scope, |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2591 | SyncStageAccessFlags src_stage_accesses, VkPipelineStageFlags dst_exec_scope, |
| 2592 | SyncStageAccessFlags dst_stage_accesses, uint32_t barrier_count, |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2593 | const VkBufferMemoryBarrier *barriers) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2594 | for (uint32_t index = 0; index < barrier_count; index++) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2595 | auto barrier = barriers[index]; // barrier is a copy |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2596 | const auto *buffer = Get<BUFFER_STATE>(barrier.buffer); |
| 2597 | if (!buffer) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2598 | barrier.size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 2599 | const ResourceAccessRange range = MakeRange(barrier); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2600 | const auto src_access_scope = AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 2601 | const auto dst_access_scope = AccessScope(dst_stage_accesses, barrier.dstAccessMask); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2602 | const SyncBarrier sync_barrier(src_exec_scope, src_access_scope, dst_exec_scope, dst_access_scope); |
| 2603 | const ApplyBarrierFunctor update_action(sync_barrier, false /* layout_transition */); |
| 2604 | context->UpdateResourceAccess(*buffer, range, update_action); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2605 | } |
| 2606 | } |
| 2607 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2608 | void SyncValidator::ApplyImageBarriers(AccessContext *context, VkPipelineStageFlags src_exec_scope, |
| 2609 | SyncStageAccessFlags src_stage_accesses, VkPipelineStageFlags dst_exec_scope, |
| 2610 | SyncStageAccessFlags dst_stage_accesses, uint32_t barrier_count, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2611 | const VkImageMemoryBarrier *barriers, const ResourceUsageTag &tag) { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2612 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 2613 | const auto &barrier = barriers[index]; |
| 2614 | const auto *image = Get<IMAGE_STATE>(barrier.image); |
| 2615 | if (!image) continue; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2616 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2617 | bool layout_transition = barrier.oldLayout != barrier.newLayout; |
| 2618 | const auto src_access_scope = AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 2619 | const auto dst_access_scope = AccessScope(dst_stage_accesses, barrier.dstAccessMask); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2620 | const SyncBarrier sync_barrier(src_exec_scope, src_access_scope, dst_exec_scope, dst_access_scope); |
| 2621 | const ApplyBarrierFunctor barrier_action(sync_barrier, layout_transition); |
| 2622 | context->UpdateResourceAccess(*image, subresource_range, barrier_action); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2623 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 2627 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 2628 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2629 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 2630 | assert(cb_context); |
| 2631 | if (!cb_context) return skip; |
| 2632 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2633 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2634 | // If we have no previous accesses, we have no hazards |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2635 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2636 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2637 | |
| 2638 | for (uint32_t region = 0; region < regionCount; region++) { |
| 2639 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2640 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2641 | 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] | 2642 | auto hazard = context->DetectHazard(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2643 | if (hazard.hazard) { |
| 2644 | // TODO -- add tag information to log msg when useful. |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 2645 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2646 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2647 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2648 | string_UsageTag(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2649 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2650 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2651 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2652 | 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] | 2653 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2654 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 2655 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2656 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2657 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2658 | string_UsageTag(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2659 | } |
| 2660 | } |
| 2661 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2662 | } |
| 2663 | return skip; |
| 2664 | } |
| 2665 | |
| 2666 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 2667 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2668 | auto *cb_context = GetAccessContext(commandBuffer); |
| 2669 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 2670 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2671 | auto *context = cb_context->GetCurrentAccessContext(); |
| 2672 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2673 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2674 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2675 | |
| 2676 | for (uint32_t region = 0; region < regionCount; region++) { |
| 2677 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2678 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2679 | 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] | 2680 | context->UpdateAccessState(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2681 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2682 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 2683 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2684 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2685 | } |
| 2686 | } |
| 2687 | } |
| 2688 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 2689 | bool SyncValidator::PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 2690 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) const { |
| 2691 | bool skip = false; |
| 2692 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 2693 | assert(cb_context); |
| 2694 | if (!cb_context) return skip; |
| 2695 | const auto *context = cb_context->GetCurrentAccessContext(); |
| 2696 | |
| 2697 | // If we have no previous accesses, we have no hazards |
| 2698 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 2699 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 2700 | |
| 2701 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 2702 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 2703 | if (src_buffer) { |
| 2704 | const ResourceAccessRange src_range = MakeRange(*src_buffer, copy_region.srcOffset, copy_region.size); |
| 2705 | auto hazard = context->DetectHazard(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range); |
| 2706 | if (hazard.hazard) { |
| 2707 | // TODO -- add tag information to log msg when useful. |
| 2708 | skip |= LogError(pCopyBufferInfos->srcBuffer, string_SyncHazardVUID(hazard.hazard), |
| 2709 | "vkCmdCopyBuffer2KHR(): Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
| 2710 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->srcBuffer).c_str(), |
| 2711 | region, string_UsageTag(hazard).c_str()); |
| 2712 | } |
| 2713 | } |
| 2714 | if (dst_buffer && !skip) { |
| 2715 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
| 2716 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range); |
| 2717 | if (hazard.hazard) { |
| 2718 | skip |= LogError(pCopyBufferInfos->dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 2719 | "vkCmdCopyBuffer2KHR(): Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
| 2720 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyBufferInfos->dstBuffer).c_str(), |
| 2721 | region, string_UsageTag(hazard).c_str()); |
| 2722 | } |
| 2723 | } |
| 2724 | if (skip) break; |
| 2725 | } |
| 2726 | return skip; |
| 2727 | } |
| 2728 | |
| 2729 | void SyncValidator::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 2730 | auto *cb_context = GetAccessContext(commandBuffer); |
| 2731 | assert(cb_context); |
| 2732 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER2KHR); |
| 2733 | auto *context = cb_context->GetCurrentAccessContext(); |
| 2734 | |
| 2735 | const auto *src_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->srcBuffer); |
| 2736 | const auto *dst_buffer = Get<BUFFER_STATE>(pCopyBufferInfos->dstBuffer); |
| 2737 | |
| 2738 | for (uint32_t region = 0; region < pCopyBufferInfos->regionCount; region++) { |
| 2739 | const auto ©_region = pCopyBufferInfos->pRegions[region]; |
| 2740 | if (src_buffer) { |
| 2741 | const ResourceAccessRange src_range = MakeRange(*src_buffer, copy_region.srcOffset, copy_region.size); |
| 2742 | context->UpdateAccessState(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range, tag); |
| 2743 | } |
| 2744 | if (dst_buffer) { |
| 2745 | const ResourceAccessRange dst_range = MakeRange(*dst_buffer, copy_region.dstOffset, copy_region.size); |
| 2746 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range, tag); |
| 2747 | } |
| 2748 | } |
| 2749 | } |
| 2750 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2751 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2752 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2753 | const VkImageCopy *pRegions) const { |
| 2754 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2755 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2756 | assert(cb_access_context); |
| 2757 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2758 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2759 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 2760 | assert(context); |
| 2761 | if (!context) return skip; |
| 2762 | |
| 2763 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 2764 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2765 | for (uint32_t region = 0; region < regionCount; region++) { |
| 2766 | const auto ©_region = pRegions[region]; |
| 2767 | if (src_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2768 | 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] | 2769 | copy_region.srcOffset, copy_region.extent); |
| 2770 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 2771 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2772 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2773 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2774 | string_UsageTag(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2775 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 2779 | VkExtent3D dst_copy_extent = |
| 2780 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2781 | 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] | 2782 | copy_region.dstOffset, dst_copy_extent); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2783 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 2784 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2785 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2786 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2787 | string_UsageTag(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2788 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 2789 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2790 | } |
| 2791 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2792 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2793 | return skip; |
| 2794 | } |
| 2795 | |
| 2796 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2797 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2798 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2799 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2800 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 2801 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2802 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 2803 | assert(context); |
| 2804 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2805 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2806 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2807 | |
| 2808 | for (uint32_t region = 0; region < regionCount; region++) { |
| 2809 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2810 | if (src_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2811 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, copy_region.srcSubresource, copy_region.srcOffset, |
| 2812 | copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2813 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2814 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 2815 | VkExtent3D dst_copy_extent = |
| 2816 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2817 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, copy_region.dstSubresource, copy_region.dstOffset, |
| 2818 | dst_copy_extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2819 | } |
| 2820 | } |
| 2821 | } |
| 2822 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 2823 | bool SyncValidator::PreCallValidateCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 2824 | const VkCopyImageInfo2KHR *pCopyImageInfo) const { |
| 2825 | bool skip = false; |
| 2826 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2827 | assert(cb_access_context); |
| 2828 | if (!cb_access_context) return skip; |
| 2829 | |
| 2830 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 2831 | assert(context); |
| 2832 | if (!context) return skip; |
| 2833 | |
| 2834 | const auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 2835 | const auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 2836 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 2837 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 2838 | if (src_image) { |
| 2839 | auto hazard = context->DetectHazard(*src_image, SYNC_TRANSFER_TRANSFER_READ, copy_region.srcSubresource, |
| 2840 | copy_region.srcOffset, copy_region.extent); |
| 2841 | if (hazard.hazard) { |
| 2842 | skip |= LogError(pCopyImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 2843 | "vkCmdCopyImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 2844 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->srcImage).c_str(), |
| 2845 | region, string_UsageTag(hazard).c_str()); |
| 2846 | } |
| 2847 | } |
| 2848 | |
| 2849 | if (dst_image) { |
| 2850 | VkExtent3D dst_copy_extent = |
| 2851 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
| 2852 | auto hazard = context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, copy_region.dstSubresource, |
| 2853 | copy_region.dstOffset, dst_copy_extent); |
| 2854 | if (hazard.hazard) { |
| 2855 | skip |= LogError(pCopyImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 2856 | "vkCmdCopyImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 2857 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pCopyImageInfo->dstImage).c_str(), |
| 2858 | region, string_UsageTag(hazard).c_str()); |
| 2859 | } |
| 2860 | if (skip) break; |
| 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | return skip; |
| 2865 | } |
| 2866 | |
| 2867 | void SyncValidator::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 2868 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2869 | assert(cb_access_context); |
| 2870 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE2KHR); |
| 2871 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 2872 | assert(context); |
| 2873 | |
| 2874 | auto *src_image = Get<IMAGE_STATE>(pCopyImageInfo->srcImage); |
| 2875 | auto *dst_image = Get<IMAGE_STATE>(pCopyImageInfo->dstImage); |
| 2876 | |
| 2877 | for (uint32_t region = 0; region < pCopyImageInfo->regionCount; region++) { |
| 2878 | const auto ©_region = pCopyImageInfo->pRegions[region]; |
| 2879 | if (src_image) { |
| 2880 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, copy_region.srcSubresource, copy_region.srcOffset, |
| 2881 | copy_region.extent, tag); |
| 2882 | } |
| 2883 | if (dst_image) { |
| 2884 | VkExtent3D dst_copy_extent = |
| 2885 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
| 2886 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, copy_region.dstSubresource, copy_region.dstOffset, |
| 2887 | dst_copy_extent, tag); |
| 2888 | } |
| 2889 | } |
| 2890 | } |
| 2891 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2892 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 2893 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 2894 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 2895 | uint32_t bufferMemoryBarrierCount, |
| 2896 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 2897 | uint32_t imageMemoryBarrierCount, |
| 2898 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 2899 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2900 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2901 | assert(cb_access_context); |
| 2902 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2903 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2904 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 2905 | assert(context); |
| 2906 | if (!context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2907 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2908 | const auto src_stage_mask = ExpandPipelineStages(cb_access_context->GetQueueFlags(), srcStageMask); |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2909 | const auto src_exec_scope = WithEarlierPipelineStages(src_stage_mask); |
| 2910 | auto src_stage_accesses = AccessScopeByStage(src_stage_mask); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2911 | // Validate Image Layout transitions |
| 2912 | for (uint32_t index = 0; index < imageMemoryBarrierCount; index++) { |
| 2913 | const auto &barrier = pImageMemoryBarriers[index]; |
| 2914 | if (barrier.newLayout == barrier.oldLayout) continue; // Only interested in layout transitions at this point. |
| 2915 | const auto *image_state = Get<IMAGE_STATE>(barrier.image); |
| 2916 | if (!image_state) continue; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2917 | const auto hazard = context->DetectImageBarrierHazard(*image_state, src_exec_scope, src_stage_accesses, barrier); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2918 | if (hazard.hazard) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2919 | // PHASE1 TODO -- add tag information to log msg when useful. |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 2920 | skip |= LogError(barrier.image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2921 | "vkCmdPipelineBarrier: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2922 | string_SyncHazard(hazard.hazard), index, report_data->FormatHandle(barrier.image).c_str(), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2923 | string_UsageTag(hazard).c_str()); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2924 | } |
| 2925 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2926 | |
| 2927 | return skip; |
| 2928 | } |
| 2929 | |
| 2930 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 2931 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 2932 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 2933 | uint32_t bufferMemoryBarrierCount, |
| 2934 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 2935 | uint32_t imageMemoryBarrierCount, |
| 2936 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2937 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2938 | assert(cb_access_context); |
| 2939 | if (!cb_access_context) return; |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 2940 | const auto tag = cb_access_context->NextCommandTag(CMD_PIPELINEBARRIER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2941 | auto access_context = cb_access_context->GetCurrentAccessContext(); |
| 2942 | assert(access_context); |
| 2943 | if (!access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2944 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2945 | const auto src_stage_mask = ExpandPipelineStages(cb_access_context->GetQueueFlags(), srcStageMask); |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2946 | auto src_stage_accesses = AccessScopeByStage(src_stage_mask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2947 | const auto dst_stage_mask = ExpandPipelineStages(cb_access_context->GetQueueFlags(), dstStageMask); |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2948 | auto dst_stage_accesses = AccessScopeByStage(dst_stage_mask); |
| 2949 | const auto src_exec_scope = WithEarlierPipelineStages(src_stage_mask); |
| 2950 | const auto dst_exec_scope = WithLaterPipelineStages(dst_stage_mask); |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2951 | |
| 2952 | // These two apply barriers one at a time as the are restricted to the resource ranges specified per each barrier, |
| 2953 | // but do not update the dependency chain information (but set the "pending" state) // s.t. the order independence |
| 2954 | // of the barriers is maintained. |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2955 | ApplyBufferBarriers(access_context, src_exec_scope, src_stage_accesses, dst_exec_scope, dst_stage_accesses, |
| 2956 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2957 | ApplyImageBarriers(access_context, src_exec_scope, src_stage_accesses, dst_exec_scope, dst_stage_accesses, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2958 | imageMemoryBarrierCount, pImageMemoryBarriers, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2959 | |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2960 | // Apply the global barriers last as is it walks all memory, it can also clean up the "pending" state without requiring an |
| 2961 | // additional pass, updating the dependency chains *last* as it goes along. |
| 2962 | // This is needed to guarantee order independence of the three lists. |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2963 | ApplyGlobalBarriers(access_context, src_exec_scope, dst_exec_scope, src_stage_accesses, dst_stage_accesses, memoryBarrierCount, |
John Zulauf | 89311b4 | 2020-09-29 16:28:47 -0600 | [diff] [blame] | 2964 | pMemoryBarriers, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | void SyncValidator::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 2968 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result) { |
| 2969 | // The state tracker sets up the device state |
| 2970 | StateTracker::PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, result); |
| 2971 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2972 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 2973 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2974 | // TODO: Find a good way to do this hooklessly. |
| 2975 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 2976 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, LayerObjectTypeSyncValidation); |
| 2977 | SyncValidator *sync_device_state = static_cast<SyncValidator *>(validation_data); |
| 2978 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 2979 | sync_device_state->SetCommandBufferResetCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 2980 | sync_device_state->ResetCommandBufferCallback(command_buffer); |
| 2981 | }); |
| 2982 | sync_device_state->SetCommandBufferFreeCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 2983 | sync_device_state->FreeCommandBufferCallback(command_buffer); |
| 2984 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2985 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2986 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2987 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 2988 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo, const char *func_name) const { |
| 2989 | bool skip = false; |
| 2990 | const auto rp_state = Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
| 2991 | auto cb_context = GetAccessContext(commandBuffer); |
| 2992 | |
| 2993 | if (rp_state && cb_context) { |
| 2994 | skip |= cb_context->ValidateBeginRenderPass(*rp_state, pRenderPassBegin, pSubpassBeginInfo, func_name); |
| 2995 | } |
| 2996 | |
| 2997 | return skip; |
| 2998 | } |
| 2999 | |
| 3000 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3001 | VkSubpassContents contents) const { |
| 3002 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 3003 | auto subpass_begin_info = lvl_init_struct<VkSubpassBeginInfo>(); |
| 3004 | subpass_begin_info.contents = contents; |
| 3005 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, "vkCmdBeginRenderPass"); |
| 3006 | return skip; |
| 3007 | } |
| 3008 | |
| 3009 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3010 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo) const { |
| 3011 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 3012 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, "vkCmdBeginRenderPass2"); |
| 3013 | return skip; |
| 3014 | } |
| 3015 | |
| 3016 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3017 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3018 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo) const { |
| 3019 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 3020 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, "vkCmdBeginRenderPass2KHR"); |
| 3021 | return skip; |
| 3022 | } |
| 3023 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3024 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 3025 | VkResult result) { |
| 3026 | // The state tracker sets up the command buffer state |
| 3027 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 3028 | |
| 3029 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 3030 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 3031 | assert(cb_access_context); |
| 3032 | cb_access_context->Reset(); |
| 3033 | } |
| 3034 | |
| 3035 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3036 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE command) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3037 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3038 | if (cb_context) { |
| 3039 | cb_context->RecordBeginRenderPass(cb_context->NextCommandTag(command)); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3040 | } |
| 3041 | } |
| 3042 | |
| 3043 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3044 | VkSubpassContents contents) { |
| 3045 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 3046 | auto subpass_begin_info = lvl_init_struct<VkSubpassBeginInfo>(); |
| 3047 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3048 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3052 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3053 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3054 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3058 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3059 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 3060 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3061 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
| 3062 | } |
| 3063 | |
| 3064 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfoKHR *pSubpassBeginInfo, |
| 3065 | const VkSubpassEndInfoKHR *pSubpassEndInfo, const char *func_name) const { |
| 3066 | bool skip = false; |
| 3067 | |
| 3068 | auto cb_context = GetAccessContext(commandBuffer); |
| 3069 | assert(cb_context); |
| 3070 | auto cb_state = cb_context->GetCommandBufferState(); |
| 3071 | if (!cb_state) return skip; |
| 3072 | |
| 3073 | auto rp_state = cb_state->activeRenderPass; |
| 3074 | if (!rp_state) return skip; |
| 3075 | |
| 3076 | skip |= cb_context->ValidateNextSubpass(func_name); |
| 3077 | |
| 3078 | return skip; |
| 3079 | } |
| 3080 | |
| 3081 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 3082 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
| 3083 | auto subpass_begin_info = lvl_init_struct<VkSubpassBeginInfo>(); |
| 3084 | subpass_begin_info.contents = contents; |
| 3085 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, "vkCmdNextSubpass"); |
| 3086 | return skip; |
| 3087 | } |
| 3088 | |
| 3089 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfoKHR *pSubpassBeginInfo, |
| 3090 | const VkSubpassEndInfoKHR *pSubpassEndInfo) const { |
| 3091 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
| 3092 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, "vkCmdNextSubpass2KHR"); |
| 3093 | return skip; |
| 3094 | } |
| 3095 | |
| 3096 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3097 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 3098 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
| 3099 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, "vkCmdNextSubpass2"); |
| 3100 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3104 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE command) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3105 | auto cb_context = GetAccessContext(commandBuffer); |
| 3106 | assert(cb_context); |
| 3107 | auto cb_state = cb_context->GetCommandBufferState(); |
| 3108 | if (!cb_state) return; |
| 3109 | |
| 3110 | auto rp_state = cb_state->activeRenderPass; |
| 3111 | if (!rp_state) return; |
| 3112 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3113 | cb_context->RecordNextSubpass(*rp_state, cb_context->NextCommandTag(command)); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 3117 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
| 3118 | auto subpass_begin_info = lvl_init_struct<VkSubpassBeginInfo>(); |
| 3119 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3120 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3124 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3125 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3126 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3130 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 3131 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3132 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3133 | } |
| 3134 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3135 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfoKHR *pSubpassEndInfo, |
| 3136 | const char *func_name) const { |
| 3137 | bool skip = false; |
| 3138 | |
| 3139 | auto cb_context = GetAccessContext(commandBuffer); |
| 3140 | assert(cb_context); |
| 3141 | auto cb_state = cb_context->GetCommandBufferState(); |
| 3142 | if (!cb_state) return skip; |
| 3143 | |
| 3144 | auto rp_state = cb_state->activeRenderPass; |
| 3145 | if (!rp_state) return skip; |
| 3146 | |
| 3147 | skip |= cb_context->ValidateEndRenderpass(func_name); |
| 3148 | return skip; |
| 3149 | } |
| 3150 | |
| 3151 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 3152 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
| 3153 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, "vkEndRenderPass"); |
| 3154 | return skip; |
| 3155 | } |
| 3156 | |
| 3157 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, |
| 3158 | const VkSubpassEndInfoKHR *pSubpassEndInfo) const { |
| 3159 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
| 3160 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, "vkEndRenderPass2"); |
| 3161 | return skip; |
| 3162 | } |
| 3163 | |
| 3164 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3165 | const VkSubpassEndInfoKHR *pSubpassEndInfo) const { |
| 3166 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
| 3167 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, "vkEndRenderPass2KHR"); |
| 3168 | return skip; |
| 3169 | } |
| 3170 | |
| 3171 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
| 3172 | CMD_TYPE command) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3173 | // Resolve the all subpass contexts to the command buffer contexts |
| 3174 | auto cb_context = GetAccessContext(commandBuffer); |
| 3175 | assert(cb_context); |
| 3176 | auto cb_state = cb_context->GetCommandBufferState(); |
| 3177 | if (!cb_state) return; |
| 3178 | |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 3179 | const auto *rp_state = cb_state->activeRenderPass.get(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3180 | if (!rp_state) return; |
| 3181 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3182 | cb_context->RecordEndRenderPass(*rp_state, cb_context->NextCommandTag(command)); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 3183 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3184 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 3185 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 3186 | // updates to a resource which do not conflict at the byte level. |
| 3187 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 3188 | // TODO: Add programatic control over suppression heuristics |
| 3189 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 3190 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 3191 | } |
| 3192 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3193 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3194 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3195 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3199 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3200 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3204 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 3205 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 3206 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3207 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3208 | template <typename BufferImageCopyRegionType> |
| 3209 | bool SyncValidator::ValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3210 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3211 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3212 | bool skip = false; |
| 3213 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3214 | assert(cb_access_context); |
| 3215 | if (!cb_access_context) return skip; |
| 3216 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3217 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3218 | const char *func_name = is_2khr ? "vkCmdCopyBufferToImage2KHR()" : "vkCmdCopyBufferToImage()"; |
| 3219 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3220 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3221 | assert(context); |
| 3222 | if (!context) return skip; |
| 3223 | |
| 3224 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3225 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3226 | |
| 3227 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3228 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3229 | if (src_buffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3230 | ResourceAccessRange src_range = |
| 3231 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
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); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3233 | if (hazard.hazard) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 3234 | // PHASE1 TODO -- add tag information to log msg when useful. |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3235 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3236 | "%s: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3237 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3238 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3239 | } |
| 3240 | } |
| 3241 | if (dst_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3242 | auto hazard = context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, copy_region.imageSubresource, |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3243 | copy_region.imageOffset, copy_region.imageExtent); |
| 3244 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3245 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3246 | "%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] | 3247 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3248 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3249 | } |
| 3250 | if (skip) break; |
| 3251 | } |
| 3252 | if (skip) break; |
| 3253 | } |
| 3254 | return skip; |
| 3255 | } |
| 3256 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3257 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3258 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3259 | const VkBufferImageCopy *pRegions) const { |
| 3260 | return ValidateCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, |
| 3261 | COPY_COMMAND_VERSION_1); |
| 3262 | } |
| 3263 | |
| 3264 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3265 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) const { |
| 3266 | return ValidateCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3267 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3268 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3269 | } |
| 3270 | |
| 3271 | template <typename BufferImageCopyRegionType> |
| 3272 | void SyncValidator::RecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3273 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3274 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3275 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3276 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3277 | |
| 3278 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3279 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYBUFFERTOIMAGE2KHR : CMD_COPYBUFFERTOIMAGE; |
| 3280 | |
| 3281 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3282 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3283 | assert(context); |
| 3284 | |
| 3285 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3286 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3287 | |
| 3288 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3289 | const auto ©_region = pRegions[region]; |
| 3290 | if (src_buffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3291 | ResourceAccessRange src_range = |
| 3292 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3293 | context->UpdateAccessState(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3294 | } |
| 3295 | if (dst_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3296 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, copy_region.imageSubresource, |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3297 | copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3298 | } |
| 3299 | } |
| 3300 | } |
| 3301 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3302 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3303 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3304 | const VkBufferImageCopy *pRegions) { |
| 3305 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
| 3306 | RecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3307 | } |
| 3308 | |
| 3309 | void SyncValidator::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 3310 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 3311 | StateTracker::PreCallRecordCmdCopyBufferToImage2KHR(commandBuffer, pCopyBufferToImageInfo); |
| 3312 | RecordCmdCopyBufferToImage(commandBuffer, pCopyBufferToImageInfo->srcBuffer, pCopyBufferToImageInfo->dstImage, |
| 3313 | pCopyBufferToImageInfo->dstImageLayout, pCopyBufferToImageInfo->regionCount, |
| 3314 | pCopyBufferToImageInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3315 | } |
| 3316 | |
| 3317 | template <typename BufferImageCopyRegionType> |
| 3318 | bool SyncValidator::ValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3319 | VkBuffer dstBuffer, uint32_t regionCount, |
| 3320 | const BufferImageCopyRegionType *pRegions, CopyCommandVersion version) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3321 | bool skip = false; |
| 3322 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3323 | assert(cb_access_context); |
| 3324 | if (!cb_access_context) return skip; |
| 3325 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3326 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3327 | const char *func_name = is_2khr ? "vkCmdCopyImageToBuffer2KHR()" : "vkCmdCopyImageToBuffer()"; |
| 3328 | |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3329 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3330 | assert(context); |
| 3331 | if (!context) return skip; |
| 3332 | |
| 3333 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3334 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3335 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->binding.mem_state->mem : VK_NULL_HANDLE; |
| 3336 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3337 | const auto ©_region = pRegions[region]; |
| 3338 | if (src_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3339 | 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] | 3340 | copy_region.imageOffset, copy_region.imageExtent); |
| 3341 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3342 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3343 | "%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] | 3344 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3345 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3346 | } |
| 3347 | } |
| 3348 | if (dst_mem) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3349 | ResourceAccessRange dst_range = |
| 3350 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3351 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3352 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3353 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3354 | "%s: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", func_name, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3355 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3356 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3357 | } |
| 3358 | } |
| 3359 | if (skip) break; |
| 3360 | } |
| 3361 | return skip; |
| 3362 | } |
| 3363 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3364 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 3365 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 3366 | const VkBufferImageCopy *pRegions) const { |
| 3367 | return ValidateCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, |
| 3368 | COPY_COMMAND_VERSION_1); |
| 3369 | } |
| 3370 | |
| 3371 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3372 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) const { |
| 3373 | return ValidateCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3374 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3375 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3376 | } |
| 3377 | |
| 3378 | template <typename BufferImageCopyRegionType> |
| 3379 | void SyncValidator::RecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3380 | VkBuffer dstBuffer, uint32_t regionCount, const BufferImageCopyRegionType *pRegions, |
| 3381 | CopyCommandVersion version) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3382 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3383 | assert(cb_access_context); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3384 | |
| 3385 | const bool is_2khr = (version == COPY_COMMAND_VERSION_2); |
| 3386 | const CMD_TYPE cmd_type = is_2khr ? CMD_COPYIMAGETOBUFFER2KHR : CMD_COPYIMAGETOBUFFER; |
| 3387 | |
| 3388 | const auto tag = cb_access_context->NextCommandTag(cmd_type); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3389 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3390 | assert(context); |
| 3391 | |
| 3392 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3393 | auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3394 | 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] | 3395 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3396 | |
| 3397 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3398 | const auto ©_region = pRegions[region]; |
| 3399 | if (src_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3400 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, copy_region.imageSubresource, |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3401 | copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3402 | } |
| 3403 | if (dst_buffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3404 | ResourceAccessRange dst_range = |
| 3405 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3406 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | } |
| 3410 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3411 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3412 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 3413 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
| 3414 | RecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions, COPY_COMMAND_VERSION_1); |
| 3415 | } |
| 3416 | |
| 3417 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 3418 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 3419 | StateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(commandBuffer, pCopyImageToBufferInfo); |
| 3420 | RecordCmdCopyImageToBuffer(commandBuffer, pCopyImageToBufferInfo->srcImage, pCopyImageToBufferInfo->srcImageLayout, |
| 3421 | pCopyImageToBufferInfo->dstBuffer, pCopyImageToBufferInfo->regionCount, |
| 3422 | pCopyImageToBufferInfo->pRegions, COPY_COMMAND_VERSION_2); |
| 3423 | } |
| 3424 | |
| 3425 | template <typename RegionType> |
| 3426 | bool SyncValidator::ValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3427 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3428 | const RegionType *pRegions, VkFilter filter, const char *apiName) const { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3429 | bool skip = false; |
| 3430 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3431 | assert(cb_access_context); |
| 3432 | if (!cb_access_context) return skip; |
| 3433 | |
| 3434 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3435 | assert(context); |
| 3436 | if (!context) return skip; |
| 3437 | |
| 3438 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3439 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3440 | |
| 3441 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3442 | const auto &blit_region = pRegions[region]; |
| 3443 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3444 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3445 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3446 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3447 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3448 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3449 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].z - blit_region.srcOffsets[0].z))}; |
| 3450 | auto hazard = |
| 3451 | 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] | 3452 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3453 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3454 | "%s: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3455 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3456 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3461 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3462 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3463 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3464 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3465 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3466 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].z - blit_region.dstOffsets[0].z))}; |
| 3467 | auto hazard = |
| 3468 | 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] | 3469 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3470 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3471 | "%s: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", apiName, |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3472 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3473 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3474 | } |
| 3475 | if (skip) break; |
| 3476 | } |
| 3477 | } |
| 3478 | |
| 3479 | return skip; |
| 3480 | } |
| 3481 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3482 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3483 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3484 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 3485 | return ValidateCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, |
| 3486 | "vkCmdBlitImage"); |
| 3487 | } |
| 3488 | |
| 3489 | bool SyncValidator::PreCallValidateCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 3490 | const VkBlitImageInfo2KHR *pBlitImageInfo) const { |
| 3491 | return ValidateCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 3492 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 3493 | pBlitImageInfo->filter, "vkCmdBlitImage2KHR"); |
| 3494 | } |
| 3495 | |
| 3496 | template <typename RegionType> |
| 3497 | void SyncValidator::RecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3498 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3499 | const RegionType *pRegions, VkFilter filter, ResourceUsageTag tag) { |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3500 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3501 | assert(cb_access_context); |
| 3502 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3503 | assert(context); |
| 3504 | |
| 3505 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3506 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3507 | |
| 3508 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3509 | const auto &blit_region = pRegions[region]; |
| 3510 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3511 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3512 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3513 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3514 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3515 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3516 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].z - blit_region.srcOffsets[0].z))}; |
| 3517 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, blit_region.srcSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3518 | } |
| 3519 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3520 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3521 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3522 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3523 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3524 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3525 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].z - blit_region.dstOffsets[0].z))}; |
| 3526 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, blit_region.dstSubresource, offset, extent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3527 | } |
| 3528 | } |
| 3529 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3530 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 3531 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3532 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3533 | const VkImageBlit *pRegions, VkFilter filter) { |
| 3534 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3535 | assert(cb_access_context); |
| 3536 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
| 3537 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 3538 | pRegions, filter); |
| 3539 | RecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter, tag); |
| 3540 | } |
| 3541 | |
| 3542 | void SyncValidator::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 3543 | StateTracker::PreCallRecordCmdBlitImage2KHR(commandBuffer, pBlitImageInfo); |
| 3544 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3545 | assert(cb_access_context); |
| 3546 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE2KHR); |
| 3547 | RecordCmdBlitImage(commandBuffer, pBlitImageInfo->srcImage, pBlitImageInfo->srcImageLayout, pBlitImageInfo->dstImage, |
| 3548 | pBlitImageInfo->dstImageLayout, pBlitImageInfo->regionCount, pBlitImageInfo->pRegions, |
| 3549 | pBlitImageInfo->filter, tag); |
| 3550 | } |
| 3551 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3552 | bool SyncValidator::ValidateIndirectBuffer(const AccessContext &context, VkCommandBuffer commandBuffer, |
| 3553 | const VkDeviceSize struct_size, const VkBuffer buffer, const VkDeviceSize offset, |
| 3554 | const uint32_t drawCount, const uint32_t stride, const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3555 | bool skip = false; |
| 3556 | if (drawCount == 0) return skip; |
| 3557 | |
| 3558 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 3559 | VkDeviceSize size = struct_size; |
| 3560 | if (drawCount == 1 || stride == size) { |
| 3561 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3562 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3563 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3564 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3565 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3566 | "%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] | 3567 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3568 | string_UsageTag(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3569 | } |
| 3570 | } else { |
| 3571 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3572 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3573 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3574 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3575 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3576 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
| 3577 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
| 3578 | string_UsageTag(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3579 | break; |
| 3580 | } |
| 3581 | } |
| 3582 | } |
| 3583 | return skip; |
| 3584 | } |
| 3585 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3586 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag &tag, const VkDeviceSize struct_size, |
| 3587 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 3588 | uint32_t stride) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3589 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 3590 | VkDeviceSize size = struct_size; |
| 3591 | if (drawCount == 1 || stride == size) { |
| 3592 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3593 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3594 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range, tag); |
| 3595 | } else { |
| 3596 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3597 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3598 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range, tag); |
| 3599 | } |
| 3600 | } |
| 3601 | } |
| 3602 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3603 | bool SyncValidator::ValidateCountBuffer(const AccessContext &context, VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3604 | VkDeviceSize offset, const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3605 | bool skip = false; |
| 3606 | |
| 3607 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3608 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3609 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3610 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3611 | skip |= LogError(count_buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3612 | "%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] | 3613 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3614 | string_UsageTag(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3615 | } |
| 3616 | return skip; |
| 3617 | } |
| 3618 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3619 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag &tag, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3620 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 3621 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3622 | context.UpdateAccessState(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range, tag); |
| 3623 | } |
| 3624 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3625 | 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] | 3626 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3627 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3628 | assert(cb_access_context); |
| 3629 | if (!cb_access_context) return skip; |
| 3630 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3631 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3632 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | 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] | 3636 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3637 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3638 | assert(cb_access_context); |
| 3639 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3640 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3641 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3642 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3643 | |
| 3644 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3645 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3646 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3647 | assert(cb_access_context); |
| 3648 | if (!cb_access_context) return skip; |
| 3649 | |
| 3650 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3651 | assert(context); |
| 3652 | if (!context) return skip; |
| 3653 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3654 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect"); |
| 3655 | skip |= ValidateIndirectBuffer(*context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, |
| 3656 | sizeof(VkDispatchIndirectCommand), "vkCmdDispatchIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3657 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3661 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3662 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3663 | assert(cb_access_context); |
| 3664 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 3665 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3666 | assert(context); |
| 3667 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3668 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 3669 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 3673 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 3674 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3675 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3676 | assert(cb_access_context); |
| 3677 | if (!cb_access_context) return skip; |
| 3678 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3679 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw"); |
| 3680 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, "vkCmdDraw"); |
| 3681 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDraw"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 3682 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 3686 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3687 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3688 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3689 | assert(cb_access_context); |
| 3690 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3691 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3692 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3693 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 3694 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 3698 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 3699 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3700 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3701 | assert(cb_access_context); |
| 3702 | if (!cb_access_context) return skip; |
| 3703 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3704 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed"); |
| 3705 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, "vkCmdDrawIndexed"); |
| 3706 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexed"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 3707 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 3711 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3712 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3713 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3714 | assert(cb_access_context); |
| 3715 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3716 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3717 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3718 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 3719 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3723 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3724 | bool skip = false; |
| 3725 | if (drawCount == 0) return skip; |
| 3726 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3727 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3728 | assert(cb_access_context); |
| 3729 | if (!cb_access_context) return skip; |
| 3730 | |
| 3731 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3732 | assert(context); |
| 3733 | if (!context) return skip; |
| 3734 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3735 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect"); |
| 3736 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndirect"); |
| 3737 | skip |= ValidateIndirectBuffer(*context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride, |
| 3738 | "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3739 | |
| 3740 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 3741 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 3742 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3743 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3744 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3748 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3749 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3750 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3751 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3752 | assert(cb_access_context); |
| 3753 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 3754 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3755 | assert(context); |
| 3756 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3757 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3758 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 3759 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3760 | |
| 3761 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 3762 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 3763 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3764 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3768 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3769 | bool skip = false; |
| 3770 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3771 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3772 | assert(cb_access_context); |
| 3773 | if (!cb_access_context) return skip; |
| 3774 | |
| 3775 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3776 | assert(context); |
| 3777 | if (!context) return skip; |
| 3778 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3779 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect"); |
| 3780 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexedIndirect"); |
| 3781 | skip |= ValidateIndirectBuffer(*context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride, |
| 3782 | "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3783 | |
| 3784 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 3785 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 3786 | // 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] | 3787 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3788 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3792 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3793 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3794 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3795 | assert(cb_access_context); |
| 3796 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 3797 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3798 | assert(context); |
| 3799 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3800 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3801 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 3802 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3803 | |
| 3804 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 3805 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 3806 | // 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] | 3807 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3811 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3812 | uint32_t stride, const char *function) const { |
| 3813 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3814 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3815 | assert(cb_access_context); |
| 3816 | if (!cb_access_context) return skip; |
| 3817 | |
| 3818 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3819 | assert(context); |
| 3820 | if (!context) return skip; |
| 3821 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3822 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 3823 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
| 3824 | skip |= ValidateIndirectBuffer(*context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, maxDrawCount, stride, |
| 3825 | function); |
| 3826 | skip |= ValidateCountBuffer(*context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3827 | |
| 3828 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 3829 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 3830 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3831 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3832 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3836 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3837 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3838 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3839 | "vkCmdDrawIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3843 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3844 | uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3845 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 3846 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3847 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3848 | assert(cb_access_context); |
| 3849 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECTCOUNT); |
| 3850 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3851 | assert(context); |
| 3852 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3853 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3854 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 3855 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 3856 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3857 | |
| 3858 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 3859 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 3860 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3861 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3862 | } |
| 3863 | |
| 3864 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3865 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3866 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3867 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3868 | "vkCmdDrawIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3872 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3873 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3874 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 3875 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3876 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3880 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3881 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3882 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3883 | "vkCmdDrawIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3884 | } |
| 3885 | |
| 3886 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3887 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3888 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3889 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 3890 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3891 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 3892 | } |
| 3893 | |
| 3894 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3895 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3896 | uint32_t stride, const char *function) const { |
| 3897 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3898 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3899 | assert(cb_access_context); |
| 3900 | if (!cb_access_context) return skip; |
| 3901 | |
| 3902 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3903 | assert(context); |
| 3904 | if (!context) return skip; |
| 3905 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3906 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 3907 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
| 3908 | skip |= ValidateIndirectBuffer(*context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, maxDrawCount, |
| 3909 | stride, function); |
| 3910 | skip |= ValidateCountBuffer(*context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3911 | |
| 3912 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 3913 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 3914 | // 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] | 3915 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3916 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3920 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3921 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3922 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3923 | "vkCmdDrawIndexedIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3927 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3928 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3929 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 3930 | maxDrawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3931 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3932 | assert(cb_access_context); |
| 3933 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 3934 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3935 | assert(context); |
| 3936 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3937 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3938 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 3939 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 3940 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3941 | |
| 3942 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 3943 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3944 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 3945 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3949 | VkDeviceSize offset, VkBuffer countBuffer, |
| 3950 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3951 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3952 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3953 | "vkCmdDrawIndexedIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3957 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3958 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3959 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 3960 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3961 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 3962 | } |
| 3963 | |
| 3964 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3965 | VkDeviceSize offset, VkBuffer countBuffer, |
| 3966 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3967 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3968 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3969 | "vkCmdDrawIndexedIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3973 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3974 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3975 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 3976 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3977 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 3978 | } |
| 3979 | |
| 3980 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 3981 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 3982 | const VkImageSubresourceRange *pRanges) const { |
| 3983 | bool skip = false; |
| 3984 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3985 | assert(cb_access_context); |
| 3986 | if (!cb_access_context) return skip; |
| 3987 | |
| 3988 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3989 | assert(context); |
| 3990 | if (!context) return skip; |
| 3991 | |
| 3992 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 3993 | |
| 3994 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 3995 | const auto &range = pRanges[index]; |
| 3996 | if (image_state) { |
| 3997 | auto hazard = |
| 3998 | context->DetectHazard(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent); |
| 3999 | if (hazard.hazard) { |
| 4000 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4001 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4002 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 4003 | string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4004 | } |
| 4005 | } |
| 4006 | } |
| 4007 | return skip; |
| 4008 | } |
| 4009 | |
| 4010 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4011 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 4012 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4013 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4014 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4015 | assert(cb_access_context); |
| 4016 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 4017 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4018 | assert(context); |
| 4019 | |
| 4020 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4021 | |
| 4022 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4023 | const auto &range = pRanges[index]; |
| 4024 | if (image_state) { |
| 4025 | context->UpdateAccessState(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent, |
| 4026 | tag); |
| 4027 | } |
| 4028 | } |
| 4029 | } |
| 4030 | |
| 4031 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 4032 | VkImageLayout imageLayout, |
| 4033 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4034 | const VkImageSubresourceRange *pRanges) const { |
| 4035 | bool skip = false; |
| 4036 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4037 | assert(cb_access_context); |
| 4038 | if (!cb_access_context) return skip; |
| 4039 | |
| 4040 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4041 | assert(context); |
| 4042 | if (!context) return skip; |
| 4043 | |
| 4044 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4045 | |
| 4046 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4047 | const auto &range = pRanges[index]; |
| 4048 | if (image_state) { |
| 4049 | auto hazard = |
| 4050 | context->DetectHazard(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent); |
| 4051 | if (hazard.hazard) { |
| 4052 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4053 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4054 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 4055 | string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4056 | } |
| 4057 | } |
| 4058 | } |
| 4059 | return skip; |
| 4060 | } |
| 4061 | |
| 4062 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4063 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 4064 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4065 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4066 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4067 | assert(cb_access_context); |
| 4068 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 4069 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4070 | assert(context); |
| 4071 | |
| 4072 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 4073 | |
| 4074 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 4075 | const auto &range = pRanges[index]; |
| 4076 | if (image_state) { |
| 4077 | context->UpdateAccessState(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent, |
| 4078 | tag); |
| 4079 | } |
| 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4084 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 4085 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 4086 | VkQueryResultFlags flags) const { |
| 4087 | bool skip = false; |
| 4088 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4089 | assert(cb_access_context); |
| 4090 | if (!cb_access_context) return skip; |
| 4091 | |
| 4092 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4093 | assert(context); |
| 4094 | if (!context) return skip; |
| 4095 | |
| 4096 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4097 | |
| 4098 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4099 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4100 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 4101 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4102 | skip |= |
| 4103 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4104 | "vkCmdCopyQueryPoolResults: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
| 4105 | report_data->FormatHandle(dstBuffer).c_str(), string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4106 | } |
| 4107 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4108 | |
| 4109 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4110 | return skip; |
| 4111 | } |
| 4112 | |
| 4113 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 4114 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4115 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4116 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 4117 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4118 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4119 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4120 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4121 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4122 | assert(context); |
| 4123 | |
| 4124 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4125 | |
| 4126 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4127 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4128 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range, tag); |
| 4129 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4130 | |
| 4131 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4135 | VkDeviceSize size, uint32_t data) const { |
| 4136 | bool skip = false; |
| 4137 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4138 | assert(cb_access_context); |
| 4139 | if (!cb_access_context) return skip; |
| 4140 | |
| 4141 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4142 | assert(context); |
| 4143 | if (!context) return skip; |
| 4144 | |
| 4145 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4146 | |
| 4147 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4148 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4149 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 4150 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4151 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4152 | "vkCmdFillBuffer: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 4153 | report_data->FormatHandle(dstBuffer).c_str(), string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4154 | } |
| 4155 | } |
| 4156 | return skip; |
| 4157 | } |
| 4158 | |
| 4159 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4160 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4161 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4162 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4163 | assert(cb_access_context); |
| 4164 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 4165 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4166 | assert(context); |
| 4167 | |
| 4168 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4169 | |
| 4170 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4171 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4172 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range, tag); |
| 4173 | } |
| 4174 | } |
| 4175 | |
| 4176 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4177 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4178 | const VkImageResolve *pRegions) const { |
| 4179 | bool skip = false; |
| 4180 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4181 | assert(cb_access_context); |
| 4182 | if (!cb_access_context) return skip; |
| 4183 | |
| 4184 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4185 | assert(context); |
| 4186 | if (!context) return skip; |
| 4187 | |
| 4188 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4189 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4190 | |
| 4191 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4192 | const auto &resolve_region = pRegions[region]; |
| 4193 | if (src_image) { |
| 4194 | auto hazard = context->DetectHazard(*src_image, SYNC_TRANSFER_TRANSFER_READ, resolve_region.srcSubresource, |
| 4195 | resolve_region.srcOffset, resolve_region.extent); |
| 4196 | if (hazard.hazard) { |
| 4197 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4198 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4199 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 4200 | string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4201 | } |
| 4202 | } |
| 4203 | |
| 4204 | if (dst_image) { |
| 4205 | auto hazard = context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, resolve_region.dstSubresource, |
| 4206 | resolve_region.dstOffset, resolve_region.extent); |
| 4207 | if (hazard.hazard) { |
| 4208 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4209 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4210 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 4211 | string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4212 | } |
| 4213 | if (skip) break; |
| 4214 | } |
| 4215 | } |
| 4216 | |
| 4217 | return skip; |
| 4218 | } |
| 4219 | |
| 4220 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4221 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4222 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4223 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 4224 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4225 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4226 | assert(cb_access_context); |
| 4227 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 4228 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4229 | assert(context); |
| 4230 | |
| 4231 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 4232 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 4233 | |
| 4234 | for (uint32_t region = 0; region < regionCount; region++) { |
| 4235 | const auto &resolve_region = pRegions[region]; |
| 4236 | if (src_image) { |
| 4237 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, resolve_region.srcSubresource, |
| 4238 | resolve_region.srcOffset, resolve_region.extent, tag); |
| 4239 | } |
| 4240 | if (dst_image) { |
| 4241 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, resolve_region.dstSubresource, |
| 4242 | resolve_region.dstOffset, resolve_region.extent, tag); |
| 4243 | } |
| 4244 | } |
| 4245 | } |
| 4246 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4247 | bool SyncValidator::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4248 | const VkResolveImageInfo2KHR *pResolveImageInfo) const { |
| 4249 | bool skip = false; |
| 4250 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4251 | assert(cb_access_context); |
| 4252 | if (!cb_access_context) return skip; |
| 4253 | |
| 4254 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4255 | assert(context); |
| 4256 | if (!context) return skip; |
| 4257 | |
| 4258 | const auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4259 | const auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4260 | |
| 4261 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4262 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4263 | if (src_image) { |
| 4264 | auto hazard = context->DetectHazard(*src_image, SYNC_TRANSFER_TRANSFER_READ, resolve_region.srcSubresource, |
| 4265 | resolve_region.srcOffset, resolve_region.extent); |
| 4266 | if (hazard.hazard) { |
| 4267 | skip |= LogError(pResolveImageInfo->srcImage, string_SyncHazardVUID(hazard.hazard), |
| 4268 | "vkCmdResolveImage2KHR: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
| 4269 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->srcImage).c_str(), |
| 4270 | region, string_UsageTag(hazard).c_str()); |
| 4271 | } |
| 4272 | } |
| 4273 | |
| 4274 | if (dst_image) { |
| 4275 | auto hazard = context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, resolve_region.dstSubresource, |
| 4276 | resolve_region.dstOffset, resolve_region.extent); |
| 4277 | if (hazard.hazard) { |
| 4278 | skip |= LogError(pResolveImageInfo->dstImage, string_SyncHazardVUID(hazard.hazard), |
| 4279 | "vkCmdResolveImage2KHR: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
| 4280 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(pResolveImageInfo->dstImage).c_str(), |
| 4281 | region, string_UsageTag(hazard).c_str()); |
| 4282 | } |
| 4283 | if (skip) break; |
| 4284 | } |
| 4285 | } |
| 4286 | |
| 4287 | return skip; |
| 4288 | } |
| 4289 | |
| 4290 | void SyncValidator::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4291 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 4292 | StateTracker::PreCallRecordCmdResolveImage2KHR(commandBuffer, pResolveImageInfo); |
| 4293 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4294 | assert(cb_access_context); |
| 4295 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE2KHR); |
| 4296 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4297 | assert(context); |
| 4298 | |
| 4299 | auto *src_image = Get<IMAGE_STATE>(pResolveImageInfo->srcImage); |
| 4300 | auto *dst_image = Get<IMAGE_STATE>(pResolveImageInfo->dstImage); |
| 4301 | |
| 4302 | for (uint32_t region = 0; region < pResolveImageInfo->regionCount; region++) { |
| 4303 | const auto &resolve_region = pResolveImageInfo->pRegions[region]; |
| 4304 | if (src_image) { |
| 4305 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, resolve_region.srcSubresource, |
| 4306 | resolve_region.srcOffset, resolve_region.extent, tag); |
| 4307 | } |
| 4308 | if (dst_image) { |
| 4309 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, resolve_region.dstSubresource, |
| 4310 | resolve_region.dstOffset, resolve_region.extent, tag); |
| 4311 | } |
| 4312 | } |
| 4313 | } |
| 4314 | |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4315 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4316 | VkDeviceSize dataSize, const void *pData) const { |
| 4317 | bool skip = false; |
| 4318 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4319 | assert(cb_access_context); |
| 4320 | if (!cb_access_context) return skip; |
| 4321 | |
| 4322 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4323 | assert(context); |
| 4324 | if (!context) return skip; |
| 4325 | |
| 4326 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4327 | |
| 4328 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4329 | // VK_WHOLE_SIZE not allowed |
| 4330 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4331 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 4332 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 4333 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4334 | "vkCmdUpdateBuffer: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 4335 | report_data->FormatHandle(dstBuffer).c_str(), string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4336 | } |
| 4337 | } |
| 4338 | return skip; |
| 4339 | } |
| 4340 | |
| 4341 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4342 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4343 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4344 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4345 | assert(cb_access_context); |
| 4346 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 4347 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4348 | assert(context); |
| 4349 | |
| 4350 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4351 | |
| 4352 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4353 | // VK_WHOLE_SIZE not allowed |
| 4354 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 4355 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range, tag); |
| 4356 | } |
| 4357 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4358 | |
| 4359 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4360 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 4361 | bool skip = false; |
| 4362 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4363 | assert(cb_access_context); |
| 4364 | if (!cb_access_context) return skip; |
| 4365 | |
| 4366 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4367 | assert(context); |
| 4368 | if (!context) return skip; |
| 4369 | |
| 4370 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4371 | |
| 4372 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4373 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4374 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 4375 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 4376 | skip |= |
| 4377 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 4378 | "vkCmdWriteBufferMarkerAMD: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
| 4379 | report_data->FormatHandle(dstBuffer).c_str(), string_UsageTag(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | return skip; |
| 4383 | } |
| 4384 | |
| 4385 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4386 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 4387 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4388 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 4389 | assert(cb_access_context); |
| 4390 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 4391 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 4392 | assert(context); |
| 4393 | |
| 4394 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 4395 | |
| 4396 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame] | 4397 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 4398 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range, tag); |
| 4399 | } |
| 4400 | } |