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) { |
| 461 | assert(prev_dep.dependency); |
| 462 | const auto dep = *prev_dep.dependency; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 463 | prev_.emplace_back(const_cast<AccessContext *>(&contexts[dep.srcSubpass]), queue_flags, dep); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 464 | prev_by_subpass_[dep.srcSubpass] = &prev_.back(); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 465 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 466 | |
| 467 | async_.reserve(subpass_dep.async.size()); |
| 468 | for (const auto async_subpass : subpass_dep.async) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 469 | async_.emplace_back(const_cast<AccessContext *>(&contexts[async_subpass])); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 470 | } |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 471 | if (subpass_dep.barrier_from_external) { |
| 472 | src_external_ = TrackBack(external_context, queue_flags, *subpass_dep.barrier_from_external); |
| 473 | } else { |
| 474 | src_external_ = TrackBack(); |
| 475 | } |
| 476 | if (subpass_dep.barrier_to_external) { |
| 477 | dst_external_ = TrackBack(this, queue_flags, *subpass_dep.barrier_to_external); |
| 478 | } else { |
| 479 | dst_external_ = TrackBack(); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 480 | } |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 481 | } |
| 482 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 483 | template <typename Detector> |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 484 | HazardResult AccessContext::DetectPreviousHazard(AddressType type, const Detector &detector, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 485 | const ResourceAccessRange &range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 486 | ResourceAccessRangeMap descent_map; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 487 | ResolvePreviousAccess(type, range, &descent_map, nullptr); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 488 | |
| 489 | HazardResult hazard; |
| 490 | for (auto prev = descent_map.begin(); prev != descent_map.end() && !hazard.hazard; ++prev) { |
| 491 | hazard = detector.Detect(prev); |
| 492 | } |
| 493 | return hazard; |
| 494 | } |
| 495 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 496 | // A recursive range walker for hazard detection, first for the current context and the (DetectHazardRecur) to walk |
| 497 | // the DAG of the contexts (for example subpasses) |
| 498 | template <typename Detector> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 499 | HazardResult AccessContext::DetectHazard(AddressType type, const Detector &detector, const ResourceAccessRange &range, |
| 500 | DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 501 | HazardResult hazard; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 502 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 503 | if (static_cast<uint32_t>(options) & DetectOptions::kDetectAsync) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 504 | // Async checks don't require recursive lookups, as the async lists are exhaustive for the top-level context |
| 505 | // so we'll check these first |
| 506 | for (const auto &async_context : async_) { |
| 507 | hazard = async_context->DetectAsyncHazard(type, detector, range); |
| 508 | if (hazard.hazard) return hazard; |
| 509 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 510 | } |
| 511 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 512 | const bool detect_prev = (static_cast<uint32_t>(options) & DetectOptions::kDetectPrevious) != 0; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 513 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 514 | const auto &accesses = GetAccessStateMap(type); |
| 515 | const auto from = accesses.lower_bound(range); |
| 516 | const auto to = accesses.upper_bound(range); |
| 517 | ResourceAccessRange gap = {range.begin, range.begin}; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 518 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 519 | for (auto pos = from; pos != to; ++pos) { |
| 520 | // Cover any leading gap, or gap between entries |
| 521 | if (detect_prev) { |
| 522 | // TODO: After profiling we may want to change the descent logic such that we don't recur per gap... |
| 523 | // Cover any leading gap, or gap between entries |
| 524 | gap.end = pos->first.begin; // We know this begin is < range.end |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 525 | if (gap.non_empty()) { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 526 | // Recur on all gaps |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 527 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 528 | if (hazard.hazard) return hazard; |
| 529 | } |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 530 | // Set up for the next gap. If pos..end is >= range.end, loop will exit, and trailing gap will be empty |
| 531 | gap.begin = pos->first.end; |
| 532 | } |
| 533 | |
| 534 | hazard = detector.Detect(pos); |
| 535 | if (hazard.hazard) return hazard; |
| 536 | } |
| 537 | |
| 538 | if (detect_prev) { |
| 539 | // Detect in the trailing empty as needed |
| 540 | gap.end = range.end; |
| 541 | if (gap.non_empty()) { |
| 542 | hazard = DetectPreviousHazard(type, detector, gap); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 543 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | return hazard; |
| 547 | } |
| 548 | |
| 549 | // A non recursive range walker for the asynchronous contexts (those we have no barriers with) |
| 550 | template <typename Detector> |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 551 | HazardResult AccessContext::DetectAsyncHazard(AddressType type, const Detector &detector, const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 552 | auto &accesses = GetAccessStateMap(type); |
| 553 | const auto from = accesses.lower_bound(range); |
| 554 | const auto to = accesses.upper_bound(range); |
| 555 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 556 | HazardResult hazard; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 557 | for (auto pos = from; pos != to && !hazard.hazard; ++pos) { |
| 558 | hazard = detector.DetectAsync(pos); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 559 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 560 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 561 | return hazard; |
| 562 | } |
| 563 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 564 | // Returns the last resolved entry |
| 565 | static void ResolveMapToEntry(ResourceAccessRangeMap *dest, ResourceAccessRangeMap::iterator entry, |
| 566 | ResourceAccessRangeMap::const_iterator first, ResourceAccessRangeMap::const_iterator last, |
| 567 | const SyncBarrier *barrier) { |
| 568 | auto at = entry; |
| 569 | for (auto pos = first; pos != last; ++pos) { |
| 570 | // Every member of the input iterator range must fit within the remaining portion of entry |
| 571 | assert(at->first.includes(pos->first)); |
| 572 | assert(at != dest->end()); |
| 573 | // Trim up at to the same size as the entry to resolve |
| 574 | at = sparse_container::split(at, *dest, pos->first); |
| 575 | auto access = pos->second; |
| 576 | if (barrier) { |
| 577 | access.ApplyBarrier(*barrier); |
| 578 | } |
| 579 | at->second.Resolve(access); |
| 580 | ++at; // Go to the remaining unused section of entry |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | void AccessContext::ResolveAccessRange(AddressType type, const ResourceAccessRange &range, const SyncBarrier *barrier, |
| 585 | ResourceAccessRangeMap *resolve_map, const ResourceAccessState *infill_state, |
| 586 | bool recur_to_infill) const { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 587 | if (!range.non_empty()) return; |
| 588 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 589 | ResourceRangeMergeIterator current(*resolve_map, GetAccessStateMap(type), range.begin); |
| 590 | while (current->range.non_empty() && range.includes(current->range.begin)) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 591 | const auto current_range = current->range & range; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 592 | if (current->pos_B->valid) { |
| 593 | const auto &src_pos = current->pos_B->lower_bound; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 594 | auto access = src_pos->second; |
| 595 | if (barrier) { |
| 596 | access.ApplyBarrier(*barrier); |
| 597 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 598 | if (current->pos_A->valid) { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 599 | const auto trimmed = sparse_container::split(current->pos_A->lower_bound, *resolve_map, current_range); |
| 600 | trimmed->second.Resolve(access); |
| 601 | current.invalidate_A(trimmed); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 602 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 603 | 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] | 604 | 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] | 605 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 606 | } else { |
| 607 | // we have to descend to fill this gap |
| 608 | if (recur_to_infill) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 609 | if (current->pos_A->valid) { |
| 610 | // Dest is valid, so we need to accumulate along the DAG and then resolve... in an N-to-1 resolve operation |
| 611 | ResourceAccessRangeMap gap_map; |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 612 | ResolvePreviousAccess(type, current_range, &gap_map, infill_state); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 613 | ResolveMapToEntry(resolve_map, current->pos_A->lower_bound, gap_map.begin(), gap_map.end(), barrier); |
| 614 | } else { |
John Zulauf | 3bcab5e | 2020-06-19 14:42:32 -0600 | [diff] [blame] | 615 | // There isn't anything in dest in current)range, so we can accumulate directly into it. |
| 616 | ResolvePreviousAccess(type, current_range, resolve_map, infill_state); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 617 | if (barrier) { |
| 618 | // 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] | 619 | for (auto pos = resolve_map->lower_bound(current_range); pos != current->pos_A->lower_bound; ++pos) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 620 | pos->second.ApplyBarrier(*barrier); |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | // Given that there could be gaps we need to seek carefully to not repeatedly search the same gaps in the next |
| 625 | // iterator of the outer while. |
| 626 | |
| 627 | // Set the parallel iterator to the end of this range s.t. ++ will move us to the next range whether or |
| 628 | // not the end of the range is a gap. For the seek to work, first we need to warn the parallel iterator |
| 629 | // we stepped on the dest map |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 630 | const auto seek_to = current_range.end - 1; // The subtraction is safe as range can't be empty (loop condition) |
| 631 | current.invalidate_A(); // Changes current->range |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 632 | current.seek(seek_to); |
| 633 | } else if (!current->pos_A->valid && infill_state) { |
| 634 | // If we didn't find anything in the current range, and we aren't reccuring... we infill if required |
| 635 | auto inserted = resolve_map->insert(current->pos_A->lower_bound, std::make_pair(current->range, *infill_state)); |
| 636 | 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] | 637 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 638 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 639 | ++current; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 640 | } |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 641 | |
| 642 | // Infill if range goes passed both the current and resolve map prior contents |
| 643 | if (recur_to_infill && (current->range.end < range.end)) { |
| 644 | ResourceAccessRange trailing_fill_range = {current->range.end, range.end}; |
| 645 | ResourceAccessRangeMap gap_map; |
| 646 | const auto the_end = resolve_map->end(); |
| 647 | ResolvePreviousAccess(type, trailing_fill_range, &gap_map, infill_state); |
| 648 | for (auto &access : gap_map) { |
| 649 | access.second.ApplyBarrier(*barrier); |
| 650 | resolve_map->insert(the_end, access); |
| 651 | } |
| 652 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 653 | } |
| 654 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 655 | void AccessContext::ResolvePreviousAccess(AddressType type, const ResourceAccessRange &range, ResourceAccessRangeMap *descent_map, |
| 656 | const ResourceAccessState *infill_state) const { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 657 | if ((prev_.size() == 0) && (src_external_.context == nullptr)) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 658 | if (range.non_empty() && infill_state) { |
| 659 | descent_map->insert(std::make_pair(range, *infill_state)); |
| 660 | } |
| 661 | } else { |
| 662 | // Look for something to fill the gap further along. |
| 663 | for (const auto &prev_dep : prev_) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 664 | prev_dep.context->ResolveAccessRange(type, range, &prev_dep.barrier, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 665 | } |
| 666 | |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 667 | if (src_external_.context) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 668 | src_external_.context->ResolveAccessRange(type, range, &src_external_.barrier, descent_map, infill_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 669 | } |
| 670 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 671 | } |
| 672 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 673 | AccessContext::AddressType AccessContext::ImageAddressType(const IMAGE_STATE &image) { |
locke-lunarg | 3f6978b | 2020-04-16 16:51:35 -0600 | [diff] [blame] | 674 | return (image.fragment_encoder->IsLinearImage()) ? AddressType::kLinearAddress : AddressType::kIdealizedAddress; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | VkDeviceSize AccessContext::ResourceBaseAddress(const BINDABLE &bindable) { |
| 678 | return bindable.binding.offset + bindable.binding.mem_state->fake_base_address; |
| 679 | } |
| 680 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 681 | 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] | 682 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 683 | static SyncStageAccessIndex ColorLoadUsage(VkAttachmentLoadOp load_op) { |
| 684 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ |
| 685 | : SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE; |
| 686 | return stage_access; |
| 687 | } |
| 688 | static SyncStageAccessIndex DepthStencilLoadUsage(VkAttachmentLoadOp load_op) { |
| 689 | const auto stage_access = (load_op == VK_ATTACHMENT_LOAD_OP_LOAD) ? SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ |
| 690 | : SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE; |
| 691 | return stage_access; |
| 692 | } |
| 693 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 694 | // Caller must manage returned pointer |
| 695 | static AccessContext *CreateStoreResolveProxyContext(const AccessContext &context, const RENDER_PASS_STATE &rp_state, |
| 696 | uint32_t subpass, const VkRect2D &render_area, |
| 697 | std::vector<const IMAGE_VIEW_STATE *> attachment_views) { |
| 698 | auto *proxy = new AccessContext(context); |
| 699 | proxy->UpdateAttachmentResolveAccess(rp_state, render_area, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 700 | proxy->UpdateAttachmentStoreAccess(rp_state, render_area, attachment_views, subpass, kCurrentCommandTag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 701 | return proxy; |
| 702 | } |
| 703 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 704 | 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] | 705 | AddressType address_type, ResourceAccessRangeMap *descent_map, |
| 706 | const ResourceAccessState *infill_state) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 707 | if (!SimpleBinding(image_state)) return; |
| 708 | |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 709 | auto subresource_range = NormalizeSubresourceRange(image_state.createInfo, subresource_range_arg); |
locke-lunarg | ae26eac | 2020-04-16 15:29:05 -0600 | [diff] [blame] | 710 | 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] | 711 | image_state.createInfo.extent); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 712 | const auto base_address = ResourceBaseAddress(image_state); |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 713 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 714 | ResolvePreviousAccess(address_type, (*range_gen + base_address), descent_map, infill_state); |
John Zulauf | 62f1059 | 2020-04-03 12:20:02 -0600 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 718 | // 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] | 719 | 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] | 720 | const VkRect2D &render_area, uint32_t subpass, |
| 721 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 722 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 723 | bool skip = false; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 724 | // As validation methods are const and precede the record/update phase, for any tranistions from the immediately |
| 725 | // previous subpass, we have to validate them against a copy of the AccessContext, with resolve operations applied, as |
| 726 | // those affects have not been recorded yet. |
| 727 | // |
| 728 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 729 | // to apply and only copy then, if this proves a hot spot. |
| 730 | std::unique_ptr<AccessContext> proxy_for_prev; |
| 731 | TrackBack proxy_track_back; |
| 732 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 733 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 734 | for (const auto &transition : transitions) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 735 | const bool prev_needs_proxy = transition.prev_pass != VK_SUBPASS_EXTERNAL && (transition.prev_pass + 1 == subpass); |
| 736 | |
| 737 | const auto *track_back = GetTrackBackFromSubpass(transition.prev_pass); |
| 738 | if (prev_needs_proxy) { |
| 739 | if (!proxy_for_prev) { |
| 740 | proxy_for_prev.reset(CreateStoreResolveProxyContext(*track_back->context, rp_state, transition.prev_pass, |
| 741 | render_area, attachment_views)); |
| 742 | proxy_track_back = *track_back; |
| 743 | proxy_track_back.context = proxy_for_prev.get(); |
| 744 | } |
| 745 | track_back = &proxy_track_back; |
| 746 | } |
| 747 | auto hazard = DetectSubpassTransitionHazard(*track_back, attachment_views[transition.attachment]); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 748 | if (hazard.hazard) { |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 749 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 750 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
| 751 | " image layout transition (old_layout: %s, new_layout: %s). Access info %s.", |
| 752 | func_name, string_SyncHazard(hazard.hazard), subpass, transition.attachment, |
| 753 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
| 754 | string_UsageTag(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | return skip; |
| 758 | } |
| 759 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 760 | 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] | 761 | const VkRect2D &render_area, uint32_t subpass, |
| 762 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 763 | const char *func_name) const { |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 764 | bool skip = false; |
| 765 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 766 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 767 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 768 | const auto external_access_scope = src_external_.barrier.dst_access_scope; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 769 | |
| 770 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 771 | if (subpass == rp_state.attachment_first_subpass[i]) { |
| 772 | if (attachment_views[i] == nullptr) continue; |
| 773 | const IMAGE_VIEW_STATE &view = *attachment_views[i]; |
| 774 | const IMAGE_STATE *image = view.image_state.get(); |
| 775 | if (image == nullptr) continue; |
| 776 | const auto &ci = attachment_ci[i]; |
| 777 | const bool is_transition = rp_state.attachment_first_is_transition[i]; |
| 778 | |
| 779 | // Need check in the following way |
| 780 | // 1) if the usage bit isn't in the dest_access_scope, and there is layout traniition for initial use, report hazard |
| 781 | // vs. transition |
| 782 | // 2) if there isn't a layout transition, we need to look at the external context with a "detect hazard" operation |
| 783 | // for each aspect loaded. |
| 784 | |
| 785 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 786 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 787 | const bool is_color = !(has_depth || has_stencil); |
| 788 | |
| 789 | const SyncStageAccessIndex load_index = has_depth ? DepthStencilLoadUsage(ci.loadOp) : ColorLoadUsage(ci.loadOp); |
| 790 | const SyncStageAccessFlags load_mask = (has_depth || is_color) ? SyncStageAccess::Flags(load_index) : 0U; |
| 791 | const SyncStageAccessIndex stencil_load_index = has_stencil ? DepthStencilLoadUsage(ci.stencilLoadOp) : load_index; |
| 792 | const SyncStageAccessFlags stencil_mask = has_stencil ? SyncStageAccess::Flags(stencil_load_index) : 0U; |
| 793 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 794 | HazardResult hazard; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 795 | const char *aspect = nullptr; |
| 796 | if (is_transition) { |
| 797 | // For transition w |
| 798 | SyncHazard transition_hazard = SyncHazard::NONE; |
| 799 | bool checked_stencil = false; |
| 800 | if (load_mask) { |
| 801 | if ((load_mask & external_access_scope) != load_mask) { |
| 802 | transition_hazard = |
| 803 | SyncStageAccess::HasWrite(load_mask) ? SyncHazard::WRITE_AFTER_WRITE : SyncHazard::READ_AFTER_WRITE; |
| 804 | aspect = is_color ? "color" : "depth"; |
| 805 | } |
| 806 | if (!transition_hazard && stencil_mask) { |
| 807 | if ((stencil_mask & external_access_scope) != stencil_mask) { |
| 808 | transition_hazard = SyncStageAccess::HasWrite(stencil_mask) ? SyncHazard::WRITE_AFTER_WRITE |
| 809 | : SyncHazard::READ_AFTER_WRITE; |
| 810 | aspect = "stencil"; |
| 811 | checked_stencil = true; |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | if (transition_hazard) { |
| 816 | // Hazard vs. ILT |
| 817 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
| 818 | skip |= |
locke-lunarg | 54379cf | 2020-08-05 12:25:29 -0600 | [diff] [blame] | 819 | sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(transition_hazard), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 820 | "%s: Hazard %s vs. layout transition in subpass %" PRIu32 " for attachment %" PRIu32 |
| 821 | " aspect %s during load with loadOp %s.", |
| 822 | func_name, string_SyncHazard(transition_hazard), subpass, i, aspect, load_op_string); |
| 823 | } |
| 824 | } else { |
| 825 | auto hazard_range = view.normalized_subresource_range; |
| 826 | bool checked_stencil = false; |
| 827 | if (is_color) { |
| 828 | hazard = DetectHazard(*image, load_index, view.normalized_subresource_range, offset, extent); |
| 829 | aspect = "color"; |
| 830 | } else { |
| 831 | if (has_depth) { |
| 832 | hazard_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 833 | hazard = DetectHazard(*image, load_index, hazard_range, offset, extent); |
| 834 | aspect = "depth"; |
| 835 | } |
| 836 | if (!hazard.hazard && has_stencil) { |
| 837 | hazard_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 838 | hazard = DetectHazard(*image, stencil_load_index, hazard_range, offset, extent); |
| 839 | aspect = "stencil"; |
| 840 | checked_stencil = true; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | if (hazard.hazard) { |
| 845 | auto load_op_string = string_VkAttachmentLoadOp(checked_stencil ? ci.stencilLoadOp : ci.loadOp); |
| 846 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 847 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 848 | " aspect %s during load with loadOp %s. Access info %s.", |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 849 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, load_op_string, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 850 | string_UsageTag(hazard).c_str()); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | } |
| 854 | } |
| 855 | return skip; |
| 856 | } |
| 857 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 858 | // Store operation validation can ignore resolve (before it) and layout tranistions after it. The first is ignored |
| 859 | // because of the ordering guarantees w.r.t. sample access and that the resolve validation hasn't altered the state, because |
| 860 | // store is part of the same Next/End operation. |
| 861 | // The latter is handled in layout transistion validation directly |
| 862 | bool AccessContext::ValidateStoreOperation(const SyncValidator &sync_state, const RENDER_PASS_STATE &rp_state, |
| 863 | const VkRect2D &render_area, uint32_t subpass, |
| 864 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, |
| 865 | const char *func_name) const { |
| 866 | bool skip = false; |
| 867 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 868 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 869 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 870 | |
| 871 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 872 | if (subpass == rp_state.attachment_last_subpass[i]) { |
| 873 | if (attachment_views[i] == nullptr) continue; |
| 874 | const IMAGE_VIEW_STATE &view = *attachment_views[i]; |
| 875 | const IMAGE_STATE *image = view.image_state.get(); |
| 876 | if (image == nullptr) continue; |
| 877 | const auto &ci = attachment_ci[i]; |
| 878 | |
| 879 | // The spec states that "don't care" is an operation with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 880 | // so we assume that an implementation is *free* to write in that case, meaning that for correctness |
| 881 | // sake, we treat DONT_CARE as writing. |
| 882 | const bool has_depth = FormatHasDepth(ci.format); |
| 883 | const bool has_stencil = FormatHasStencil(ci.format); |
| 884 | const bool is_color = !(has_depth || has_stencil); |
| 885 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 886 | if (!has_stencil && !store_op_stores) continue; |
| 887 | |
| 888 | HazardResult hazard; |
| 889 | const char *aspect = nullptr; |
| 890 | bool checked_stencil = false; |
| 891 | if (is_color) { |
| 892 | hazard = DetectHazard(*image, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 893 | view.normalized_subresource_range, kAttachmentRasterOrder, offset, extent); |
| 894 | aspect = "color"; |
| 895 | } else { |
| 896 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 897 | auto hazard_range = view.normalized_subresource_range; |
| 898 | if (has_depth && store_op_stores) { |
| 899 | hazard_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 900 | hazard = DetectHazard(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, hazard_range, |
| 901 | kAttachmentRasterOrder, offset, extent); |
| 902 | aspect = "depth"; |
| 903 | } |
| 904 | if (!hazard.hazard && has_stencil && stencil_op_stores) { |
| 905 | hazard_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 906 | hazard = DetectHazard(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, hazard_range, |
| 907 | kAttachmentRasterOrder, offset, extent); |
| 908 | aspect = "stencil"; |
| 909 | checked_stencil = true; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | if (hazard.hazard) { |
| 914 | const char *const op_type_string = checked_stencil ? "stencilStoreOp" : "storeOp"; |
| 915 | 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] | 916 | skip |= sync_state.LogError(rp_state.renderPass, string_SyncHazardVUID(hazard.hazard), |
| 917 | "%s: Hazard %s in subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 918 | " %s aspect during store with %s %s. Access info %s", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 919 | func_name, string_SyncHazard(hazard.hazard), subpass, i, aspect, op_type_string, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 920 | store_op_string, string_UsageTag(hazard).c_str()); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | } |
| 924 | return skip; |
| 925 | } |
| 926 | |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 927 | bool AccessContext::ValidateResolveOperations(const SyncValidator &sync_state, const RENDER_PASS_STATE &rp_state, |
| 928 | const VkRect2D &render_area, |
| 929 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, const char *func_name, |
| 930 | uint32_t subpass) const { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 931 | ValidateResolveAction validate_action(rp_state.renderPass, subpass, *this, sync_state, func_name); |
| 932 | ResolveOperation(validate_action, rp_state, render_area, attachment_views, subpass); |
| 933 | return validate_action.GetSkip(); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 934 | } |
| 935 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 936 | class HazardDetector { |
| 937 | SyncStageAccessIndex usage_index_; |
| 938 | |
| 939 | public: |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 940 | 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] | 941 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 942 | return pos->second.DetectAsyncHazard(usage_index_); |
| 943 | } |
| 944 | HazardDetector(SyncStageAccessIndex usage) : usage_index_(usage) {} |
| 945 | }; |
| 946 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 947 | class HazardDetectorWithOrdering { |
| 948 | const SyncStageAccessIndex usage_index_; |
| 949 | const SyncOrderingBarrier &ordering_; |
| 950 | |
| 951 | public: |
| 952 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 953 | return pos->second.DetectHazard(usage_index_, ordering_); |
| 954 | } |
| 955 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 956 | return pos->second.DetectAsyncHazard(usage_index_); |
| 957 | } |
| 958 | HazardDetectorWithOrdering(SyncStageAccessIndex usage, const SyncOrderingBarrier &ordering) |
| 959 | : usage_index_(usage), ordering_(ordering) {} |
| 960 | }; |
| 961 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 962 | HazardResult AccessContext::DetectHazard(AddressType type, SyncStageAccessIndex usage_index, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 963 | const ResourceAccessRange &range) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 964 | HazardDetector detector(usage_index); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 965 | return DetectHazard(type, detector, range, DetectOptions::kDetectAll); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 966 | } |
| 967 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 968 | HazardResult AccessContext::DetectHazard(const BUFFER_STATE &buffer, SyncStageAccessIndex usage_index, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 969 | const ResourceAccessRange &range) const { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 970 | if (!SimpleBinding(buffer)) return HazardResult(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 971 | return DetectHazard(AddressType::kLinearAddress, usage_index, range + ResourceBaseAddress(buffer)); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 972 | } |
| 973 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 974 | template <typename Detector> |
| 975 | HazardResult AccessContext::DetectHazard(Detector &detector, const IMAGE_STATE &image, |
| 976 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 977 | const VkExtent3D &extent, DetectOptions options) const { |
| 978 | if (!SimpleBinding(image)) return HazardResult(); |
| 979 | subresource_adapter::ImageRangeGenerator range_gen(*image.fragment_encoder.get(), subresource_range, offset, extent); |
| 980 | const auto address_type = ImageAddressType(image); |
| 981 | const auto base_address = ResourceBaseAddress(image); |
| 982 | for (; range_gen->non_empty(); ++range_gen) { |
| 983 | HazardResult hazard = DetectHazard(address_type, detector, (*range_gen + base_address), options); |
| 984 | if (hazard.hazard) return hazard; |
| 985 | } |
| 986 | return HazardResult(); |
| 987 | } |
| 988 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 989 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 990 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 991 | const VkExtent3D &extent) const { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 992 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 993 | subresource.layerCount}; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 994 | return DetectHazard(image, current_usage, subresource_range, offset, extent); |
| 995 | } |
| 996 | |
| 997 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 998 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
| 999 | const VkExtent3D &extent) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1000 | HazardDetector detector(current_usage); |
| 1001 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
| 1002 | } |
| 1003 | |
| 1004 | HazardResult AccessContext::DetectHazard(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1005 | const VkImageSubresourceRange &subresource_range, const SyncOrderingBarrier &ordering, |
| 1006 | const VkOffset3D &offset, const VkExtent3D &extent) const { |
| 1007 | HazardDetectorWithOrdering detector(current_usage, ordering); |
| 1008 | return DetectHazard(detector, image, subresource_range, offset, extent, DetectOptions::kDetectAll); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1009 | } |
| 1010 | |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1011 | // Some common code for looking at attachments, if there's anything wrong, we return no hazard, core validation |
| 1012 | // should have reported the issue regarding an invalid attachment entry |
| 1013 | HazardResult AccessContext::DetectHazard(const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, |
| 1014 | const SyncOrderingBarrier &ordering, const VkOffset3D &offset, const VkExtent3D &extent, |
| 1015 | VkImageAspectFlags aspect_mask) const { |
| 1016 | if (view != nullptr) { |
| 1017 | const IMAGE_STATE *image = view->image_state.get(); |
| 1018 | if (image != nullptr) { |
| 1019 | auto *detect_range = &view->normalized_subresource_range; |
| 1020 | VkImageSubresourceRange masked_range; |
| 1021 | if (aspect_mask) { // If present and non-zero, restrict the normalized range to aspects present in aspect_mask |
| 1022 | masked_range = view->normalized_subresource_range; |
| 1023 | masked_range.aspectMask = aspect_mask & masked_range.aspectMask; |
| 1024 | detect_range = &masked_range; |
| 1025 | } |
| 1026 | |
| 1027 | // NOTE: The range encoding code is not robust to invalid ranges, so we protect it from our change |
| 1028 | if (detect_range->aspectMask) { |
| 1029 | return DetectHazard(*image, current_usage, *detect_range, ordering, offset, extent); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | return HazardResult(); |
| 1034 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1035 | class BarrierHazardDetector { |
| 1036 | public: |
| 1037 | BarrierHazardDetector(SyncStageAccessIndex usage_index, VkPipelineStageFlags src_exec_scope, |
| 1038 | SyncStageAccessFlags src_access_scope) |
| 1039 | : usage_index_(usage_index), src_exec_scope_(src_exec_scope), src_access_scope_(src_access_scope) {} |
| 1040 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1041 | HazardResult Detect(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1042 | return pos->second.DetectBarrierHazard(usage_index_, src_exec_scope_, src_access_scope_); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1043 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1044 | HazardResult DetectAsync(const ResourceAccessRangeMap::const_iterator &pos) const { |
| 1045 | // Async barrier hazard detection can use the same path as the usage index is not IsRead, but is IsWrite |
| 1046 | return pos->second.DetectAsyncHazard(usage_index_); |
| 1047 | } |
| 1048 | |
| 1049 | private: |
| 1050 | SyncStageAccessIndex usage_index_; |
| 1051 | VkPipelineStageFlags src_exec_scope_; |
| 1052 | SyncStageAccessFlags src_access_scope_; |
| 1053 | }; |
| 1054 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1055 | HazardResult AccessContext::DetectBarrierHazard(AddressType type, SyncStageAccessIndex current_usage, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1056 | VkPipelineStageFlags src_exec_scope, SyncStageAccessFlags src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1057 | const ResourceAccessRange &range, DetectOptions options) const { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1058 | BarrierHazardDetector detector(current_usage, src_exec_scope, src_access_scope); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1059 | return DetectHazard(type, detector, range, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1062 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags src_exec_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1063 | SyncStageAccessFlags src_access_scope, |
| 1064 | const VkImageSubresourceRange &subresource_range, |
| 1065 | DetectOptions options) const { |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 1066 | BarrierHazardDetector detector(SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION, src_exec_scope, src_access_scope); |
| 1067 | VkOffset3D zero_offset = {0, 0, 0}; |
| 1068 | return DetectHazard(detector, image, subresource_range, zero_offset, image.createInfo.extent, options); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1071 | HazardResult AccessContext::DetectImageBarrierHazard(const IMAGE_STATE &image, VkPipelineStageFlags src_exec_scope, |
| 1072 | SyncStageAccessFlags src_stage_accesses, |
| 1073 | const VkImageMemoryBarrier &barrier) const { |
| 1074 | auto subresource_range = NormalizeSubresourceRange(image.createInfo, barrier.subresourceRange); |
| 1075 | const auto src_access_scope = SyncStageAccess::AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 1076 | return DetectImageBarrierHazard(image, src_exec_scope, src_access_scope, subresource_range, kDetectAll); |
| 1077 | } |
| 1078 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1079 | template <typename Flags, typename Map> |
| 1080 | SyncStageAccessFlags AccessScopeImpl(Flags flag_mask, const Map &map) { |
| 1081 | SyncStageAccessFlags scope = 0; |
| 1082 | for (const auto &bit_scope : map) { |
| 1083 | if (flag_mask < bit_scope.first) break; |
| 1084 | |
| 1085 | if (flag_mask & bit_scope.first) { |
| 1086 | scope |= bit_scope.second; |
| 1087 | } |
| 1088 | } |
| 1089 | return scope; |
| 1090 | } |
| 1091 | |
| 1092 | SyncStageAccessFlags SyncStageAccess::AccessScopeByStage(VkPipelineStageFlags stages) { |
| 1093 | return AccessScopeImpl(stages, syncStageAccessMaskByStageBit); |
| 1094 | } |
| 1095 | |
| 1096 | SyncStageAccessFlags SyncStageAccess::AccessScopeByAccess(VkAccessFlags accesses) { |
| 1097 | return AccessScopeImpl(accesses, syncStageAccessMaskByAccessBit); |
| 1098 | } |
| 1099 | |
| 1100 | // Getting from stage mask and access mask to stage/acess masks is something we need to be good at... |
| 1101 | SyncStageAccessFlags SyncStageAccess::AccessScope(VkPipelineStageFlags stages, VkAccessFlags accesses) { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1102 | // The access scope is the intersection of all stage/access types possible for the enabled stages and the enables |
| 1103 | // accesses (after doing a couple factoring of common terms the union of stage/access intersections is the intersections |
| 1104 | // 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] | 1105 | return AccessScopeByStage(stages) & AccessScopeByAccess(accesses); |
| 1106 | } |
| 1107 | |
| 1108 | template <typename Action> |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1109 | void UpdateMemoryAccessState(ResourceAccessRangeMap *accesses, const ResourceAccessRange &range, const Action &action) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1110 | // TODO: Optimization for operations that do a pure overwrite (i.e. WRITE usages which rewrite the state, vs READ usages |
| 1111 | // that do incrementalupdates |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1112 | auto pos = accesses->lower_bound(range); |
| 1113 | if (pos == accesses->end() || !pos->first.intersects(range)) { |
| 1114 | // The range is empty, fill it with a default value. |
| 1115 | pos = action.Infill(accesses, pos, range); |
| 1116 | } else if (range.begin < pos->first.begin) { |
| 1117 | // Leading empty space, infill |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1118 | pos = action.Infill(accesses, pos, ResourceAccessRange(range.begin, pos->first.begin)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1119 | } else if (pos->first.begin < range.begin) { |
| 1120 | // Trim the beginning if needed |
| 1121 | pos = accesses->split(pos, range.begin, sparse_container::split_op_keep_both()); |
| 1122 | ++pos; |
| 1123 | } |
| 1124 | |
| 1125 | const auto the_end = accesses->end(); |
| 1126 | while ((pos != the_end) && pos->first.intersects(range)) { |
| 1127 | if (pos->first.end > range.end) { |
| 1128 | pos = accesses->split(pos, range.end, sparse_container::split_op_keep_both()); |
| 1129 | } |
| 1130 | |
| 1131 | pos = action(accesses, pos); |
| 1132 | if (pos == the_end) break; |
| 1133 | |
| 1134 | auto next = pos; |
| 1135 | ++next; |
| 1136 | if ((pos->first.end < range.end) && (next != the_end) && !next->first.is_subsequent_to(pos->first)) { |
| 1137 | // Need to infill if next is disjoint |
| 1138 | 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] | 1139 | ResourceAccessRange new_range(pos->first.end, limit); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1140 | next = action.Infill(accesses, next, new_range); |
| 1141 | } |
| 1142 | pos = next; |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | struct UpdateMemoryAccessStateFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1147 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1148 | Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1149 | // this is only called on gaps, and never returns a gap. |
| 1150 | ResourceAccessState default_state; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1151 | context.ResolvePreviousAccess(type, range, accesses, &default_state); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1152 | return accesses->lower_bound(range); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1153 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1154 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1155 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1156 | auto &access_state = pos->second; |
| 1157 | access_state.Update(usage, tag); |
| 1158 | return pos; |
| 1159 | } |
| 1160 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1161 | UpdateMemoryAccessStateFunctor(AccessContext::AddressType type_, const AccessContext &context_, SyncStageAccessIndex usage_, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1162 | const ResourceUsageTag &tag_) |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1163 | : type(type_), context(context_), usage(usage_), tag(tag_) {} |
| 1164 | const AccessContext::AddressType type; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1165 | const AccessContext &context; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1166 | const SyncStageAccessIndex usage; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1167 | const ResourceUsageTag &tag; |
| 1168 | }; |
| 1169 | |
| 1170 | struct ApplyMemoryAccessBarrierFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1171 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1172 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1173 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1174 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1175 | auto &access_state = pos->second; |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 1176 | access_state.ApplyMemoryAccessBarrier(src_exec_scope, src_access_scope, dst_exec_scope, dst_access_scope); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1177 | return pos; |
| 1178 | } |
| 1179 | |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 1180 | ApplyMemoryAccessBarrierFunctor(VkPipelineStageFlags src_exec_scope_, SyncStageAccessFlags src_access_scope_, |
| 1181 | VkPipelineStageFlags dst_exec_scope_, SyncStageAccessFlags dst_access_scope_) |
| 1182 | : src_exec_scope(src_exec_scope_), |
| 1183 | src_access_scope(src_access_scope_), |
| 1184 | dst_exec_scope(dst_exec_scope_), |
| 1185 | dst_access_scope(dst_access_scope_) {} |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1186 | |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 1187 | VkPipelineStageFlags src_exec_scope; |
| 1188 | SyncStageAccessFlags src_access_scope; |
| 1189 | VkPipelineStageFlags dst_exec_scope; |
| 1190 | SyncStageAccessFlags dst_access_scope; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1191 | }; |
| 1192 | |
| 1193 | struct ApplyGlobalBarrierFunctor { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1194 | using Iterator = ResourceAccessRangeMap::iterator; |
| 1195 | inline Iterator Infill(ResourceAccessRangeMap *accesses, Iterator pos, ResourceAccessRange range) const { return pos; } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1196 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 1197 | Iterator operator()(ResourceAccessRangeMap *accesses, Iterator pos) const { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1198 | auto &access_state = pos->second; |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 1199 | access_state.ApplyExecutionBarrier(src_exec_scope, dst_exec_scope); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1200 | |
| 1201 | for (const auto &functor : barrier_functor) { |
| 1202 | functor(accesses, pos); |
| 1203 | } |
| 1204 | return pos; |
| 1205 | } |
| 1206 | |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 1207 | ApplyGlobalBarrierFunctor(VkPipelineStageFlags src_exec_scope, VkPipelineStageFlags dst_exec_scope, |
| 1208 | SyncStageAccessFlags src_stage_accesses, SyncStageAccessFlags dst_stage_accesses, |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1209 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers) |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 1210 | : src_exec_scope(src_exec_scope), dst_exec_scope(dst_exec_scope) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1211 | // Don't want to create this per tracked item, but don't want to loop through all tracked items per barrier... |
| 1212 | barrier_functor.reserve(memoryBarrierCount); |
| 1213 | for (uint32_t barrier_index = 0; barrier_index < memoryBarrierCount; barrier_index++) { |
| 1214 | const auto &barrier = pMemoryBarriers[barrier_index]; |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 1215 | barrier_functor.emplace_back(src_exec_scope, SyncStageAccess::AccessScope(src_stage_accesses, barrier.srcAccessMask), |
| 1216 | dst_exec_scope, SyncStageAccess::AccessScope(dst_stage_accesses, barrier.dstAccessMask)); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1217 | } |
| 1218 | } |
| 1219 | |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 1220 | const VkPipelineStageFlags src_exec_scope; |
| 1221 | const VkPipelineStageFlags dst_exec_scope; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 1222 | std::vector<ApplyMemoryAccessBarrierFunctor> barrier_functor; |
| 1223 | }; |
| 1224 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1225 | void AccessContext::UpdateAccessState(AddressType type, SyncStageAccessIndex current_usage, const ResourceAccessRange &range, |
| 1226 | const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1227 | UpdateMemoryAccessStateFunctor action(type, *this, current_usage, tag); |
| 1228 | UpdateMemoryAccessState(&GetAccessStateMap(type), range, action); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1229 | } |
| 1230 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1231 | void AccessContext::UpdateAccessState(const BUFFER_STATE &buffer, SyncStageAccessIndex current_usage, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1232 | const ResourceAccessRange &range, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1233 | if (!SimpleBinding(buffer)) return; |
| 1234 | const auto base_address = ResourceBaseAddress(buffer); |
| 1235 | UpdateAccessState(AddressType::kLinearAddress, current_usage, range + base_address, tag); |
| 1236 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1237 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1238 | void AccessContext::UpdateAccessState(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1239 | const VkImageSubresourceRange &subresource_range, const VkOffset3D &offset, |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1240 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1241 | if (!SimpleBinding(image)) return; |
locke-lunarg | ae26eac | 2020-04-16 15:29:05 -0600 | [diff] [blame] | 1242 | 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] | 1243 | const auto address_type = ImageAddressType(image); |
| 1244 | const auto base_address = ResourceBaseAddress(image); |
| 1245 | UpdateMemoryAccessStateFunctor action(address_type, *this, current_usage, tag); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1246 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1247 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), (*range_gen + base_address), action); |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 1248 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1249 | } |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1250 | void AccessContext::UpdateAccessState(const IMAGE_VIEW_STATE *view, SyncStageAccessIndex current_usage, const VkOffset3D &offset, |
| 1251 | const VkExtent3D &extent, VkImageAspectFlags aspect_mask, const ResourceUsageTag &tag) { |
| 1252 | if (view != nullptr) { |
| 1253 | const IMAGE_STATE *image = view->image_state.get(); |
| 1254 | if (image != nullptr) { |
| 1255 | auto *update_range = &view->normalized_subresource_range; |
| 1256 | VkImageSubresourceRange masked_range; |
| 1257 | if (aspect_mask) { // If present and non-zero, restrict the normalized range to aspects present in aspect_mask |
| 1258 | masked_range = view->normalized_subresource_range; |
| 1259 | masked_range.aspectMask = aspect_mask & masked_range.aspectMask; |
| 1260 | update_range = &masked_range; |
| 1261 | } |
| 1262 | UpdateAccessState(*image, current_usage, *update_range, offset, extent, tag); |
| 1263 | } |
| 1264 | } |
| 1265 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 1266 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1267 | void AccessContext::UpdateAccessState(const IMAGE_STATE &image, SyncStageAccessIndex current_usage, |
| 1268 | const VkImageSubresourceLayers &subresource, const VkOffset3D &offset, |
| 1269 | const VkExtent3D &extent, const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1270 | VkImageSubresourceRange subresource_range = {subresource.aspectMask, subresource.mipLevel, 1, subresource.baseArrayLayer, |
| 1271 | subresource.layerCount}; |
| 1272 | UpdateAccessState(image, current_usage, subresource_range, offset, extent, tag); |
| 1273 | } |
| 1274 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1275 | template <typename Action> |
| 1276 | void AccessContext::UpdateMemoryAccess(const BUFFER_STATE &buffer, const ResourceAccessRange &range, const Action action) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1277 | if (!SimpleBinding(buffer)) return; |
| 1278 | const auto base_address = ResourceBaseAddress(buffer); |
| 1279 | UpdateMemoryAccessState(&GetAccessStateMap(AddressType::kLinearAddress), (range + base_address), action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | template <typename Action> |
| 1283 | void AccessContext::UpdateMemoryAccess(const IMAGE_STATE &image, const VkImageSubresourceRange &subresource_range, |
| 1284 | const Action action) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1285 | if (!SimpleBinding(image)) return; |
| 1286 | const auto address_type = ImageAddressType(image); |
| 1287 | auto *accesses = &GetAccessStateMap(address_type); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1288 | |
locke-lunarg | ae26eac | 2020-04-16 15:29:05 -0600 | [diff] [blame] | 1289 | 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] | 1290 | image.createInfo.extent); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1291 | |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1292 | const auto base_address = ResourceBaseAddress(image); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1293 | for (; range_gen->non_empty(); ++range_gen) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1294 | UpdateMemoryAccessState(accesses, (*range_gen + base_address), action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1298 | void AccessContext::UpdateAttachmentResolveAccess(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 1299 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass, |
| 1300 | const ResourceUsageTag &tag) { |
| 1301 | UpdateStateResolveAction update(*this, tag); |
| 1302 | ResolveOperation(update, rp_state, render_area, attachment_views, subpass); |
| 1303 | } |
| 1304 | |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1305 | void AccessContext::UpdateAttachmentStoreAccess(const RENDER_PASS_STATE &rp_state, const VkRect2D &render_area, |
| 1306 | const std::vector<const IMAGE_VIEW_STATE *> &attachment_views, uint32_t subpass, |
| 1307 | const ResourceUsageTag &tag) { |
| 1308 | const auto *attachment_ci = rp_state.createInfo.pAttachments; |
| 1309 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1310 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 1311 | |
| 1312 | for (uint32_t i = 0; i < rp_state.createInfo.attachmentCount; i++) { |
| 1313 | if (rp_state.attachment_last_subpass[i] == subpass) { |
| 1314 | if (attachment_views[i] == nullptr) continue; // UNUSED |
| 1315 | const auto &view = *attachment_views[i]; |
| 1316 | const IMAGE_STATE *image = view.image_state.get(); |
| 1317 | if (image == nullptr) continue; |
| 1318 | |
| 1319 | const auto &ci = attachment_ci[i]; |
| 1320 | const bool has_depth = FormatHasDepth(ci.format); |
| 1321 | const bool has_stencil = FormatHasStencil(ci.format); |
| 1322 | const bool is_color = !(has_depth || has_stencil); |
| 1323 | const bool store_op_stores = ci.storeOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1324 | |
| 1325 | if (is_color && store_op_stores) { |
| 1326 | UpdateAccessState(*image, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, view.normalized_subresource_range, |
| 1327 | offset, extent, tag); |
| 1328 | } else { |
| 1329 | auto update_range = view.normalized_subresource_range; |
| 1330 | if (has_depth && store_op_stores) { |
| 1331 | update_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 1332 | UpdateAccessState(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, update_range, offset, extent, |
| 1333 | tag); |
| 1334 | } |
| 1335 | const bool stencil_op_stores = ci.stencilStoreOp != VK_ATTACHMENT_STORE_OP_NONE_QCOM; |
| 1336 | if (has_stencil && stencil_op_stores) { |
| 1337 | update_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 1338 | UpdateAccessState(*image, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, update_range, offset, extent, |
| 1339 | tag); |
| 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1346 | template <typename Action> |
| 1347 | void AccessContext::ApplyGlobalBarriers(const Action &barrier_action) { |
| 1348 | // 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] | 1349 | for (const auto address_type : kAddressTypes) { |
| 1350 | UpdateMemoryAccessState(&GetAccessStateMap(address_type), full_range, barrier_action); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | void AccessContext::ResolveChildContexts(const std::vector<AccessContext> &contexts) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1355 | for (uint32_t subpass_index = 0; subpass_index < contexts.size(); subpass_index++) { |
| 1356 | auto &context = contexts[subpass_index]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1357 | for (const auto address_type : kAddressTypes) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1358 | context.ResolveAccessRange(address_type, full_range, &context.GetDstExternalTrackBack().barrier, |
| 1359 | &GetAccessStateMap(address_type), nullptr, false); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | } |
| 1363 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1364 | void AccessContext::ApplyImageBarrier(const IMAGE_STATE &image, VkPipelineStageFlags src_exec_scope, |
| 1365 | SyncStageAccessFlags src_access_scope, VkPipelineStageFlags dst_exec_scope, |
| 1366 | SyncStageAccessFlags dst_access_scope, const VkImageSubresourceRange &subresource_range) { |
| 1367 | const ApplyMemoryAccessBarrierFunctor barrier_action(src_exec_scope, src_access_scope, dst_exec_scope, dst_access_scope); |
| 1368 | UpdateMemoryAccess(image, subresource_range, barrier_action); |
| 1369 | } |
| 1370 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1371 | // Note: ImageBarriers do not operate at offset/extent resolution, only at the whole subreources level |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1372 | void AccessContext::ApplyImageBarrier(const IMAGE_STATE &image, VkPipelineStageFlags src_exec_scope, |
| 1373 | SyncStageAccessFlags src_access_scope, VkPipelineStageFlags dst_exec_scope, |
| 1374 | SyncStageAccessFlags dst_access_scope, const VkImageSubresourceRange &subresource_range, |
| 1375 | bool layout_transition, const ResourceUsageTag &tag) { |
| 1376 | if (layout_transition) { |
| 1377 | UpdateAccessState(image, SYNC_IMAGE_LAYOUT_TRANSITION, subresource_range, VkOffset3D{0, 0, 0}, image.createInfo.extent, |
| 1378 | tag); |
| 1379 | ApplyImageBarrier(image, src_exec_scope, SYNC_IMAGE_LAYOUT_TRANSITION_BIT, dst_exec_scope, dst_access_scope, |
| 1380 | subresource_range); |
John Zulauf | c920122 | 2020-05-13 15:13:03 -0600 | [diff] [blame] | 1381 | } else { |
| 1382 | ApplyImageBarrier(image, src_exec_scope, src_access_scope, dst_exec_scope, dst_access_scope, subresource_range); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1383 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1384 | } |
| 1385 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1386 | // Note: ImageBarriers do not operate at offset/extent resolution, only at the whole subreources level |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1387 | void AccessContext::ApplyImageBarrier(const IMAGE_STATE &image, const SyncBarrier &barrier, |
| 1388 | const VkImageSubresourceRange &subresource_range, bool layout_transition, |
| 1389 | const ResourceUsageTag &tag) { |
| 1390 | ApplyImageBarrier(image, barrier.src_exec_scope, barrier.src_access_scope, barrier.dst_exec_scope, barrier.dst_access_scope, |
| 1391 | subresource_range, layout_transition, tag); |
| 1392 | } |
| 1393 | |
| 1394 | // Suitable only for *subpass* access contexts |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1395 | 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] | 1396 | if (!attach_view) return HazardResult(); |
| 1397 | const auto image_state = attach_view->image_state.get(); |
| 1398 | if (!image_state) return HazardResult(); |
| 1399 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1400 | // 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] | 1401 | assert(track_back.context); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1402 | |
| 1403 | // Do the detection against the specific prior context independent of other contexts. (Synchronous only) |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1404 | auto hazard = track_back.context->DetectImageBarrierHazard(*image_state, track_back.barrier.src_exec_scope, |
| 1405 | track_back.barrier.src_access_scope, |
| 1406 | attach_view->normalized_subresource_range, kDetectPrevious); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1407 | if (!hazard.hazard) { |
| 1408 | // The Async hazard check is against the current context's async set. |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1409 | hazard = DetectImageBarrierHazard(*image_state, track_back.barrier.src_exec_scope, track_back.barrier.src_access_scope, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1410 | attach_view->normalized_subresource_range, kDetectAsync); |
| 1411 | } |
| 1412 | return hazard; |
| 1413 | } |
| 1414 | |
| 1415 | // Class CommandBufferAccessContext: Keep track of resource access state information for a specific command buffer |
| 1416 | bool CommandBufferAccessContext::ValidateBeginRenderPass(const RENDER_PASS_STATE &rp_state, |
| 1417 | |
| 1418 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 1419 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo, |
| 1420 | const char *func_name) const { |
| 1421 | // Check if any of the layout transitions are hazardous.... but we don't have the renderpass context to work with, so we |
| 1422 | bool skip = false; |
| 1423 | uint32_t subpass = 0; |
| 1424 | const auto &transitions = rp_state.subpass_transitions[subpass]; |
| 1425 | if (transitions.size()) { |
| 1426 | const std::vector<AccessContext> empty_context_vector; |
| 1427 | // Create context we can use to validate against... |
| 1428 | AccessContext temp_context(subpass, queue_flags_, rp_state.subpass_dependencies, empty_context_vector, |
| 1429 | const_cast<AccessContext *>(&cb_access_context_)); |
| 1430 | |
| 1431 | assert(pRenderPassBegin); |
| 1432 | if (nullptr == pRenderPassBegin) return skip; |
| 1433 | |
| 1434 | const auto fb_state = sync_state_->Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
| 1435 | assert(fb_state); |
| 1436 | if (nullptr == fb_state) return skip; |
| 1437 | |
| 1438 | // Create a limited array of views (which we'll need to toss |
| 1439 | std::vector<const IMAGE_VIEW_STATE *> views; |
| 1440 | const auto count_attachment = GetFramebufferAttachments(*pRenderPassBegin, *fb_state); |
| 1441 | const auto attachment_count = count_attachment.first; |
| 1442 | const auto *attachments = count_attachment.second; |
| 1443 | views.resize(attachment_count, nullptr); |
| 1444 | for (const auto &transition : transitions) { |
| 1445 | assert(transition.attachment < attachment_count); |
| 1446 | views[transition.attachment] = sync_state_->Get<IMAGE_VIEW_STATE>(attachments[transition.attachment]); |
| 1447 | } |
| 1448 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1449 | skip |= temp_context.ValidateLayoutTransitions(*sync_state_, rp_state, pRenderPassBegin->renderArea, 0, views, func_name); |
| 1450 | 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] | 1451 | } |
| 1452 | return skip; |
| 1453 | } |
| 1454 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1455 | bool CommandBufferAccessContext::ValidateDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1456 | const char *func_name) const { |
| 1457 | bool skip = false; |
| 1458 | const PIPELINE_STATE *pPipe = nullptr; |
| 1459 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
| 1460 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pPipe, &per_sets); |
| 1461 | if (!pPipe || !per_sets) { |
| 1462 | return skip; |
| 1463 | } |
| 1464 | |
| 1465 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1466 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1467 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1468 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1469 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1470 | |
| 1471 | for (const auto &stage_state : pPipe->stage_state) { |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1472 | 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] | 1473 | pPipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) |
| 1474 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1475 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1476 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1477 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1478 | set_binding.first.second); |
| 1479 | const auto descriptor_type = binding_it.GetType(); |
| 1480 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1481 | auto array_idx = 0; |
| 1482 | |
| 1483 | if (binding_it.IsVariableDescriptorCount()) { |
| 1484 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1485 | } |
| 1486 | SyncStageAccessIndex sync_index = |
| 1487 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1488 | |
| 1489 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1490 | uint32_t index = i - index_range.start; |
| 1491 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1492 | switch (descriptor->GetClass()) { |
| 1493 | case DescriptorClass::ImageSampler: |
| 1494 | case DescriptorClass::Image: { |
| 1495 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1496 | VkImageLayout image_layout; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1497 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1498 | const auto image_sampler_descriptor = static_cast<const ImageSamplerDescriptor *>(descriptor); |
| 1499 | img_view_state = image_sampler_descriptor->GetImageViewState(); |
| 1500 | image_layout = image_sampler_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1501 | } else { |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1502 | const auto image_descriptor = static_cast<const ImageDescriptor *>(descriptor); |
| 1503 | img_view_state = image_descriptor->GetImageViewState(); |
| 1504 | image_layout = image_descriptor->GetImageLayout(); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1505 | } |
| 1506 | if (!img_view_state) continue; |
| 1507 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
| 1508 | VkExtent3D extent = {}; |
| 1509 | VkOffset3D offset = {}; |
| 1510 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1511 | extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1512 | offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1513 | } else { |
| 1514 | extent = img_state->createInfo.extent; |
| 1515 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 1516 | HazardResult hazard; |
| 1517 | const auto &subresource_range = img_view_state->normalized_subresource_range; |
| 1518 | if (descriptor_type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) { |
| 1519 | // Input attachments are subject to raster ordering rules |
| 1520 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, |
| 1521 | kAttachmentRasterOrder, offset, extent); |
| 1522 | } else { |
| 1523 | hazard = current_context_->DetectHazard(*img_state, sync_index, subresource_range, offset, extent); |
| 1524 | } |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1525 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1526 | skip |= sync_state_->LogError( |
| 1527 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1528 | "%s: Hazard %s for %s, in %s, and %s, %s, type: %s, imageLayout: %s, binding #%" PRIu32 |
| 1529 | ", index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 1530 | func_name, string_SyncHazard(hazard.hazard), |
| 1531 | sync_state_->report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1532 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
| 1533 | sync_state_->report_data->FormatHandle(pPipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1534 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1535 | string_VkDescriptorType(descriptor_type), string_VkImageLayout(image_layout), |
| 1536 | set_binding.first.second, index, string_UsageTag(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1537 | } |
| 1538 | break; |
| 1539 | } |
| 1540 | case DescriptorClass::TexelBuffer: { |
| 1541 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1542 | if (!buf_view_state) continue; |
| 1543 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 1544 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1545 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 1546 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1547 | skip |= sync_state_->LogError( |
| 1548 | buf_view_state->buffer_view, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1549 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1550 | func_name, string_SyncHazard(hazard.hazard), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1551 | sync_state_->report_data->FormatHandle(buf_view_state->buffer_view).c_str(), |
| 1552 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
| 1553 | sync_state_->report_data->FormatHandle(pPipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1554 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1555 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
| 1556 | string_UsageTag(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1557 | } |
| 1558 | break; |
| 1559 | } |
| 1560 | case DescriptorClass::GeneralBuffer: { |
| 1561 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1562 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1563 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 1564 | const ResourceAccessRange range = |
| 1565 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1566 | auto hazard = current_context_->DetectHazard(*buf_state, sync_index, range); |
John Zulauf | 3ac701a | 2020-09-07 14:34:41 -0600 | [diff] [blame] | 1567 | if (hazard.hazard && !sync_state_->SupressedBoundDescriptorWAW(hazard)) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1568 | skip |= sync_state_->LogError( |
| 1569 | buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1570 | "%s: Hazard %s for %s in %s, %s, and %s, type: %s, binding #%d index %d. Access info %s.", |
| 1571 | func_name, string_SyncHazard(hazard.hazard), |
| 1572 | sync_state_->report_data->FormatHandle(buf_state->buffer).c_str(), |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1573 | sync_state_->report_data->FormatHandle(cb_state_->commandBuffer).c_str(), |
| 1574 | sync_state_->report_data->FormatHandle(pPipe->pipeline).c_str(), |
locke-lunarg | 7cc0ead | 2020-07-17 14:29:16 -0600 | [diff] [blame] | 1575 | sync_state_->report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1576 | string_VkDescriptorType(descriptor_type), set_binding.first.second, index, |
| 1577 | string_UsageTag(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1578 | } |
| 1579 | break; |
| 1580 | } |
| 1581 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1582 | default: |
| 1583 | break; |
| 1584 | } |
| 1585 | } |
| 1586 | } |
| 1587 | } |
| 1588 | return skip; |
| 1589 | } |
| 1590 | |
| 1591 | void CommandBufferAccessContext::RecordDispatchDrawDescriptorSet(VkPipelineBindPoint pipelineBindPoint, |
| 1592 | const ResourceUsageTag &tag) { |
| 1593 | const PIPELINE_STATE *pPipe = nullptr; |
| 1594 | const std::vector<LAST_BOUND_STATE::PER_SET> *per_sets = nullptr; |
| 1595 | GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(*cb_state_.get(), pipelineBindPoint, &pPipe, &per_sets); |
| 1596 | if (!pPipe || !per_sets) { |
| 1597 | return; |
| 1598 | } |
| 1599 | |
| 1600 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 1601 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 1602 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 1603 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 1604 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 1605 | |
| 1606 | for (const auto &stage_state : pPipe->stage_state) { |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1607 | if (stage_state.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT && pPipe->graphicsPipelineCI.pRasterizationState && |
| 1608 | pPipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) |
| 1609 | continue; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1610 | for (const auto &set_binding : stage_state.descriptor_uses) { |
| 1611 | cvdescriptorset::DescriptorSet *descriptor_set = (*per_sets)[set_binding.first.first].bound_descriptor_set; |
| 1612 | cvdescriptorset::DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), |
| 1613 | set_binding.first.second); |
| 1614 | const auto descriptor_type = binding_it.GetType(); |
| 1615 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
| 1616 | auto array_idx = 0; |
| 1617 | |
| 1618 | if (binding_it.IsVariableDescriptorCount()) { |
| 1619 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
| 1620 | } |
| 1621 | SyncStageAccessIndex sync_index = |
| 1622 | GetSyncStageAccessIndexsByDescriptorSet(descriptor_type, set_binding.second, stage_state.stage_flag); |
| 1623 | |
| 1624 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
| 1625 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 1626 | switch (descriptor->GetClass()) { |
| 1627 | case DescriptorClass::ImageSampler: |
| 1628 | case DescriptorClass::Image: { |
| 1629 | const IMAGE_VIEW_STATE *img_view_state = nullptr; |
| 1630 | if (descriptor->GetClass() == DescriptorClass::ImageSampler) { |
| 1631 | img_view_state = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetImageViewState(); |
| 1632 | } else { |
| 1633 | img_view_state = static_cast<const ImageDescriptor *>(descriptor)->GetImageViewState(); |
| 1634 | } |
| 1635 | if (!img_view_state) continue; |
| 1636 | const IMAGE_STATE *img_state = img_view_state->image_state.get(); |
| 1637 | VkExtent3D extent = {}; |
| 1638 | VkOffset3D offset = {}; |
| 1639 | if (sync_index == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ) { |
| 1640 | extent = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.extent); |
| 1641 | offset = CastTo3D(cb_state_->activeRenderPassBeginInfo.renderArea.offset); |
| 1642 | } else { |
| 1643 | extent = img_state->createInfo.extent; |
| 1644 | } |
| 1645 | current_context_->UpdateAccessState(*img_state, sync_index, img_view_state->normalized_subresource_range, |
| 1646 | offset, extent, tag); |
| 1647 | break; |
| 1648 | } |
| 1649 | case DescriptorClass::TexelBuffer: { |
| 1650 | auto buf_view_state = static_cast<const TexelDescriptor *>(descriptor)->GetBufferViewState(); |
| 1651 | if (!buf_view_state) continue; |
| 1652 | const BUFFER_STATE *buf_state = buf_view_state->buffer_state.get(); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 1653 | const ResourceAccessRange range = MakeRange(*buf_view_state); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1654 | current_context_->UpdateAccessState(*buf_state, sync_index, range, tag); |
| 1655 | break; |
| 1656 | } |
| 1657 | case DescriptorClass::GeneralBuffer: { |
| 1658 | const auto *buffer_descriptor = static_cast<const BufferDescriptor *>(descriptor); |
| 1659 | auto buf_state = buffer_descriptor->GetBufferState(); |
| 1660 | if (!buf_state) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 1661 | const ResourceAccessRange range = |
| 1662 | MakeRange(*buf_state, buffer_descriptor->GetOffset(), buffer_descriptor->GetRange()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1663 | current_context_->UpdateAccessState(*buf_state, sync_index, range, tag); |
| 1664 | break; |
| 1665 | } |
| 1666 | // TODO: INLINE_UNIFORM_BLOCK_EXT, ACCELERATION_STRUCTURE_KHR |
| 1667 | default: |
| 1668 | break; |
| 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | bool CommandBufferAccessContext::ValidateDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const char *func_name) const { |
| 1676 | bool skip = false; |
| 1677 | const auto *pPipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1678 | if (!pPipe) { |
| 1679 | return skip; |
| 1680 | } |
| 1681 | |
| 1682 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 1683 | const auto &binding_buffers_size = binding_buffers.size(); |
| 1684 | const auto &binding_descriptions_size = pPipe->vertex_binding_descriptions_.size(); |
| 1685 | |
| 1686 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
| 1687 | const auto &binding_description = pPipe->vertex_binding_descriptions_[i]; |
| 1688 | if (binding_description.binding < binding_buffers_size) { |
| 1689 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
| 1690 | if (binding_buffer.buffer == VK_NULL_HANDLE) continue; |
| 1691 | |
| 1692 | auto *buf_state = sync_state_->Get<BUFFER_STATE>(binding_buffer.buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 1693 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 1694 | vertexCount, binding_description.stride); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1695 | auto hazard = current_context_->DetectHazard(*buf_state, SYNC_VERTEX_INPUT_VERTEX_ATTRIBUTE_READ, range); |
| 1696 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1697 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1698 | 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] | 1699 | 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] | 1700 | 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] | 1701 | } |
| 1702 | } |
| 1703 | } |
| 1704 | return skip; |
| 1705 | } |
| 1706 | |
| 1707 | void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t firstVertex, const ResourceUsageTag &tag) { |
| 1708 | const auto *pPipe = GetCurrentPipelineFromCommandBuffer(*cb_state_.get(), VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1709 | if (!pPipe) { |
| 1710 | return; |
| 1711 | } |
| 1712 | const auto &binding_buffers = cb_state_->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 1713 | const auto &binding_buffers_size = binding_buffers.size(); |
| 1714 | const auto &binding_descriptions_size = pPipe->vertex_binding_descriptions_.size(); |
| 1715 | |
| 1716 | for (size_t i = 0; i < binding_descriptions_size; ++i) { |
| 1717 | const auto &binding_description = pPipe->vertex_binding_descriptions_[i]; |
| 1718 | if (binding_description.binding < binding_buffers_size) { |
| 1719 | const auto &binding_buffer = binding_buffers[binding_description.binding]; |
| 1720 | if (binding_buffer.buffer == VK_NULL_HANDLE) continue; |
| 1721 | |
| 1722 | auto *buf_state = sync_state_->Get<BUFFER_STATE>(binding_buffer.buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 1723 | const ResourceAccessRange range = GetBufferRange(binding_buffer.offset, buf_state->createInfo.size, firstVertex, |
| 1724 | vertexCount, binding_description.stride); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1725 | current_context_->UpdateAccessState(*buf_state, SYNC_VERTEX_INPUT_VERTEX_ATTRIBUTE_READ, range, tag); |
| 1726 | } |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const char *func_name) const { |
| 1731 | bool skip = false; |
| 1732 | if (cb_state_->index_buffer_binding.buffer == VK_NULL_HANDLE) return skip; |
| 1733 | |
| 1734 | auto *index_buf_state = sync_state_->Get<BUFFER_STATE>(cb_state_->index_buffer_binding.buffer); |
| 1735 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 1736 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 1737 | firstIndex, indexCount, index_size); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1738 | auto hazard = current_context_->DetectHazard(*index_buf_state, SYNC_VERTEX_INPUT_INDEX_READ, range); |
| 1739 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1740 | skip |= sync_state_->LogError( |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1741 | 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] | 1742 | 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] | 1743 | 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] | 1744 | } |
| 1745 | |
| 1746 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 1747 | // We will detect more accurate range in the future. |
| 1748 | skip |= ValidateDrawVertex(UINT32_MAX, 0, func_name); |
| 1749 | return skip; |
| 1750 | } |
| 1751 | |
| 1752 | void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag &tag) { |
| 1753 | if (cb_state_->index_buffer_binding.buffer == VK_NULL_HANDLE) return; |
| 1754 | |
| 1755 | auto *index_buf_state = sync_state_->Get<BUFFER_STATE>(cb_state_->index_buffer_binding.buffer); |
| 1756 | const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 1757 | const ResourceAccessRange range = GetBufferRange(cb_state_->index_buffer_binding.offset, index_buf_state->createInfo.size, |
| 1758 | firstIndex, indexCount, index_size); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1759 | current_context_->UpdateAccessState(*index_buf_state, SYNC_VERTEX_INPUT_INDEX_READ, range, tag); |
| 1760 | |
| 1761 | // TODO: For now, we detect the whole vertex buffer. Index buffer could be changed until SubmitQueue. |
| 1762 | // We will detect more accurate range in the future. |
| 1763 | RecordDrawVertex(UINT32_MAX, 0, tag); |
| 1764 | } |
| 1765 | |
| 1766 | bool CommandBufferAccessContext::ValidateDrawSubpassAttachment(const char *func_name) const { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 1767 | bool skip = false; |
| 1768 | if (!current_renderpass_context_) return skip; |
| 1769 | skip |= current_renderpass_context_->ValidateDrawSubpassAttachment(*sync_state_, *cb_state_.get(), |
| 1770 | cb_state_->activeRenderPassBeginInfo.renderArea, func_name); |
| 1771 | return skip; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | void CommandBufferAccessContext::RecordDrawSubpassAttachment(const ResourceUsageTag &tag) { |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 1775 | if (current_renderpass_context_) |
| 1776 | current_renderpass_context_->RecordDrawSubpassAttachment(*cb_state_.get(), cb_state_->activeRenderPassBeginInfo.renderArea, |
| 1777 | tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1778 | } |
| 1779 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1780 | bool CommandBufferAccessContext::ValidateNextSubpass(const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1781 | bool skip = false; |
locke-lunarg | 7077d50 | 2020-06-18 21:37:26 -0600 | [diff] [blame] | 1782 | if (!current_renderpass_context_) return skip; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1783 | skip |= |
| 1784 | current_renderpass_context_->ValidateNextSubpass(*sync_state_, cb_state_->activeRenderPassBeginInfo.renderArea, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1785 | |
| 1786 | return skip; |
| 1787 | } |
| 1788 | |
| 1789 | bool CommandBufferAccessContext::ValidateEndRenderpass(const char *func_name) const { |
| 1790 | // TODO: Things to add here. |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1791 | // Validate Preserve attachments |
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 | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1794 | skip |= current_renderpass_context_->ValidateEndRenderPass(*sync_state_, cb_state_->activeRenderPassBeginInfo.renderArea, |
| 1795 | func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1796 | |
| 1797 | return skip; |
| 1798 | } |
| 1799 | |
| 1800 | void CommandBufferAccessContext::RecordBeginRenderPass(const ResourceUsageTag &tag) { |
| 1801 | assert(sync_state_); |
| 1802 | if (!cb_state_) return; |
| 1803 | |
| 1804 | // Create an access context the current renderpass. |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1805 | render_pass_contexts_.emplace_back(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1806 | current_renderpass_context_ = &render_pass_contexts_.back(); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1807 | 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] | 1808 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1809 | } |
| 1810 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1811 | void CommandBufferAccessContext::RecordNextSubpass(const RENDER_PASS_STATE &rp_state, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1812 | assert(current_renderpass_context_); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1813 | current_renderpass_context_->RecordNextSubpass(cb_state_->activeRenderPassBeginInfo.renderArea, tag); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1814 | current_context_ = ¤t_renderpass_context_->CurrentContext(); |
| 1815 | } |
| 1816 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1817 | void CommandBufferAccessContext::RecordEndRenderPass(const RENDER_PASS_STATE &render_pass, const ResourceUsageTag &tag) { |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1818 | assert(current_renderpass_context_); |
| 1819 | if (!current_renderpass_context_) return; |
| 1820 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1821 | current_renderpass_context_->RecordEndRenderPass(&cb_access_context_, cb_state_->activeRenderPassBeginInfo.renderArea, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1822 | current_context_ = &cb_access_context_; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 1823 | current_renderpass_context_ = nullptr; |
| 1824 | } |
| 1825 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1826 | bool RenderPassAccessContext::ValidateDrawSubpassAttachment(const SyncValidator &sync_state, const CMD_BUFFER_STATE &cmd, |
| 1827 | const VkRect2D &render_area, const char *func_name) const { |
| 1828 | bool skip = false; |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1829 | const auto *pPipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1830 | if (!pPipe || |
| 1831 | (pPipe->graphicsPipelineCI.pRasterizationState && pPipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1832 | return skip; |
| 1833 | } |
| 1834 | const auto &list = pPipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1835 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
| 1836 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1837 | VkOffset3D offset = CastTo3D(render_area.offset); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1838 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1839 | const auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 1840 | // Subpass's inputAttachment has been done in ValidateDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1841 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 1842 | for (const auto location : list) { |
| 1843 | if (location >= subpass.colorAttachmentCount || subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) |
| 1844 | continue; |
| 1845 | 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] | 1846 | HazardResult hazard = current_context.DetectHazard(img_view_state, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, |
| 1847 | kColorAttachmentRasterOrder, offset, extent); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1848 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1849 | 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] | 1850 | "%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] | 1851 | func_name, string_SyncHazard(hazard.hazard), |
| 1852 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1853 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 1854 | location, string_UsageTag(hazard).c_str()); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1855 | } |
| 1856 | } |
| 1857 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1858 | |
| 1859 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 1860 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
| 1861 | if (pPipe->graphicsPipelineCI.pDepthStencilState && subpass.pDepthStencilAttachment && |
| 1862 | subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1863 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pDepthStencilAttachment->attachment]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1864 | bool depth_write = false, stencil_write = false; |
| 1865 | |
| 1866 | // PHASE1 TODO: These validation should be in core_checks. |
| 1867 | if (!FormatIsStencilOnly(img_view_state->create_info.format) && |
| 1868 | pPipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 1869 | pPipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
| 1870 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 1871 | depth_write = true; |
| 1872 | } |
| 1873 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 1874 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 1875 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 1876 | // PHASE1 TODO: These validation should be in core_checks. |
| 1877 | if (!FormatIsDepthOnly(img_view_state->create_info.format) && |
| 1878 | pPipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
| 1879 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 1880 | stencil_write = true; |
| 1881 | } |
| 1882 | |
| 1883 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 1884 | if (depth_write) { |
| 1885 | HazardResult hazard = |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1886 | current_context.DetectHazard(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 1887 | kDepthStencilAttachmentRasterOrder, offset, extent, VK_IMAGE_ASPECT_DEPTH_BIT); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1888 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1889 | skip |= sync_state.LogError( |
| 1890 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1891 | "%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] | 1892 | func_name, string_SyncHazard(hazard.hazard), |
| 1893 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1894 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 1895 | string_UsageTag(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1896 | } |
| 1897 | } |
| 1898 | if (stencil_write) { |
| 1899 | HazardResult hazard = |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1900 | current_context.DetectHazard(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, |
| 1901 | kDepthStencilAttachmentRasterOrder, offset, extent, VK_IMAGE_ASPECT_STENCIL_BIT); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1902 | if (hazard.hazard) { |
locke-lunarg | 88dbb54 | 2020-06-23 22:05:42 -0600 | [diff] [blame] | 1903 | skip |= sync_state.LogError( |
| 1904 | img_view_state->image_view, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 1905 | "%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] | 1906 | func_name, string_SyncHazard(hazard.hazard), |
| 1907 | sync_state.report_data->FormatHandle(img_view_state->image_view).c_str(), |
| 1908 | sync_state.report_data->FormatHandle(cmd.commandBuffer).c_str(), cmd.activeSubpass, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 1909 | string_UsageTag(hazard).c_str()); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1910 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1911 | } |
| 1912 | } |
| 1913 | return skip; |
| 1914 | } |
| 1915 | |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1916 | void RenderPassAccessContext::RecordDrawSubpassAttachment(const CMD_BUFFER_STATE &cmd, const VkRect2D &render_area, |
| 1917 | const ResourceUsageTag &tag) { |
| 1918 | const auto *pPipe = GetCurrentPipelineFromCommandBuffer(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); |
locke-lunarg | e9f1cdf | 2020-06-12 12:28:57 -0600 | [diff] [blame] | 1919 | if (!pPipe || |
| 1920 | (pPipe->graphicsPipelineCI.pRasterizationState && pPipe->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable)) { |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1921 | return; |
| 1922 | } |
| 1923 | const auto &list = pPipe->fragmentShader_writable_output_location_list; |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1924 | const auto &subpass = rp_state_->createInfo.pSubpasses[current_subpass_]; |
| 1925 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 1926 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 1927 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1928 | auto ¤t_context = CurrentContext(); |
locke-lunarg | 44f9bb1 | 2020-06-10 14:43:57 -0600 | [diff] [blame] | 1929 | // Subpass's inputAttachment has been done in RecordDispatchDrawDescriptorSet |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 1930 | if (subpass.pColorAttachments && subpass.colorAttachmentCount && !list.empty()) { |
| 1931 | for (const auto location : list) { |
| 1932 | if (location >= subpass.colorAttachmentCount || subpass.pColorAttachments[location].attachment == VK_ATTACHMENT_UNUSED) |
| 1933 | continue; |
| 1934 | 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] | 1935 | current_context.UpdateAccessState(img_view_state, SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, offset, extent, |
| 1936 | 0, tag); |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1937 | } |
| 1938 | } |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1939 | |
| 1940 | // PHASE1 TODO: Add layout based read/vs. write selection. |
| 1941 | // PHASE1 TODO: Read operations for both depth and stencil are possible in the future. |
| 1942 | if (pPipe->graphicsPipelineCI.pDepthStencilState && subpass.pDepthStencilAttachment && |
| 1943 | subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1944 | const IMAGE_VIEW_STATE *img_view_state = attachment_views_[subpass.pDepthStencilAttachment->attachment]; |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1945 | bool depth_write = false, stencil_write = false; |
| 1946 | |
| 1947 | // PHASE1 TODO: These validation should be in core_checks. |
| 1948 | if (!FormatIsStencilOnly(img_view_state->create_info.format) && |
| 1949 | pPipe->graphicsPipelineCI.pDepthStencilState->depthTestEnable && |
| 1950 | pPipe->graphicsPipelineCI.pDepthStencilState->depthWriteEnable && |
| 1951 | IsImageLayoutDepthWritable(subpass.pDepthStencilAttachment->layout)) { |
| 1952 | depth_write = true; |
| 1953 | } |
| 1954 | // PHASE1 TODO: It needs to check if stencil is writable. |
| 1955 | // If failOp, passOp, or depthFailOp are not KEEP, and writeMask isn't 0, it's writable. |
| 1956 | // If depth test is disable, it's considered depth test passes, and then depthFailOp doesn't run. |
| 1957 | // PHASE1 TODO: These validation should be in core_checks. |
| 1958 | if (!FormatIsDepthOnly(img_view_state->create_info.format) && |
| 1959 | pPipe->graphicsPipelineCI.pDepthStencilState->stencilTestEnable && |
| 1960 | IsImageLayoutStencilWritable(subpass.pDepthStencilAttachment->layout)) { |
| 1961 | stencil_write = true; |
| 1962 | } |
| 1963 | |
| 1964 | // PHASE1 TODO: Add EARLY stage detection based on ExecutionMode. |
| 1965 | if (depth_write) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1966 | current_context.UpdateAccessState(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, offset, |
| 1967 | extent, VK_IMAGE_ASPECT_DEPTH_BIT, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1968 | } |
| 1969 | if (stencil_write) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 1970 | current_context.UpdateAccessState(img_view_state, SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, offset, |
| 1971 | extent, VK_IMAGE_ASPECT_STENCIL_BIT, tag); |
locke-lunarg | 3704783 | 2020-06-12 13:44:45 -0600 | [diff] [blame] | 1972 | } |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 1973 | } |
| 1974 | } |
| 1975 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1976 | bool RenderPassAccessContext::ValidateNextSubpass(const SyncValidator &sync_state, const VkRect2D &render_area, |
| 1977 | const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1978 | // PHASE1 TODO: Add Validate Preserve attachments |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1979 | bool skip = false; |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 1980 | skip |= CurrentContext().ValidateResolveOperations(sync_state, *rp_state_, render_area, attachment_views_, func_name, |
| 1981 | current_subpass_); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1982 | skip |= CurrentContext().ValidateStoreOperation(sync_state, *rp_state_, render_area, current_subpass_, attachment_views_, |
| 1983 | func_name); |
| 1984 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 1985 | const auto next_subpass = current_subpass_ + 1; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 1986 | const auto &next_context = subpass_contexts_[next_subpass]; |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1987 | skip |= next_context.ValidateLayoutTransitions(sync_state, *rp_state_, render_area, next_subpass, attachment_views_, func_name); |
| 1988 | skip |= next_context.ValidateLoadOperation(sync_state, *rp_state_, render_area, next_subpass, attachment_views_, func_name); |
| 1989 | return skip; |
| 1990 | } |
| 1991 | bool RenderPassAccessContext::ValidateEndRenderPass(const SyncValidator &sync_state, const VkRect2D &render_area, |
| 1992 | const char *func_name) const { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1993 | // PHASE1 TODO: Validate Preserve |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1994 | bool skip = false; |
| 1995 | skip |= CurrentContext().ValidateResolveOperations(sync_state, *rp_state_, render_area, attachment_views_, func_name, |
| 1996 | current_subpass_); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 1997 | skip |= CurrentContext().ValidateStoreOperation(sync_state, *rp_state_, render_area, current_subpass_, attachment_views_, |
| 1998 | func_name); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 1999 | skip |= ValidateFinalSubpassLayoutTransitions(sync_state, render_area, func_name); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2000 | return skip; |
| 2001 | } |
| 2002 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2003 | AccessContext *RenderPassAccessContext::CreateStoreResolveProxy(const VkRect2D &render_area) const { |
| 2004 | return CreateStoreResolveProxyContext(CurrentContext(), *rp_state_, current_subpass_, render_area, attachment_views_); |
| 2005 | } |
| 2006 | |
| 2007 | bool RenderPassAccessContext::ValidateFinalSubpassLayoutTransitions(const SyncValidator &sync_state, const VkRect2D &render_area, |
| 2008 | const char *func_name) const { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2009 | bool skip = false; |
| 2010 | |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2011 | // As validation methods are const and precede the record/update phase, for any tranistions from the current (last) |
| 2012 | // subpass, we have to validate them against a copy of the current AccessContext, with resolve operations applied. |
| 2013 | // Note: we could be more efficient by tracking whether or not we actually *have* any changes (e.g. attachment resolve) |
| 2014 | // to apply and only copy then, if this proves a hot spot. |
| 2015 | std::unique_ptr<AccessContext> proxy_for_current; |
| 2016 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2017 | // Validate the "finalLayout" transitions to external |
| 2018 | // Get them from where there we're hidding in the extra entry. |
| 2019 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2020 | for (const auto &transition : final_transitions) { |
| 2021 | const auto &attach_view = attachment_views_[transition.attachment]; |
| 2022 | const auto &trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
| 2023 | 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] | 2024 | auto *context = trackback.context; |
| 2025 | |
| 2026 | if (transition.prev_pass == current_subpass_) { |
| 2027 | if (!proxy_for_current) { |
| 2028 | // We haven't recorded resolve ofor the current_subpass, so we need to copy current and update it *as if* |
| 2029 | proxy_for_current.reset(CreateStoreResolveProxy(render_area)); |
| 2030 | } |
| 2031 | context = proxy_for_current.get(); |
| 2032 | } |
| 2033 | |
| 2034 | auto hazard = context->DetectImageBarrierHazard( |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2035 | *attach_view->image_state, trackback.barrier.src_exec_scope, trackback.barrier.src_access_scope, |
| 2036 | attach_view->normalized_subresource_range, AccessContext::DetectOptions::kDetectPrevious); |
| 2037 | if (hazard.hazard) { |
| 2038 | skip |= sync_state.LogError(rp_state_->renderPass, string_SyncHazardVUID(hazard.hazard), |
| 2039 | "%s: Hazard %s with last use subpass %" PRIu32 " for attachment %" PRIu32 |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 2040 | " 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] | 2041 | func_name, string_SyncHazard(hazard.hazard), transition.prev_pass, transition.attachment, |
John Zulauf | 389c34b | 2020-07-28 11:19:35 -0600 | [diff] [blame] | 2042 | string_VkImageLayout(transition.old_layout), string_VkImageLayout(transition.new_layout), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2043 | string_UsageTag(hazard).c_str()); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | return skip; |
| 2047 | } |
| 2048 | |
| 2049 | void RenderPassAccessContext::RecordLayoutTransitions(const ResourceUsageTag &tag) { |
| 2050 | // Add layout transitions... |
| 2051 | const auto &transitions = rp_state_->subpass_transitions[current_subpass_]; |
| 2052 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
John Zulauf | c920122 | 2020-05-13 15:13:03 -0600 | [diff] [blame] | 2053 | std::set<const IMAGE_VIEW_STATE *> view_seen; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2054 | for (const auto &transition : transitions) { |
| 2055 | const auto attachment_view = attachment_views_[transition.attachment]; |
| 2056 | if (!attachment_view) continue; |
| 2057 | const auto image = attachment_view->image_state.get(); |
| 2058 | if (!image) continue; |
| 2059 | |
| 2060 | const auto *barrier = subpass_context.GetTrackBackFromSubpass(transition.prev_pass); |
John Zulauf | c920122 | 2020-05-13 15:13:03 -0600 | [diff] [blame] | 2061 | auto insert_pair = view_seen.insert(attachment_view); |
| 2062 | if (insert_pair.second) { |
| 2063 | // We haven't recorded the transistion yet, so treat this as a normal barrier with transistion. |
| 2064 | subpass_context.ApplyImageBarrier(*image, barrier->barrier, attachment_view->normalized_subresource_range, true, tag); |
| 2065 | |
| 2066 | } else { |
| 2067 | // We've recorded the transition, but we need to added on the additional dest barriers, and rerecording the transition |
| 2068 | // would clear out the prior barrier flags, so apply this as a *non* transition barrier |
| 2069 | auto barrier_to_transition = barrier->barrier; |
| 2070 | barrier_to_transition.src_access_scope |= SYNC_IMAGE_LAYOUT_TRANSITION_BIT; |
| 2071 | subpass_context.ApplyImageBarrier(*image, barrier->barrier, attachment_view->normalized_subresource_range, false, tag); |
| 2072 | } |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2076 | void RenderPassAccessContext::RecordLoadOperations(const VkRect2D &render_area, const ResourceUsageTag &tag) { |
| 2077 | const auto *attachment_ci = rp_state_->createInfo.pAttachments; |
| 2078 | auto &subpass_context = subpass_contexts_[current_subpass_]; |
| 2079 | VkExtent3D extent = CastTo3D(render_area.extent); |
| 2080 | VkOffset3D offset = CastTo3D(render_area.offset); |
| 2081 | |
| 2082 | for (uint32_t i = 0; i < rp_state_->createInfo.attachmentCount; i++) { |
| 2083 | if (rp_state_->attachment_first_subpass[i] == current_subpass_) { |
| 2084 | if (attachment_views_[i] == nullptr) continue; // UNUSED |
| 2085 | const auto &view = *attachment_views_[i]; |
| 2086 | const IMAGE_STATE *image = view.image_state.get(); |
| 2087 | if (image == nullptr) continue; |
| 2088 | |
| 2089 | const auto &ci = attachment_ci[i]; |
| 2090 | const bool has_depth = FormatHasDepth(ci.format); |
John Zulauf | b027cdb | 2020-05-21 14:25:22 -0600 | [diff] [blame] | 2091 | const bool has_stencil = FormatHasStencil(ci.format); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2092 | const bool is_color = !(has_depth || has_stencil); |
| 2093 | |
| 2094 | if (is_color) { |
| 2095 | subpass_context.UpdateAccessState(*image, ColorLoadUsage(ci.loadOp), view.normalized_subresource_range, offset, |
| 2096 | extent, tag); |
| 2097 | } else { |
| 2098 | auto update_range = view.normalized_subresource_range; |
| 2099 | if (has_depth) { |
| 2100 | update_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 2101 | subpass_context.UpdateAccessState(*image, DepthStencilLoadUsage(ci.loadOp), update_range, offset, extent, tag); |
| 2102 | } |
| 2103 | if (has_stencil) { |
| 2104 | update_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 2105 | subpass_context.UpdateAccessState(*image, DepthStencilLoadUsage(ci.stencilLoadOp), update_range, offset, extent, |
| 2106 | tag); |
| 2107 | } |
| 2108 | } |
| 2109 | } |
| 2110 | } |
| 2111 | } |
| 2112 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2113 | void RenderPassAccessContext::RecordBeginRenderPass(const SyncValidator &state, const CMD_BUFFER_STATE &cb_state, |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2114 | const AccessContext *external_context, VkQueueFlags queue_flags, |
| 2115 | const ResourceUsageTag &tag) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2116 | current_subpass_ = 0; |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 2117 | rp_state_ = cb_state.activeRenderPass.get(); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2118 | subpass_contexts_.reserve(rp_state_->createInfo.subpassCount); |
| 2119 | // Add this for all subpasses here so that they exsist during next subpass validation |
| 2120 | for (uint32_t pass = 0; pass < rp_state_->createInfo.subpassCount; pass++) { |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2121 | 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] | 2122 | } |
| 2123 | attachment_views_ = state.GetCurrentAttachmentViews(cb_state); |
| 2124 | |
| 2125 | RecordLayoutTransitions(tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2126 | RecordLoadOperations(cb_state.activeRenderPassBeginInfo.renderArea, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2127 | } |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2128 | |
| 2129 | void RenderPassAccessContext::RecordNextSubpass(const VkRect2D &render_area, const ResourceUsageTag &tag) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2130 | // Resolves are against *prior* subpass context and thus *before* the subpass increment |
| 2131 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, render_area, attachment_views_, current_subpass_, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2132 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, render_area, attachment_views_, current_subpass_, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2133 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2134 | current_subpass_++; |
| 2135 | assert(current_subpass_ < subpass_contexts_.size()); |
| 2136 | RecordLayoutTransitions(tag); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 2137 | RecordLoadOperations(render_area, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2138 | } |
| 2139 | |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2140 | void RenderPassAccessContext::RecordEndRenderPass(AccessContext *external_context, const VkRect2D &render_area, |
| 2141 | const ResourceUsageTag &tag) { |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2142 | // Add the resolve and store accesses |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2143 | CurrentContext().UpdateAttachmentResolveAccess(*rp_state_, render_area, attachment_views_, current_subpass_, tag); |
John Zulauf | aff2066 | 2020-06-01 14:07:58 -0600 | [diff] [blame] | 2144 | CurrentContext().UpdateAttachmentStoreAccess(*rp_state_, render_area, attachment_views_, current_subpass_, tag); |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2145 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2146 | // Export the accesses from the renderpass... |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2147 | external_context->ResolveChildContexts(subpass_contexts_); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2148 | |
| 2149 | // Add the "finalLayout" transitions to external |
| 2150 | // Get them from where there we're hidding in the extra entry. |
| 2151 | const auto &final_transitions = rp_state_->subpass_transitions.back(); |
| 2152 | for (const auto &transition : final_transitions) { |
| 2153 | const auto &attachment = attachment_views_[transition.attachment]; |
| 2154 | const auto &last_trackback = subpass_contexts_[transition.prev_pass].GetDstExternalTrackBack(); |
John Zulauf | aa97d8b | 2020-07-14 10:58:13 -0600 | [diff] [blame] | 2155 | assert(&subpass_contexts_[transition.prev_pass] == last_trackback.context); |
John Zulauf | 1a22429 | 2020-06-30 14:52:13 -0600 | [diff] [blame] | 2156 | external_context->ApplyImageBarrier(*attachment->image_state, last_trackback.barrier, |
| 2157 | attachment->normalized_subresource_range, true, tag); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2158 | } |
| 2159 | } |
| 2160 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2161 | SyncBarrier::SyncBarrier(VkQueueFlags queue_flags, const VkSubpassDependency2 &barrier) { |
| 2162 | const auto src_stage_mask = ExpandPipelineStages(queue_flags, barrier.srcStageMask); |
| 2163 | src_exec_scope = WithEarlierPipelineStages(src_stage_mask); |
| 2164 | src_access_scope = SyncStageAccess::AccessScope(src_stage_mask, barrier.srcAccessMask); |
| 2165 | const auto dst_stage_mask = ExpandPipelineStages(queue_flags, barrier.dstStageMask); |
| 2166 | dst_exec_scope = WithLaterPipelineStages(dst_stage_mask); |
| 2167 | dst_access_scope = SyncStageAccess::AccessScope(dst_stage_mask, barrier.dstAccessMask); |
| 2168 | } |
| 2169 | |
| 2170 | void ResourceAccessState::ApplyBarrier(const SyncBarrier &barrier) { |
| 2171 | ApplyExecutionBarrier(barrier.src_exec_scope, barrier.dst_exec_scope); |
| 2172 | ApplyMemoryAccessBarrier(barrier.src_exec_scope, barrier.src_access_scope, barrier.dst_exec_scope, barrier.dst_access_scope); |
| 2173 | } |
| 2174 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2175 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index) const { |
| 2176 | HazardResult hazard; |
| 2177 | auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2178 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2179 | if (IsRead(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2180 | // Only check reads vs. last_write if it doesn't happen-after any other read because either: |
| 2181 | // * the previous reads are not hazards, and thus last_write must be visible and available to |
| 2182 | // any reads that happen after. |
| 2183 | // * the previous reads *are* hazards to last_write, have been reported, and if that hazard is fixed |
| 2184 | // the current read will be also not be a hazard, thus reporting a hazard here adds no needed information. |
| 2185 | if (((usage_stage & read_execution_barriers) == 0) && last_write && IsWriteHazard(usage)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2186 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2187 | } |
| 2188 | } else { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2189 | // Write operation: |
| 2190 | // Check for read operations more recent than last_write (as setting last_write clears reads, that would be *any* |
| 2191 | // If reads exists -- test only against them because either: |
| 2192 | // * the reads were hazards, and we've reported the hazard, so just test the current write vs. the read operations |
| 2193 | // * 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 |
| 2194 | // the current write happens after the reads, so just test the write against the reades |
| 2195 | // Otherwise test against last_write |
| 2196 | // |
| 2197 | // Look for casus belli for WAR |
| 2198 | if (last_read_count) { |
| 2199 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
| 2200 | const auto &read_access = last_reads[read_index]; |
| 2201 | if (IsReadHazard(usage_stage, read_access)) { |
| 2202 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2203 | break; |
| 2204 | } |
| 2205 | } |
| 2206 | } else if (input_attachment_barriers != kNoAttachmentRead) { |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2207 | if (IsReadHazard(usage_stage, input_attachment_barriers)) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2208 | hazard.Set(this, usage_index, WRITE_AFTER_READ, SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ, input_attachment_tag); |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2209 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2210 | } else if (last_write && IsWriteHazard(usage)) { |
| 2211 | // Write-After-Write check -- if we have a previous write to test against |
| 2212 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2213 | } |
| 2214 | } |
| 2215 | return hazard; |
| 2216 | } |
| 2217 | |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2218 | HazardResult ResourceAccessState::DetectHazard(SyncStageAccessIndex usage_index, const SyncOrderingBarrier &ordering) const { |
| 2219 | // The ordering guarantees act as barriers to the last accesses, independent of synchronization operations |
| 2220 | HazardResult hazard; |
| 2221 | const auto usage = FlagBit(usage_index); |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2222 | const auto usage_stage = PipelineStageBit(usage_index); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2223 | const bool write_is_ordered = (last_write & ordering.access_scope) == last_write; // Is true if no write, and that's good. |
| 2224 | if (IsRead(usage)) { |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2225 | if (!write_is_ordered) { |
| 2226 | // Only check for RAW if the write is unordered, and there are no reads ordered before the current read since last_write |
| 2227 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 2228 | // We need to assemble the effect read_execution barriers from the union of the state barriers and the ordering rules |
| 2229 | // Check to see if there are any reads ordered before usage, including ordering rules and barriers. |
| 2230 | bool ordered_read = 0 != ((last_read_stages & ordering.exec_scope) | (read_execution_barriers & usage_stage)); |
| 2231 | // Noting the "special* encoding of the input attachment ordering rule (in access, but not exec) |
| 2232 | if ((ordering.access_scope & SyncStageAccessFlagBits::SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT) && |
| 2233 | (input_attachment_barriers != kNoAttachmentRead)) { |
| 2234 | ordered_read = true; |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2235 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2236 | |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2237 | if (!ordered_read && IsWriteHazard(usage)) { |
| 2238 | hazard.Set(this, usage_index, READ_AFTER_WRITE, last_write, write_tag); |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | } else { |
| 2243 | // Only check for WAW if there are no reads since last_write |
| 2244 | if (last_read_count) { |
| 2245 | // Ignore ordered read stages (which represent frame-buffer local operations, except input attachment |
| 2246 | const auto unordered_reads = last_read_stages & ~ordering.exec_scope; |
| 2247 | // Look for any WAR hazards outside the ordered set of stages |
| 2248 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
| 2249 | const auto &read_access = last_reads[read_index]; |
| 2250 | if ((read_access.stage & unordered_reads) && IsReadHazard(usage_stage, read_access)) { |
| 2251 | hazard.Set(this, usage_index, WRITE_AFTER_READ, read_access.access, read_access.tag); |
| 2252 | break; |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2253 | } |
| 2254 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2255 | } else if (input_attachment_barriers != kNoAttachmentRead) { |
| 2256 | // This is special case code for the fragment shader input attachment, which unlike all other fragment shader operations |
| 2257 | // is framebuffer local, and thus subject to raster ordering guarantees |
| 2258 | if (0 == (ordering.access_scope & SyncStageAccessFlagBits::SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT)) { |
| 2259 | // NOTE: Currently all ordering barriers include this bit, so this code may never be reached, but it's |
| 2260 | // here s.t. if we need to change the ordering barrier/rules we needn't change the code. |
| 2261 | hazard.Set(this, usage_index, WRITE_AFTER_READ, SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ, input_attachment_tag); |
| 2262 | } |
| 2263 | } else if (!write_is_ordered && IsWriteHazard(usage)) { |
| 2264 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
John Zulauf | 6913342 | 2020-05-20 14:55:53 -0600 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | return hazard; |
| 2268 | } |
| 2269 | |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2270 | // Asynchronous Hazards occur between subpasses with no connection through the DAG |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2271 | HazardResult ResourceAccessState::DetectAsyncHazard(SyncStageAccessIndex usage_index) const { |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2272 | HazardResult hazard; |
| 2273 | auto usage = FlagBit(usage_index); |
| 2274 | if (IsRead(usage)) { |
| 2275 | if (last_write != 0) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2276 | hazard.Set(this, usage_index, READ_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2277 | } |
| 2278 | } else { |
| 2279 | if (last_write != 0) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2280 | hazard.Set(this, usage_index, WRITE_RACING_WRITE, last_write, write_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2281 | } else if (last_read_count > 0) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2282 | hazard.Set(this, usage_index, WRITE_RACING_READ, last_reads[0].access, last_reads[0].tag); |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2283 | } else if (input_attachment_barriers != kNoAttachmentRead) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2284 | hazard.Set(this, usage_index, WRITE_RACING_READ, SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ, input_attachment_tag); |
John Zulauf | 2f952d2 | 2020-02-10 11:34:51 -0700 | [diff] [blame] | 2285 | } |
| 2286 | } |
| 2287 | return hazard; |
| 2288 | } |
| 2289 | |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2290 | HazardResult ResourceAccessState::DetectBarrierHazard(SyncStageAccessIndex usage_index, VkPipelineStageFlags src_exec_scope, |
| 2291 | SyncStageAccessFlags src_access_scope) const { |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2292 | // Only supporting image layout transitions for now |
| 2293 | assert(usage_index == SyncStageAccessIndex::SYNC_IMAGE_LAYOUT_TRANSITION); |
| 2294 | HazardResult hazard; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2295 | // only test for WAW if there no intervening read operations. |
| 2296 | // See DetectHazard(SyncStagetAccessIndex) above for more details. |
| 2297 | if (last_read_count) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2298 | // Look at the reads if any |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2299 | 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] | 2300 | const auto &read_access = last_reads[read_index]; |
| 2301 | // If the read stage is not in the src sync sync |
| 2302 | // *AND* not execution chained with an existing sync barrier (that's the or) |
| 2303 | // then the barrier access is unsafe (R/W after R) |
| 2304 | if ((src_exec_scope & (read_access.stage | read_access.barriers)) == 0) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2305 | 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] | 2306 | break; |
| 2307 | } |
| 2308 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2309 | } else if (input_attachment_barriers != kNoAttachmentRead) { |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2310 | // Same logic as read acces above for the special case of input attachment read |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2311 | if ((src_exec_scope & (VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | input_attachment_barriers)) == 0) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2312 | hazard.Set(this, usage_index, WRITE_AFTER_READ, SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT, input_attachment_tag); |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2313 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2314 | } else if (last_write) { |
| 2315 | // If the previous write is *not* in the 1st access scope |
| 2316 | // *AND* the current barrier is not in the dependency chain |
| 2317 | // *AND* the there is no prior memory barrier for the previous write in the dependency chain |
| 2318 | // then the barrier access is unsafe (R/W after W) |
| 2319 | if (((last_write & src_access_scope) == 0) && ((src_exec_scope & write_dependency_chain) == 0) && (write_barriers == 0)) { |
| 2320 | // TODO: Do we need a difference hazard name for this? |
| 2321 | hazard.Set(this, usage_index, WRITE_AFTER_WRITE, last_write, write_tag); |
| 2322 | } |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2323 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2324 | |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2325 | return hazard; |
| 2326 | } |
| 2327 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2328 | // The logic behind resolves is the same as update, we assume that earlier hazards have be reported, and that no |
| 2329 | // tranistive hazard can exists with a hazard between the earlier operations. Yes, an early hazard can mask that another |
| 2330 | // exists, but if you fix *that* hazard it either fixes or unmasks the subsequent ones. |
| 2331 | void ResourceAccessState::Resolve(const ResourceAccessState &other) { |
| 2332 | if (write_tag.IsBefore(other.write_tag)) { |
| 2333 | // If this is a later write, we've reported any exsiting hazard, and we can just overwrite as the more recent operation |
| 2334 | *this = other; |
| 2335 | } else if (!other.write_tag.IsBefore(write_tag)) { |
| 2336 | // This is the *equals* case for write operations, we merged the write barriers and the read state (but without the |
| 2337 | // dependency chaining logic or any stage expansion) |
| 2338 | write_barriers |= other.write_barriers; |
| 2339 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2340 | // Merge the read states |
| 2341 | if (input_attachment_barriers == kNoAttachmentRead) { |
| 2342 | // this doesn't have an input attachment read, so we'll take other, unconditionally (even if it's kNoAttachmentRead) |
| 2343 | input_attachment_barriers = other.input_attachment_barriers; |
| 2344 | input_attachment_tag = other.input_attachment_tag; |
| 2345 | } else if (other.input_attachment_barriers != kNoAttachmentRead) { |
| 2346 | // Both states have an input attachment read, pick the newest tag and merge barriers. |
| 2347 | if (input_attachment_tag.IsBefore(other.input_attachment_tag)) { |
| 2348 | input_attachment_tag = other.input_attachment_tag; |
| 2349 | } |
| 2350 | input_attachment_barriers |= other.input_attachment_barriers; |
| 2351 | } |
| 2352 | // The else clause is that only this has an attachment read and no merge is needed |
| 2353 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2354 | for (uint32_t other_read_index = 0; other_read_index < other.last_read_count; other_read_index++) { |
| 2355 | auto &other_read = other.last_reads[other_read_index]; |
| 2356 | if (last_read_stages & other_read.stage) { |
| 2357 | // Merge in the barriers for read stages that exist in *both* this and other |
| 2358 | // TODO: This is N^2 with stages... perhaps the ReadStates should be by stage index. |
| 2359 | for (uint32_t my_read_index = 0; my_read_index < last_read_count; my_read_index++) { |
| 2360 | auto &my_read = last_reads[my_read_index]; |
| 2361 | if (other_read.stage == my_read.stage) { |
| 2362 | if (my_read.tag.IsBefore(other_read.tag)) { |
| 2363 | my_read.tag = other_read.tag; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2364 | my_read.access = other_read.access; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2365 | } |
| 2366 | my_read.barriers |= other_read.barriers; |
| 2367 | break; |
| 2368 | } |
| 2369 | } |
| 2370 | } else { |
| 2371 | // The other read stage doesn't exist in this, so add it. |
| 2372 | last_reads[last_read_count] = other_read; |
| 2373 | last_read_count++; |
| 2374 | last_read_stages |= other_read.stage; |
| 2375 | } |
| 2376 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2377 | read_execution_barriers |= other.read_execution_barriers; |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2378 | } // the else clause would be that other write is before this write... in which case we supercede the other state and ignore |
| 2379 | // it. |
| 2380 | } |
| 2381 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2382 | void ResourceAccessState::Update(SyncStageAccessIndex usage_index, const ResourceUsageTag &tag) { |
| 2383 | // Move this logic in the ResourceStateTracker as methods, thereof (or we'll repeat it for every flavor of resource... |
| 2384 | const auto usage_bit = FlagBit(usage_index); |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2385 | if (usage_bit == SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT) { |
| 2386 | // Input attachment requires special treatment for raster/load/store ordering guarantees |
| 2387 | input_attachment_barriers = 0; |
| 2388 | input_attachment_tag = tag; |
| 2389 | } else if (IsRead(usage_index)) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2390 | // Mulitple outstanding reads may be of interest and do dependency chains independently |
| 2391 | // However, for purposes of barrier tracking, only one read per pipeline stage matters |
| 2392 | const auto usage_stage = PipelineStageBit(usage_index); |
| 2393 | if (usage_stage & last_read_stages) { |
| 2394 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
| 2395 | ReadState &access = last_reads[read_index]; |
| 2396 | if (access.stage == usage_stage) { |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2397 | access.access = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2398 | access.barriers = 0; |
| 2399 | access.tag = tag; |
| 2400 | break; |
| 2401 | } |
| 2402 | } |
| 2403 | } else { |
| 2404 | // We don't have this stage in the list yet... |
| 2405 | assert(last_read_count < last_reads.size()); |
| 2406 | ReadState &access = last_reads[last_read_count++]; |
| 2407 | access.stage = usage_stage; |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2408 | access.access = usage_bit; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2409 | access.barriers = 0; |
| 2410 | access.tag = tag; |
| 2411 | last_read_stages |= usage_stage; |
| 2412 | } |
| 2413 | } else { |
| 2414 | // Assume write |
| 2415 | // TODO determine what to do with READ-WRITE operations if any |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2416 | // Clobber last read and all barriers... because all we have is DANGER, DANGER, WILL ROBINSON!!! |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2417 | // if the last_reads/last_write were unsafe, we've reported them, |
| 2418 | // in either case the prior access is irrelevant, we can overwrite them as *this* write is now after them |
| 2419 | last_read_count = 0; |
| 2420 | last_read_stages = 0; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2421 | read_execution_barriers = 0; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2422 | |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2423 | input_attachment_barriers = kNoAttachmentRead; // Denotes no outstanding input attachment read after the last write. |
| 2424 | // NOTE: we don't reset the tag, as the equality check ignores it when kNoAttachmentRead is set. |
| 2425 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2426 | write_barriers = 0; |
| 2427 | write_dependency_chain = 0; |
| 2428 | write_tag = tag; |
| 2429 | last_write = usage_bit; |
| 2430 | } |
| 2431 | } |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2432 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2433 | void ResourceAccessState::ApplyExecutionBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask) { |
| 2434 | // Execution Barriers only protect read operations |
| 2435 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
| 2436 | ReadState &access = last_reads[read_index]; |
| 2437 | // The | implements the "dependency chain" logic for this access, as the barriers field stores the second sync scope |
| 2438 | if (srcStageMask & (access.stage | access.barriers)) { |
| 2439 | access.barriers |= dstStageMask; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2440 | read_execution_barriers |= dstStageMask; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2441 | } |
| 2442 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2443 | if ((input_attachment_barriers != kNoAttachmentRead) && |
| 2444 | (srcStageMask & (VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | input_attachment_barriers))) { |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2445 | input_attachment_barriers |= dstStageMask; |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2446 | read_execution_barriers |= dstStageMask; |
John Zulauf | d14743a | 2020-07-03 09:42:39 -0600 | [diff] [blame] | 2447 | } |
John Zulauf | 361fb53 | 2020-07-22 10:45:39 -0600 | [diff] [blame] | 2448 | if (write_dependency_chain & srcStageMask) { |
| 2449 | write_dependency_chain |= dstStageMask; |
| 2450 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2451 | } |
| 2452 | |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2453 | void ResourceAccessState::ApplyMemoryAccessBarrier(VkPipelineStageFlags src_exec_scope, SyncStageAccessFlags src_access_scope, |
| 2454 | VkPipelineStageFlags dst_exec_scope, SyncStageAccessFlags dst_access_scope) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2455 | // Assuming we've applied the execution side of this barrier, we update just the write |
| 2456 | // The || implements the "dependency chain" logic for this barrier |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2457 | if ((src_access_scope & last_write) || (write_dependency_chain & src_exec_scope)) { |
| 2458 | write_barriers |= dst_access_scope; |
| 2459 | write_dependency_chain |= dst_exec_scope; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2460 | } |
| 2461 | } |
| 2462 | |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2463 | // This should be just Bits or Index, but we don't have an invalid state for Index |
| 2464 | VkPipelineStageFlags ResourceAccessState::GetReadBarriers(SyncStageAccessFlags usage_bit) const { |
| 2465 | VkPipelineStageFlags barriers = 0U; |
| 2466 | if (usage_bit & SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ_BIT) { |
| 2467 | barriers = input_attachment_barriers; |
| 2468 | } else { |
| 2469 | for (uint32_t read_index = 0; read_index < last_read_count; read_index++) { |
| 2470 | const auto &read_access = last_reads[read_index]; |
| 2471 | if (read_access.access & usage_bit) { |
| 2472 | barriers = read_access.barriers; |
| 2473 | break; |
| 2474 | } |
| 2475 | } |
| 2476 | } |
| 2477 | return barriers; |
| 2478 | } |
| 2479 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 2480 | void SyncValidator::ResetCommandBufferCallback(VkCommandBuffer command_buffer) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2481 | auto *access_context = GetAccessContextNoInsert(command_buffer); |
| 2482 | if (access_context) { |
| 2483 | access_context->Reset(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2484 | } |
| 2485 | } |
| 2486 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 2487 | void SyncValidator::FreeCommandBufferCallback(VkCommandBuffer command_buffer) { |
| 2488 | auto access_found = cb_access_state.find(command_buffer); |
| 2489 | if (access_found != cb_access_state.end()) { |
| 2490 | access_found->second->Reset(); |
| 2491 | cb_access_state.erase(access_found); |
| 2492 | } |
| 2493 | } |
| 2494 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2495 | void SyncValidator::ApplyGlobalBarriers(AccessContext *context, VkPipelineStageFlags srcStageMask, |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2496 | VkPipelineStageFlags dstStageMask, SyncStageAccessFlags src_access_scope, |
| 2497 | SyncStageAccessFlags dst_access_scope, uint32_t memoryBarrierCount, |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2498 | const VkMemoryBarrier *pMemoryBarriers) { |
| 2499 | // TODO: Implement this better (maybe some delayed/on-demand integration). |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2500 | ApplyGlobalBarrierFunctor barriers_functor(srcStageMask, dstStageMask, src_access_scope, dst_access_scope, memoryBarrierCount, |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2501 | pMemoryBarriers); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2502 | context->ApplyGlobalBarriers(barriers_functor); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2503 | } |
| 2504 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2505 | void SyncValidator::ApplyBufferBarriers(AccessContext *context, VkPipelineStageFlags src_exec_scope, |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2506 | SyncStageAccessFlags src_stage_accesses, VkPipelineStageFlags dst_exec_scope, |
| 2507 | SyncStageAccessFlags dst_stage_accesses, uint32_t barrier_count, |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2508 | const VkBufferMemoryBarrier *barriers) { |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2509 | for (uint32_t index = 0; index < barrier_count; index++) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 2510 | auto barrier = barriers[index]; // barrier is a copy |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2511 | const auto *buffer = Get<BUFFER_STATE>(barrier.buffer); |
| 2512 | if (!buffer) continue; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 2513 | barrier.size = GetBufferWholeSize(*buffer, barrier.offset, barrier.size); |
| 2514 | const ResourceAccessRange range = MakeRange(barrier); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2515 | const auto src_access_scope = AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 2516 | const auto dst_access_scope = AccessScope(dst_stage_accesses, barrier.dstAccessMask); |
| 2517 | const ApplyMemoryAccessBarrierFunctor update_action(src_exec_scope, src_access_scope, dst_exec_scope, dst_access_scope); |
| 2518 | context->UpdateMemoryAccess(*buffer, range, update_action); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2522 | void SyncValidator::ApplyImageBarriers(AccessContext *context, VkPipelineStageFlags src_exec_scope, |
| 2523 | SyncStageAccessFlags src_stage_accesses, VkPipelineStageFlags dst_exec_scope, |
| 2524 | SyncStageAccessFlags dst_stage_accesses, uint32_t barrier_count, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2525 | const VkImageMemoryBarrier *barriers, const ResourceUsageTag &tag) { |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2526 | for (uint32_t index = 0; index < barrier_count; index++) { |
| 2527 | const auto &barrier = barriers[index]; |
| 2528 | const auto *image = Get<IMAGE_STATE>(barrier.image); |
| 2529 | if (!image) continue; |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2530 | auto subresource_range = NormalizeSubresourceRange(image->createInfo, barrier.subresourceRange); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2531 | bool layout_transition = barrier.oldLayout != barrier.newLayout; |
| 2532 | const auto src_access_scope = AccessScope(src_stage_accesses, barrier.srcAccessMask); |
| 2533 | const auto dst_access_scope = AccessScope(dst_stage_accesses, barrier.dstAccessMask); |
| 2534 | context->ApplyImageBarrier(*image, src_exec_scope, src_access_scope, dst_exec_scope, dst_access_scope, subresource_range, |
| 2535 | layout_transition, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2536 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | bool SyncValidator::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 2540 | uint32_t regionCount, const VkBufferCopy *pRegions) const { |
| 2541 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2542 | const auto *cb_context = GetAccessContext(commandBuffer); |
| 2543 | assert(cb_context); |
| 2544 | if (!cb_context) return skip; |
| 2545 | const auto *context = cb_context->GetCurrentAccessContext(); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2546 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2547 | // If we have no previous accesses, we have no hazards |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2548 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2549 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2550 | |
| 2551 | for (uint32_t region = 0; region < regionCount; region++) { |
| 2552 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2553 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 2554 | 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] | 2555 | auto hazard = context->DetectHazard(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2556 | if (hazard.hazard) { |
| 2557 | // TODO -- add tag information to log msg when useful. |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 2558 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2559 | "vkCmdCopyBuffer: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2560 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2561 | string_UsageTag(hazard).c_str()); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2562 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2563 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2564 | if (dst_buffer && !skip) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 2565 | 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] | 2566 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2567 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 2568 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2569 | "vkCmdCopyBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2570 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2571 | string_UsageTag(hazard).c_str()); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2572 | } |
| 2573 | } |
| 2574 | if (skip) break; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2575 | } |
| 2576 | return skip; |
| 2577 | } |
| 2578 | |
| 2579 | void SyncValidator::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 2580 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2581 | auto *cb_context = GetAccessContext(commandBuffer); |
| 2582 | assert(cb_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 2583 | const auto tag = cb_context->NextCommandTag(CMD_COPYBUFFER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2584 | auto *context = cb_context->GetCurrentAccessContext(); |
| 2585 | |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2586 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2587 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2588 | |
| 2589 | for (uint32_t region = 0; region < regionCount; region++) { |
| 2590 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2591 | if (src_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 2592 | 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] | 2593 | context->UpdateAccessState(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2594 | } |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2595 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 2596 | 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] | 2597 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2598 | } |
| 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | bool SyncValidator::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2603 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2604 | const VkImageCopy *pRegions) const { |
| 2605 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2606 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2607 | assert(cb_access_context); |
| 2608 | if (!cb_access_context) return skip; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2609 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2610 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 2611 | assert(context); |
| 2612 | if (!context) return skip; |
| 2613 | |
| 2614 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 2615 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2616 | for (uint32_t region = 0; region < regionCount; region++) { |
| 2617 | const auto ©_region = pRegions[region]; |
| 2618 | if (src_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2619 | 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] | 2620 | copy_region.srcOffset, copy_region.extent); |
| 2621 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 2622 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2623 | "vkCmdCopyImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2624 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2625 | string_UsageTag(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2626 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 2630 | VkExtent3D dst_copy_extent = |
| 2631 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2632 | 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] | 2633 | copy_region.dstOffset, dst_copy_extent); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2634 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 2635 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2636 | "vkCmdCopyImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2637 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2638 | string_UsageTag(hazard).c_str()); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2639 | } |
locke-lunarg | 1dbbb9e | 2020-02-28 22:43:53 -0700 | [diff] [blame] | 2640 | if (skip) break; |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2641 | } |
| 2642 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2643 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2644 | return skip; |
| 2645 | } |
| 2646 | |
| 2647 | void SyncValidator::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2648 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2649 | const VkImageCopy *pRegions) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2650 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2651 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 2652 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGE); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2653 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 2654 | assert(context); |
| 2655 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2656 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2657 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2658 | |
| 2659 | for (uint32_t region = 0; region < regionCount; region++) { |
| 2660 | const auto ©_region = pRegions[region]; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2661 | if (src_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2662 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, copy_region.srcSubresource, copy_region.srcOffset, |
| 2663 | copy_region.extent, tag); |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 2664 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2665 | if (dst_image) { |
locke-lunarg | 1df1f88 | 2020-03-02 16:42:08 -0700 | [diff] [blame] | 2666 | VkExtent3D dst_copy_extent = |
| 2667 | GetAdjustedDestImageExtent(src_image->createInfo.format, dst_image->createInfo.format, copy_region.extent); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2668 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, copy_region.dstSubresource, copy_region.dstOffset, |
| 2669 | dst_copy_extent, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2670 | } |
| 2671 | } |
| 2672 | } |
| 2673 | |
| 2674 | bool SyncValidator::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 2675 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 2676 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 2677 | uint32_t bufferMemoryBarrierCount, |
| 2678 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 2679 | uint32_t imageMemoryBarrierCount, |
| 2680 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
| 2681 | bool skip = false; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2682 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2683 | assert(cb_access_context); |
| 2684 | if (!cb_access_context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2685 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2686 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 2687 | assert(context); |
| 2688 | if (!context) return skip; |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2689 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2690 | const auto src_stage_mask = ExpandPipelineStages(cb_access_context->GetQueueFlags(), srcStageMask); |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2691 | const auto src_exec_scope = WithEarlierPipelineStages(src_stage_mask); |
| 2692 | auto src_stage_accesses = AccessScopeByStage(src_stage_mask); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2693 | // Validate Image Layout transitions |
| 2694 | for (uint32_t index = 0; index < imageMemoryBarrierCount; index++) { |
| 2695 | const auto &barrier = pImageMemoryBarriers[index]; |
| 2696 | if (barrier.newLayout == barrier.oldLayout) continue; // Only interested in layout transitions at this point. |
| 2697 | const auto *image_state = Get<IMAGE_STATE>(barrier.image); |
| 2698 | if (!image_state) continue; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 2699 | 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] | 2700 | if (hazard.hazard) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 2701 | // PHASE1 TODO -- add tag information to log msg when useful. |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 2702 | skip |= LogError(barrier.image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 2703 | "vkCmdPipelineBarrier: Hazard %s for image barrier %" PRIu32 " %s. Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 2704 | string_SyncHazard(hazard.hazard), index, report_data->FormatHandle(barrier.image).c_str(), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 2705 | string_UsageTag(hazard).c_str()); |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2706 | } |
| 2707 | } |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2708 | |
| 2709 | return skip; |
| 2710 | } |
| 2711 | |
| 2712 | void SyncValidator::PreCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 2713 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 2714 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 2715 | uint32_t bufferMemoryBarrierCount, |
| 2716 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 2717 | uint32_t imageMemoryBarrierCount, |
| 2718 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2719 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2720 | assert(cb_access_context); |
| 2721 | if (!cb_access_context) return; |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 2722 | const auto tag = cb_access_context->NextCommandTag(CMD_PIPELINEBARRIER); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2723 | auto access_context = cb_access_context->GetCurrentAccessContext(); |
| 2724 | assert(access_context); |
| 2725 | if (!access_context) return; |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2726 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2727 | const auto src_stage_mask = ExpandPipelineStages(cb_access_context->GetQueueFlags(), srcStageMask); |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2728 | auto src_stage_accesses = AccessScopeByStage(src_stage_mask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2729 | const auto dst_stage_mask = ExpandPipelineStages(cb_access_context->GetQueueFlags(), dstStageMask); |
John Zulauf | 36bcf6a | 2020-02-03 15:12:52 -0700 | [diff] [blame] | 2730 | auto dst_stage_accesses = AccessScopeByStage(dst_stage_mask); |
| 2731 | const auto src_exec_scope = WithEarlierPipelineStages(src_stage_mask); |
| 2732 | const auto dst_exec_scope = WithLaterPipelineStages(dst_stage_mask); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2733 | ApplyBufferBarriers(access_context, src_exec_scope, src_stage_accesses, dst_exec_scope, dst_stage_accesses, |
| 2734 | bufferMemoryBarrierCount, pBufferMemoryBarriers); |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 2735 | 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] | 2736 | imageMemoryBarrierCount, pImageMemoryBarriers, tag); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2737 | |
| 2738 | // Apply these last in-case there operation is a superset of the other two and would clean them up... |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2739 | ApplyGlobalBarriers(access_context, src_exec_scope, dst_exec_scope, src_stage_accesses, dst_stage_accesses, memoryBarrierCount, |
John Zulauf | 0cb5be2 | 2020-01-23 12:18:22 -0700 | [diff] [blame] | 2740 | pMemoryBarriers); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | void SyncValidator::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 2744 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result) { |
| 2745 | // The state tracker sets up the device state |
| 2746 | StateTracker::PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, result); |
| 2747 | |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 2748 | // Add the callback hooks for the functions that are either broadly or deeply used and that the ValidationStateTracker |
| 2749 | // refactor would be messier without. |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2750 | // TODO: Find a good way to do this hooklessly. |
| 2751 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 2752 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, LayerObjectTypeSyncValidation); |
| 2753 | SyncValidator *sync_device_state = static_cast<SyncValidator *>(validation_data); |
| 2754 | |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 2755 | sync_device_state->SetCommandBufferResetCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 2756 | sync_device_state->ResetCommandBufferCallback(command_buffer); |
| 2757 | }); |
| 2758 | sync_device_state->SetCommandBufferFreeCallback([sync_device_state](VkCommandBuffer command_buffer) -> void { |
| 2759 | sync_device_state->FreeCommandBufferCallback(command_buffer); |
| 2760 | }); |
John Zulauf | 9cb530d | 2019-09-30 14:14:10 -0600 | [diff] [blame] | 2761 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2762 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2763 | bool SyncValidator::ValidateBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 2764 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo, const char *func_name) const { |
| 2765 | bool skip = false; |
| 2766 | const auto rp_state = Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
| 2767 | auto cb_context = GetAccessContext(commandBuffer); |
| 2768 | |
| 2769 | if (rp_state && cb_context) { |
| 2770 | skip |= cb_context->ValidateBeginRenderPass(*rp_state, pRenderPassBegin, pSubpassBeginInfo, func_name); |
| 2771 | } |
| 2772 | |
| 2773 | return skip; |
| 2774 | } |
| 2775 | |
| 2776 | bool SyncValidator::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 2777 | VkSubpassContents contents) const { |
| 2778 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 2779 | auto subpass_begin_info = lvl_init_struct<VkSubpassBeginInfo>(); |
| 2780 | subpass_begin_info.contents = contents; |
| 2781 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, "vkCmdBeginRenderPass"); |
| 2782 | return skip; |
| 2783 | } |
| 2784 | |
| 2785 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 2786 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo) const { |
| 2787 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 2788 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, "vkCmdBeginRenderPass2"); |
| 2789 | return skip; |
| 2790 | } |
| 2791 | |
| 2792 | bool SyncValidator::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 2793 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 2794 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo) const { |
| 2795 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 2796 | skip |= ValidateBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, "vkCmdBeginRenderPass2KHR"); |
| 2797 | return skip; |
| 2798 | } |
| 2799 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2800 | void SyncValidator::PostCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo, |
| 2801 | VkResult result) { |
| 2802 | // The state tracker sets up the command buffer state |
| 2803 | StateTracker::PostCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo, result); |
| 2804 | |
| 2805 | // Create/initialize the structure that trackers accesses at the command buffer scope. |
| 2806 | auto cb_access_context = GetAccessContext(commandBuffer); |
| 2807 | assert(cb_access_context); |
| 2808 | cb_access_context->Reset(); |
| 2809 | } |
| 2810 | |
| 2811 | void SyncValidator::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2812 | const VkSubpassBeginInfo *pSubpassBeginInfo, CMD_TYPE command) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2813 | auto cb_context = GetAccessContext(commandBuffer); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2814 | if (cb_context) { |
| 2815 | cb_context->RecordBeginRenderPass(cb_context->NextCommandTag(command)); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2816 | } |
| 2817 | } |
| 2818 | |
| 2819 | void SyncValidator::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 2820 | VkSubpassContents contents) { |
| 2821 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 2822 | auto subpass_begin_info = lvl_init_struct<VkSubpassBeginInfo>(); |
| 2823 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2824 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, &subpass_begin_info, CMD_BEGINRENDERPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | void SyncValidator::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 2828 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 2829 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2830 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | void SyncValidator::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 2834 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 2835 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
| 2836 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2837 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, CMD_BEGINRENDERPASS2); |
| 2838 | } |
| 2839 | |
| 2840 | bool SyncValidator::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfoKHR *pSubpassBeginInfo, |
| 2841 | const VkSubpassEndInfoKHR *pSubpassEndInfo, const char *func_name) const { |
| 2842 | bool skip = false; |
| 2843 | |
| 2844 | auto cb_context = GetAccessContext(commandBuffer); |
| 2845 | assert(cb_context); |
| 2846 | auto cb_state = cb_context->GetCommandBufferState(); |
| 2847 | if (!cb_state) return skip; |
| 2848 | |
| 2849 | auto rp_state = cb_state->activeRenderPass; |
| 2850 | if (!rp_state) return skip; |
| 2851 | |
| 2852 | skip |= cb_context->ValidateNextSubpass(func_name); |
| 2853 | |
| 2854 | return skip; |
| 2855 | } |
| 2856 | |
| 2857 | bool SyncValidator::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) const { |
| 2858 | bool skip = StateTracker::PreCallValidateCmdNextSubpass(commandBuffer, contents); |
| 2859 | auto subpass_begin_info = lvl_init_struct<VkSubpassBeginInfo>(); |
| 2860 | subpass_begin_info.contents = contents; |
| 2861 | skip |= ValidateCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, "vkCmdNextSubpass"); |
| 2862 | return skip; |
| 2863 | } |
| 2864 | |
| 2865 | bool SyncValidator::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfoKHR *pSubpassBeginInfo, |
| 2866 | const VkSubpassEndInfoKHR *pSubpassEndInfo) const { |
| 2867 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
| 2868 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, "vkCmdNextSubpass2KHR"); |
| 2869 | return skip; |
| 2870 | } |
| 2871 | |
| 2872 | bool SyncValidator::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 2873 | const VkSubpassEndInfo *pSubpassEndInfo) const { |
| 2874 | bool skip = StateTracker::PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
| 2875 | skip |= ValidateCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, "vkCmdNextSubpass2"); |
| 2876 | return skip; |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | void SyncValidator::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2880 | const VkSubpassEndInfo *pSubpassEndInfo, CMD_TYPE command) { |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2881 | auto cb_context = GetAccessContext(commandBuffer); |
| 2882 | assert(cb_context); |
| 2883 | auto cb_state = cb_context->GetCommandBufferState(); |
| 2884 | if (!cb_state) return; |
| 2885 | |
| 2886 | auto rp_state = cb_state->activeRenderPass; |
| 2887 | if (!rp_state) return; |
| 2888 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2889 | cb_context->RecordNextSubpass(*rp_state, cb_context->NextCommandTag(command)); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | void SyncValidator::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 2893 | StateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
| 2894 | auto subpass_begin_info = lvl_init_struct<VkSubpassBeginInfo>(); |
| 2895 | subpass_begin_info.contents = contents; |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2896 | RecordCmdNextSubpass(commandBuffer, &subpass_begin_info, nullptr, CMD_NEXTSUBPASS); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2897 | } |
| 2898 | |
| 2899 | void SyncValidator::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 2900 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 2901 | StateTracker::PostCallRecordCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2902 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | void SyncValidator::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 2906 | const VkSubpassEndInfo *pSubpassEndInfo) { |
| 2907 | StateTracker::PostCallRecordCmdNextSubpass2KHR(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2908 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, CMD_NEXTSUBPASS2); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2909 | } |
| 2910 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2911 | bool SyncValidator::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfoKHR *pSubpassEndInfo, |
| 2912 | const char *func_name) const { |
| 2913 | bool skip = false; |
| 2914 | |
| 2915 | auto cb_context = GetAccessContext(commandBuffer); |
| 2916 | assert(cb_context); |
| 2917 | auto cb_state = cb_context->GetCommandBufferState(); |
| 2918 | if (!cb_state) return skip; |
| 2919 | |
| 2920 | auto rp_state = cb_state->activeRenderPass; |
| 2921 | if (!rp_state) return skip; |
| 2922 | |
| 2923 | skip |= cb_context->ValidateEndRenderpass(func_name); |
| 2924 | return skip; |
| 2925 | } |
| 2926 | |
| 2927 | bool SyncValidator::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 2928 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
| 2929 | skip |= ValidateCmdEndRenderPass(commandBuffer, nullptr, "vkEndRenderPass"); |
| 2930 | return skip; |
| 2931 | } |
| 2932 | |
| 2933 | bool SyncValidator::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, |
| 2934 | const VkSubpassEndInfoKHR *pSubpassEndInfo) const { |
| 2935 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
| 2936 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, "vkEndRenderPass2"); |
| 2937 | return skip; |
| 2938 | } |
| 2939 | |
| 2940 | bool SyncValidator::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 2941 | const VkSubpassEndInfoKHR *pSubpassEndInfo) const { |
| 2942 | bool skip = StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
| 2943 | skip |= ValidateCmdEndRenderPass(commandBuffer, pSubpassEndInfo, "vkEndRenderPass2KHR"); |
| 2944 | return skip; |
| 2945 | } |
| 2946 | |
| 2947 | void SyncValidator::RecordCmdEndRenderPass(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo, |
| 2948 | CMD_TYPE command) { |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 2949 | // Resolve the all subpass contexts to the command buffer contexts |
| 2950 | auto cb_context = GetAccessContext(commandBuffer); |
| 2951 | assert(cb_context); |
| 2952 | auto cb_state = cb_context->GetCommandBufferState(); |
| 2953 | if (!cb_state) return; |
| 2954 | |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 2955 | const auto *rp_state = cb_state->activeRenderPass.get(); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 2956 | if (!rp_state) return; |
| 2957 | |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2958 | cb_context->RecordEndRenderPass(*rp_state, cb_context->NextCommandTag(command)); |
John Zulauf | e5da6e5 | 2020-03-18 15:32:18 -0600 | [diff] [blame] | 2959 | } |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2960 | |
John Zulauf | 33fc1d5 | 2020-07-17 11:01:10 -0600 | [diff] [blame] | 2961 | // Simple heuristic rule to detect WAW operations representing algorithmically safe or increment |
| 2962 | // updates to a resource which do not conflict at the byte level. |
| 2963 | // TODO: Revisit this rule to see if it needs to be tighter or looser |
| 2964 | // TODO: Add programatic control over suppression heuristics |
| 2965 | bool SyncValidator::SupressedBoundDescriptorWAW(const HazardResult &hazard) const { |
| 2966 | return (hazard.hazard == WRITE_AFTER_WRITE) && (FlagBit(hazard.usage_index) == hazard.prior_access); |
| 2967 | } |
| 2968 | |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2969 | void SyncValidator::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2970 | RecordCmdEndRenderPass(commandBuffer, nullptr, CMD_ENDRENDERPASS); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 2971 | StateTracker::PostCallRecordCmdEndRenderPass(commandBuffer); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | void SyncValidator::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2975 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 2976 | StateTracker::PostCallRecordCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | void SyncValidator::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 2980 | RecordCmdEndRenderPass(commandBuffer, pSubpassEndInfo, CMD_ENDRENDERPASS2); |
John Zulauf | 5a1a538 | 2020-06-22 17:23:25 -0600 | [diff] [blame] | 2981 | StateTracker::PostCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
John Zulauf | 3d84f1b | 2020-03-09 13:33:25 -0600 | [diff] [blame] | 2982 | } |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 2983 | |
| 2984 | bool SyncValidator::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 2985 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2986 | const VkBufferImageCopy *pRegions) const { |
| 2987 | bool skip = false; |
| 2988 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 2989 | assert(cb_access_context); |
| 2990 | if (!cb_access_context) return skip; |
| 2991 | |
| 2992 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 2993 | assert(context); |
| 2994 | if (!context) return skip; |
| 2995 | |
| 2996 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 2997 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 2998 | |
| 2999 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3000 | const auto ©_region = pRegions[region]; |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3001 | if (src_buffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3002 | ResourceAccessRange src_range = |
| 3003 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3004 | auto hazard = context->DetectHazard(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3005 | if (hazard.hazard) { |
John Zulauf | 7635de3 | 2020-05-29 17:14:15 -0600 | [diff] [blame] | 3006 | // PHASE1 TODO -- add tag information to log msg when useful. |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3007 | skip |= LogError(srcBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3008 | "vkCmdCopyBufferToImage: Hazard %s for srcBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3009 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcBuffer).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3010 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3011 | } |
| 3012 | } |
| 3013 | if (dst_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3014 | 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] | 3015 | copy_region.imageOffset, copy_region.imageExtent); |
| 3016 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3017 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3018 | "vkCmdCopyBufferToImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3019 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3020 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3021 | } |
| 3022 | if (skip) break; |
| 3023 | } |
| 3024 | if (skip) break; |
| 3025 | } |
| 3026 | return skip; |
| 3027 | } |
| 3028 | |
| 3029 | void SyncValidator::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 3030 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3031 | const VkBufferImageCopy *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3032 | StateTracker::PreCallRecordCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3033 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3034 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3035 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYBUFFERTOIMAGE); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3036 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3037 | assert(context); |
| 3038 | |
| 3039 | const auto *src_buffer = Get<BUFFER_STATE>(srcBuffer); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3040 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3041 | |
| 3042 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3043 | const auto ©_region = pRegions[region]; |
| 3044 | if (src_buffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3045 | ResourceAccessRange src_range = |
| 3046 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, dst_image->createInfo.format)); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3047 | context->UpdateAccessState(*src_buffer, SYNC_TRANSFER_TRANSFER_READ, src_range, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3048 | } |
| 3049 | if (dst_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3050 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, copy_region.imageSubresource, |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3051 | copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3052 | } |
| 3053 | } |
| 3054 | } |
| 3055 | |
| 3056 | bool SyncValidator::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 3057 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, |
| 3058 | const VkBufferImageCopy *pRegions) const { |
| 3059 | bool skip = false; |
| 3060 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3061 | assert(cb_access_context); |
| 3062 | if (!cb_access_context) return skip; |
| 3063 | |
| 3064 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3065 | assert(context); |
| 3066 | if (!context) return skip; |
| 3067 | |
| 3068 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3069 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3070 | const auto dst_mem = (dst_buffer && !dst_buffer->sparse) ? dst_buffer->binding.mem_state->mem : VK_NULL_HANDLE; |
| 3071 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3072 | const auto ©_region = pRegions[region]; |
| 3073 | if (src_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3074 | 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] | 3075 | copy_region.imageOffset, copy_region.imageExtent); |
| 3076 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3077 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3078 | "vkCmdCopyImageToBuffer: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3079 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3080 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3081 | } |
| 3082 | } |
| 3083 | if (dst_mem) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3084 | ResourceAccessRange dst_range = |
| 3085 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3086 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3087 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3088 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3089 | "vkCmdCopyImageToBuffer: Hazard %s for dstBuffer %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3090 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstBuffer).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3091 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3092 | } |
| 3093 | } |
| 3094 | if (skip) break; |
| 3095 | } |
| 3096 | return skip; |
| 3097 | } |
| 3098 | |
| 3099 | void SyncValidator::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3100 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3101 | StateTracker::PreCallRecordCmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3102 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3103 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3104 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYIMAGETOBUFFER); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3105 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3106 | assert(context); |
| 3107 | |
| 3108 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3109 | auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3110 | 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] | 3111 | const VulkanTypedHandle dst_handle(dst_mem, kVulkanObjectTypeDeviceMemory); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3112 | |
| 3113 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3114 | const auto ©_region = pRegions[region]; |
| 3115 | if (src_image) { |
John Zulauf | 540266b | 2020-04-06 18:54:53 -0600 | [diff] [blame] | 3116 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, copy_region.imageSubresource, |
John Zulauf | 5f13a79 | 2020-03-10 07:31:21 -0600 | [diff] [blame] | 3117 | copy_region.imageOffset, copy_region.imageExtent, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3118 | } |
| 3119 | if (dst_buffer) { |
John Zulauf | 355e49b | 2020-04-24 15:11:15 -0600 | [diff] [blame] | 3120 | ResourceAccessRange dst_range = |
| 3121 | MakeRange(copy_region.bufferOffset, GetBufferSizeFromCopyImage(copy_region, src_image->createInfo.format)); |
John Zulauf | 16adfc9 | 2020-04-08 10:28:33 -0600 | [diff] [blame] | 3122 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, dst_range, tag); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3123 | } |
| 3124 | } |
| 3125 | } |
| 3126 | |
| 3127 | bool SyncValidator::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3128 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3129 | const VkImageBlit *pRegions, VkFilter filter) const { |
| 3130 | bool skip = false; |
| 3131 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3132 | assert(cb_access_context); |
| 3133 | if (!cb_access_context) return skip; |
| 3134 | |
| 3135 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3136 | assert(context); |
| 3137 | if (!context) return skip; |
| 3138 | |
| 3139 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3140 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3141 | |
| 3142 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3143 | const auto &blit_region = pRegions[region]; |
| 3144 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3145 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3146 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3147 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3148 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3149 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3150 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].z - blit_region.srcOffsets[0].z))}; |
| 3151 | auto hazard = |
| 3152 | 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] | 3153 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3154 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3155 | "vkCmdBlitImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3156 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3157 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3158 | } |
| 3159 | } |
| 3160 | |
| 3161 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3162 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3163 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3164 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3165 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3166 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3167 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].z - blit_region.dstOffsets[0].z))}; |
| 3168 | auto hazard = |
| 3169 | 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] | 3170 | if (hazard.hazard) { |
locke-lunarg | a000365 | 2020-03-10 11:38:51 -0600 | [diff] [blame] | 3171 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3172 | "vkCmdBlitImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3173 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3174 | string_UsageTag(hazard).c_str()); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3175 | } |
| 3176 | if (skip) break; |
| 3177 | } |
| 3178 | } |
| 3179 | |
| 3180 | return skip; |
| 3181 | } |
| 3182 | |
| 3183 | void SyncValidator::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3184 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3185 | const VkImageBlit *pRegions, VkFilter filter) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3186 | StateTracker::PreCallRecordCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 3187 | pRegions, filter); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3188 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3189 | assert(cb_access_context); |
John Zulauf | 2b151bf | 2020-04-24 15:37:44 -0600 | [diff] [blame] | 3190 | const auto tag = cb_access_context->NextCommandTag(CMD_BLITIMAGE); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3191 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3192 | assert(context); |
| 3193 | |
| 3194 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3195 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
locke-lunarg | a19c71d | 2020-03-02 18:17:04 -0700 | [diff] [blame] | 3196 | |
| 3197 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3198 | const auto &blit_region = pRegions[region]; |
| 3199 | if (src_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3200 | VkOffset3D offset = {std::min(blit_region.srcOffsets[0].x, blit_region.srcOffsets[1].x), |
| 3201 | std::min(blit_region.srcOffsets[0].y, blit_region.srcOffsets[1].y), |
| 3202 | std::min(blit_region.srcOffsets[0].z, blit_region.srcOffsets[1].z)}; |
| 3203 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.srcOffsets[1].x - blit_region.srcOffsets[0].x)), |
| 3204 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].y - blit_region.srcOffsets[0].y)), |
| 3205 | static_cast<uint32_t>(abs(blit_region.srcOffsets[1].z - blit_region.srcOffsets[0].z))}; |
| 3206 | 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] | 3207 | } |
| 3208 | if (dst_image) { |
locke-lunarg | 8f93acc | 2020-06-18 21:26:46 -0600 | [diff] [blame] | 3209 | VkOffset3D offset = {std::min(blit_region.dstOffsets[0].x, blit_region.dstOffsets[1].x), |
| 3210 | std::min(blit_region.dstOffsets[0].y, blit_region.dstOffsets[1].y), |
| 3211 | std::min(blit_region.dstOffsets[0].z, blit_region.dstOffsets[1].z)}; |
| 3212 | VkExtent3D extent = {static_cast<uint32_t>(abs(blit_region.dstOffsets[1].x - blit_region.dstOffsets[0].x)), |
| 3213 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].y - blit_region.dstOffsets[0].y)), |
| 3214 | static_cast<uint32_t>(abs(blit_region.dstOffsets[1].z - blit_region.dstOffsets[0].z))}; |
| 3215 | 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] | 3216 | } |
| 3217 | } |
| 3218 | } |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3219 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3220 | bool SyncValidator::ValidateIndirectBuffer(const AccessContext &context, VkCommandBuffer commandBuffer, |
| 3221 | const VkDeviceSize struct_size, const VkBuffer buffer, const VkDeviceSize offset, |
| 3222 | const uint32_t drawCount, const uint32_t stride, const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3223 | bool skip = false; |
| 3224 | if (drawCount == 0) return skip; |
| 3225 | |
| 3226 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 3227 | VkDeviceSize size = struct_size; |
| 3228 | if (drawCount == 1 || stride == size) { |
| 3229 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3230 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3231 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3232 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3233 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3234 | "%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] | 3235 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3236 | string_UsageTag(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3237 | } |
| 3238 | } else { |
| 3239 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3240 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3241 | auto hazard = context.DetectHazard(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3242 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3243 | skip |= LogError(buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3244 | "%s: Hazard %s for indirect %s in %s. Access info %s.", function, string_SyncHazard(hazard.hazard), |
| 3245 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
| 3246 | string_UsageTag(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3247 | break; |
| 3248 | } |
| 3249 | } |
| 3250 | } |
| 3251 | return skip; |
| 3252 | } |
| 3253 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3254 | void SyncValidator::RecordIndirectBuffer(AccessContext &context, const ResourceUsageTag &tag, const VkDeviceSize struct_size, |
| 3255 | const VkBuffer buffer, const VkDeviceSize offset, const uint32_t drawCount, |
| 3256 | uint32_t stride) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3257 | const auto *buf_state = Get<BUFFER_STATE>(buffer); |
| 3258 | VkDeviceSize size = struct_size; |
| 3259 | if (drawCount == 1 || stride == size) { |
| 3260 | if (drawCount > 1) size *= drawCount; |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3261 | const ResourceAccessRange range = MakeRange(offset, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3262 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range, tag); |
| 3263 | } else { |
| 3264 | for (uint32_t i = 0; i < drawCount; ++i) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3265 | const ResourceAccessRange range = MakeRange(offset + i * stride, size); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3266 | context.UpdateAccessState(*buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range, tag); |
| 3267 | } |
| 3268 | } |
| 3269 | } |
| 3270 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3271 | bool SyncValidator::ValidateCountBuffer(const AccessContext &context, VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3272 | VkDeviceSize offset, const char *function) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3273 | bool skip = false; |
| 3274 | |
| 3275 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3276 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3277 | auto hazard = context.DetectHazard(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range); |
| 3278 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3279 | skip |= LogError(count_buf_state->buffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3280 | "%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] | 3281 | report_data->FormatHandle(buffer).c_str(), report_data->FormatHandle(commandBuffer).c_str(), |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3282 | string_UsageTag(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3283 | } |
| 3284 | return skip; |
| 3285 | } |
| 3286 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3287 | void SyncValidator::RecordCountBuffer(AccessContext &context, const ResourceUsageTag &tag, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3288 | const auto *count_buf_state = Get<BUFFER_STATE>(buffer); |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3289 | const ResourceAccessRange range = MakeRange(offset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3290 | context.UpdateAccessState(*count_buf_state, SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ, range, tag); |
| 3291 | } |
| 3292 | |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3293 | 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] | 3294 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3295 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3296 | assert(cb_access_context); |
| 3297 | if (!cb_access_context) return skip; |
| 3298 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3299 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3300 | return skip; |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3301 | } |
| 3302 | |
| 3303 | 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] | 3304 | StateTracker::PreCallRecordCmdDispatch(commandBuffer, x, y, z); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3305 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3306 | assert(cb_access_context); |
| 3307 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCH); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3308 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3309 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
locke-lunarg | 36ba259 | 2020-04-03 09:42:04 -0600 | [diff] [blame] | 3310 | } |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3311 | |
| 3312 | bool SyncValidator::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3313 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3314 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3315 | assert(cb_access_context); |
| 3316 | if (!cb_access_context) return skip; |
| 3317 | |
| 3318 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3319 | assert(context); |
| 3320 | if (!context) return skip; |
| 3321 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3322 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect"); |
| 3323 | skip |= ValidateIndirectBuffer(*context, commandBuffer, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, |
| 3324 | sizeof(VkDispatchIndirectCommand), "vkCmdDispatchIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3325 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | void SyncValidator::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3329 | StateTracker::PreCallRecordCmdDispatchIndirect(commandBuffer, buffer, offset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3330 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3331 | assert(cb_access_context); |
| 3332 | const auto tag = cb_access_context->NextCommandTag(CMD_DISPATCHINDIRECT); |
| 3333 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3334 | assert(context); |
| 3335 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3336 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_COMPUTE, tag); |
| 3337 | RecordIndirectBuffer(*context, tag, sizeof(VkDispatchIndirectCommand), buffer, offset, 1, sizeof(VkDispatchIndirectCommand)); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | bool SyncValidator::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 3341 | uint32_t firstVertex, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 3342 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3343 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3344 | assert(cb_access_context); |
| 3345 | if (!cb_access_context) return skip; |
| 3346 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3347 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw"); |
| 3348 | skip |= cb_access_context->ValidateDrawVertex(vertexCount, firstVertex, "vkCmdDraw"); |
| 3349 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDraw"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 3350 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | void SyncValidator::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 3354 | uint32_t firstVertex, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3355 | StateTracker::PreCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3356 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3357 | assert(cb_access_context); |
| 3358 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAW); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3359 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3360 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3361 | cb_access_context->RecordDrawVertex(vertexCount, firstVertex, tag); |
| 3362 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3363 | } |
| 3364 | |
| 3365 | bool SyncValidator::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 3366 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 3367 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3368 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3369 | assert(cb_access_context); |
| 3370 | if (!cb_access_context) return skip; |
| 3371 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3372 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed"); |
| 3373 | skip |= cb_access_context->ValidateDrawVertexIndex(indexCount, firstIndex, "vkCmdDrawIndexed"); |
| 3374 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexed"); |
locke-lunarg | a4d39ea | 2020-05-22 14:17:29 -0600 | [diff] [blame] | 3375 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | void SyncValidator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 3379 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3380 | StateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3381 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3382 | assert(cb_access_context); |
| 3383 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXED); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3384 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3385 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3386 | cb_access_context->RecordDrawVertexIndex(indexCount, firstIndex, tag); |
| 3387 | cb_access_context->RecordDrawSubpassAttachment(tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | bool SyncValidator::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3391 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3392 | bool skip = false; |
| 3393 | if (drawCount == 0) return skip; |
| 3394 | |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3395 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3396 | assert(cb_access_context); |
| 3397 | if (!cb_access_context) return skip; |
| 3398 | |
| 3399 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3400 | assert(context); |
| 3401 | if (!context) return skip; |
| 3402 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3403 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect"); |
| 3404 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndirect"); |
| 3405 | skip |= ValidateIndirectBuffer(*context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride, |
| 3406 | "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3407 | |
| 3408 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 3409 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 3410 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3411 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, "vkCmdDrawIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3412 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | void SyncValidator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3416 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3417 | StateTracker::PreCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3418 | if (drawCount == 0) return; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3419 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3420 | assert(cb_access_context); |
| 3421 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECT); |
| 3422 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3423 | assert(context); |
| 3424 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3425 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3426 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 3427 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3428 | |
| 3429 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 3430 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 3431 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3432 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3436 | uint32_t drawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3437 | bool skip = false; |
| 3438 | if (drawCount == 0) return skip; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3439 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3440 | assert(cb_access_context); |
| 3441 | if (!cb_access_context) return skip; |
| 3442 | |
| 3443 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3444 | assert(context); |
| 3445 | if (!context) return skip; |
| 3446 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3447 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect"); |
| 3448 | skip |= cb_access_context->ValidateDrawSubpassAttachment("vkCmdDrawIndexedIndirect"); |
| 3449 | skip |= ValidateIndirectBuffer(*context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride, |
| 3450 | "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3451 | |
| 3452 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 3453 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 3454 | // 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] | 3455 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, "vkCmdDrawIndexedIndirect"); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3456 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3460 | uint32_t drawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3461 | StateTracker::PreCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3462 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3463 | assert(cb_access_context); |
| 3464 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECT); |
| 3465 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3466 | assert(context); |
| 3467 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3468 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3469 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 3470 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, drawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3471 | |
| 3472 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 3473 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 3474 | // 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] | 3475 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | bool SyncValidator::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3479 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3480 | uint32_t stride, const char *function) const { |
| 3481 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3482 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3483 | assert(cb_access_context); |
| 3484 | if (!cb_access_context) return skip; |
| 3485 | |
| 3486 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3487 | assert(context); |
| 3488 | if (!context) return skip; |
| 3489 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3490 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 3491 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
| 3492 | skip |= ValidateIndirectBuffer(*context, commandBuffer, sizeof(VkDrawIndirectCommand), buffer, offset, maxDrawCount, stride, |
| 3493 | function); |
| 3494 | skip |= ValidateCountBuffer(*context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3495 | |
| 3496 | // TODO: For now, we validate the whole vertex buffer. It might cause some false positive. |
| 3497 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 3498 | // We will validate the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3499 | skip |= cb_access_context->ValidateDrawVertex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3500 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | bool SyncValidator::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3504 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3505 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3506 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3507 | "vkCmdDrawIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | void SyncValidator::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3511 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3512 | uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3513 | StateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 3514 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3515 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3516 | assert(cb_access_context); |
| 3517 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDIRECTCOUNT); |
| 3518 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3519 | assert(context); |
| 3520 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3521 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3522 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 3523 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndirectCommand), buffer, offset, 1, stride); |
| 3524 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3525 | |
| 3526 | // TODO: For now, we record the whole vertex buffer. It might cause some false positive. |
| 3527 | // VkDrawIndirectCommand buffer could be changed until SubmitQueue. |
| 3528 | // We will record the vertex buffer in SubmitQueue in the future. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3529 | cb_access_context->RecordDrawVertex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3533 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3534 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3535 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3536 | "vkCmdDrawIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | void SyncValidator::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3540 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3541 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3542 | StateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 3543 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3544 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | bool SyncValidator::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3548 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3549 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3550 | return ValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3551 | "vkCmdDrawIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | void SyncValidator::PreCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3555 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3556 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3557 | StateTracker::PreCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 3558 | stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3559 | PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 3560 | } |
| 3561 | |
| 3562 | bool SyncValidator::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3563 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3564 | uint32_t stride, const char *function) const { |
| 3565 | bool skip = false; |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3566 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3567 | assert(cb_access_context); |
| 3568 | if (!cb_access_context) return skip; |
| 3569 | |
| 3570 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3571 | assert(context); |
| 3572 | if (!context) return skip; |
| 3573 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3574 | skip |= cb_access_context->ValidateDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
| 3575 | skip |= cb_access_context->ValidateDrawSubpassAttachment(function); |
| 3576 | skip |= ValidateIndirectBuffer(*context, commandBuffer, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, maxDrawCount, |
| 3577 | stride, function); |
| 3578 | skip |= ValidateCountBuffer(*context, commandBuffer, countBuffer, countBufferOffset, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3579 | |
| 3580 | // TODO: For now, we validate the whole index and vertex buffer. It might cause some false positive. |
| 3581 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
| 3582 | // 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] | 3583 | skip |= cb_access_context->ValidateDrawVertexIndex(UINT32_MAX, 0, function); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3584 | return skip; |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3588 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3589 | uint32_t maxDrawCount, uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3590 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3591 | "vkCmdDrawIndexedIndirectCount"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3592 | } |
| 3593 | |
| 3594 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3595 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3596 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3597 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 3598 | maxDrawCount, stride); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3599 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3600 | assert(cb_access_context); |
| 3601 | const auto tag = cb_access_context->NextCommandTag(CMD_DRAWINDEXEDINDIRECTCOUNT); |
| 3602 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3603 | assert(context); |
| 3604 | |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3605 | cb_access_context->RecordDispatchDrawDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, tag); |
| 3606 | cb_access_context->RecordDrawSubpassAttachment(tag); |
| 3607 | RecordIndirectBuffer(*context, tag, sizeof(VkDrawIndexedIndirectCommand), buffer, offset, 1, stride); |
| 3608 | RecordCountBuffer(*context, tag, countBuffer, countBufferOffset); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3609 | |
| 3610 | // TODO: For now, we record the whole index and vertex buffer. It might cause some false positive. |
| 3611 | // VkDrawIndexedIndirectCommand buffer could be changed until SubmitQueue. |
locke-lunarg | 61870c2 | 2020-06-09 14:51:50 -0600 | [diff] [blame] | 3612 | // We will update the index and vertex buffer in SubmitQueue in the future. |
| 3613 | cb_access_context->RecordDrawVertexIndex(UINT32_MAX, 0, tag); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3614 | } |
| 3615 | |
| 3616 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3617 | VkDeviceSize offset, VkBuffer countBuffer, |
| 3618 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3619 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3620 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3621 | "vkCmdDrawIndexedIndirectCountKHR"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3625 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3626 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3627 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 3628 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3629 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 3630 | } |
| 3631 | |
| 3632 | bool SyncValidator::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3633 | VkDeviceSize offset, VkBuffer countBuffer, |
| 3634 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3635 | uint32_t stride) const { |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3636 | return ValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 3637 | "vkCmdDrawIndexedIndirectCountAMD"); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | void SyncValidator::PreCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3641 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3642 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3643 | StateTracker::PreCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 3644 | maxDrawCount, stride); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3645 | PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); |
| 3646 | } |
| 3647 | |
| 3648 | bool SyncValidator::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 3649 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 3650 | const VkImageSubresourceRange *pRanges) const { |
| 3651 | bool skip = false; |
| 3652 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3653 | assert(cb_access_context); |
| 3654 | if (!cb_access_context) return skip; |
| 3655 | |
| 3656 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3657 | assert(context); |
| 3658 | if (!context) return skip; |
| 3659 | |
| 3660 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 3661 | |
| 3662 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 3663 | const auto &range = pRanges[index]; |
| 3664 | if (image_state) { |
| 3665 | auto hazard = |
| 3666 | context->DetectHazard(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent); |
| 3667 | if (hazard.hazard) { |
| 3668 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3669 | "vkCmdClearColorImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3670 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3671 | string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | } |
| 3675 | return skip; |
| 3676 | } |
| 3677 | |
| 3678 | void SyncValidator::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 3679 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 3680 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3681 | StateTracker::PreCallRecordCmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3682 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3683 | assert(cb_access_context); |
| 3684 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARCOLORIMAGE); |
| 3685 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3686 | assert(context); |
| 3687 | |
| 3688 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 3689 | |
| 3690 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 3691 | const auto &range = pRanges[index]; |
| 3692 | if (image_state) { |
| 3693 | context->UpdateAccessState(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent, |
| 3694 | tag); |
| 3695 | } |
| 3696 | } |
| 3697 | } |
| 3698 | |
| 3699 | bool SyncValidator::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 3700 | VkImageLayout imageLayout, |
| 3701 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 3702 | const VkImageSubresourceRange *pRanges) const { |
| 3703 | bool skip = false; |
| 3704 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3705 | assert(cb_access_context); |
| 3706 | if (!cb_access_context) return skip; |
| 3707 | |
| 3708 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3709 | assert(context); |
| 3710 | if (!context) return skip; |
| 3711 | |
| 3712 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 3713 | |
| 3714 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 3715 | const auto &range = pRanges[index]; |
| 3716 | if (image_state) { |
| 3717 | auto hazard = |
| 3718 | context->DetectHazard(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent); |
| 3719 | if (hazard.hazard) { |
| 3720 | skip |= LogError(image, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3721 | "vkCmdClearDepthStencilImage: Hazard %s for %s, range index %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3722 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(image).c_str(), index, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3723 | string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3724 | } |
| 3725 | } |
| 3726 | } |
| 3727 | return skip; |
| 3728 | } |
| 3729 | |
| 3730 | void SyncValidator::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 3731 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 3732 | const VkImageSubresourceRange *pRanges) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3733 | StateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3734 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3735 | assert(cb_access_context); |
| 3736 | const auto tag = cb_access_context->NextCommandTag(CMD_CLEARDEPTHSTENCILIMAGE); |
| 3737 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3738 | assert(context); |
| 3739 | |
| 3740 | const auto *image_state = Get<IMAGE_STATE>(image); |
| 3741 | |
| 3742 | for (uint32_t index = 0; index < rangeCount; index++) { |
| 3743 | const auto &range = pRanges[index]; |
| 3744 | if (image_state) { |
| 3745 | context->UpdateAccessState(*image_state, SYNC_TRANSFER_TRANSFER_WRITE, range, {0, 0, 0}, image_state->createInfo.extent, |
| 3746 | tag); |
| 3747 | } |
| 3748 | } |
| 3749 | } |
| 3750 | |
| 3751 | bool SyncValidator::PreCallValidateCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 3752 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 3753 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 3754 | VkQueryResultFlags flags) const { |
| 3755 | bool skip = false; |
| 3756 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3757 | assert(cb_access_context); |
| 3758 | if (!cb_access_context) return skip; |
| 3759 | |
| 3760 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3761 | assert(context); |
| 3762 | if (!context) return skip; |
| 3763 | |
| 3764 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3765 | |
| 3766 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3767 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3768 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 3769 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3770 | skip |= |
| 3771 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3772 | "vkCmdCopyQueryPoolResults: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
| 3773 | report_data->FormatHandle(dstBuffer).c_str(), string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3774 | } |
| 3775 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3776 | |
| 3777 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3778 | return skip; |
| 3779 | } |
| 3780 | |
| 3781 | void SyncValidator::PreCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, |
| 3782 | uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 3783 | VkDeviceSize stride, VkQueryResultFlags flags) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3784 | StateTracker::PreCallRecordCmdCopyQueryPoolResults(commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, |
| 3785 | stride, flags); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3786 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3787 | assert(cb_access_context); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3788 | const auto tag = cb_access_context->NextCommandTag(CMD_COPYQUERYPOOLRESULTS); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3789 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3790 | assert(context); |
| 3791 | |
| 3792 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3793 | |
| 3794 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3795 | const ResourceAccessRange range = MakeRange(dstOffset, stride * queryCount); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3796 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range, tag); |
| 3797 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3798 | |
| 3799 | // TODO:Track VkQueryPool |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | bool SyncValidator::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 3803 | VkDeviceSize size, uint32_t data) const { |
| 3804 | bool skip = false; |
| 3805 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3806 | assert(cb_access_context); |
| 3807 | if (!cb_access_context) return skip; |
| 3808 | |
| 3809 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3810 | assert(context); |
| 3811 | if (!context) return skip; |
| 3812 | |
| 3813 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3814 | |
| 3815 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3816 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3817 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 3818 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3819 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3820 | "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] | 3821 | report_data->FormatHandle(dstBuffer).c_str(), string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3822 | } |
| 3823 | } |
| 3824 | return skip; |
| 3825 | } |
| 3826 | |
| 3827 | void SyncValidator::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 3828 | VkDeviceSize size, uint32_t data) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3829 | StateTracker::PreCallRecordCmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3830 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3831 | assert(cb_access_context); |
| 3832 | const auto tag = cb_access_context->NextCommandTag(CMD_FILLBUFFER); |
| 3833 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3834 | assert(context); |
| 3835 | |
| 3836 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3837 | |
| 3838 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3839 | const ResourceAccessRange range = MakeRange(*dst_buffer, dstOffset, size); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3840 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range, tag); |
| 3841 | } |
| 3842 | } |
| 3843 | |
| 3844 | bool SyncValidator::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3845 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3846 | const VkImageResolve *pRegions) const { |
| 3847 | bool skip = false; |
| 3848 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3849 | assert(cb_access_context); |
| 3850 | if (!cb_access_context) return skip; |
| 3851 | |
| 3852 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3853 | assert(context); |
| 3854 | if (!context) return skip; |
| 3855 | |
| 3856 | const auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3857 | const auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3858 | |
| 3859 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3860 | const auto &resolve_region = pRegions[region]; |
| 3861 | if (src_image) { |
| 3862 | auto hazard = context->DetectHazard(*src_image, SYNC_TRANSFER_TRANSFER_READ, resolve_region.srcSubresource, |
| 3863 | resolve_region.srcOffset, resolve_region.extent); |
| 3864 | if (hazard.hazard) { |
| 3865 | skip |= LogError(srcImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3866 | "vkCmdResolveImage: Hazard %s for srcImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3867 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(srcImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3868 | string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3869 | } |
| 3870 | } |
| 3871 | |
| 3872 | if (dst_image) { |
| 3873 | auto hazard = context->DetectHazard(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, resolve_region.dstSubresource, |
| 3874 | resolve_region.dstOffset, resolve_region.extent); |
| 3875 | if (hazard.hazard) { |
| 3876 | skip |= LogError(dstImage, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3877 | "vkCmdResolveImage: Hazard %s for dstImage %s, region %" PRIu32 ". Access info %s.", |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3878 | string_SyncHazard(hazard.hazard), report_data->FormatHandle(dstImage).c_str(), region, |
John Zulauf | 37ceaed | 2020-07-03 16:18:15 -0600 | [diff] [blame] | 3879 | string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3880 | } |
| 3881 | if (skip) break; |
| 3882 | } |
| 3883 | } |
| 3884 | |
| 3885 | return skip; |
| 3886 | } |
| 3887 | |
| 3888 | void SyncValidator::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3889 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3890 | const VkImageResolve *pRegions) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3891 | StateTracker::PreCallRecordCmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, |
| 3892 | pRegions); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3893 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3894 | assert(cb_access_context); |
| 3895 | const auto tag = cb_access_context->NextCommandTag(CMD_RESOLVEIMAGE); |
| 3896 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3897 | assert(context); |
| 3898 | |
| 3899 | auto *src_image = Get<IMAGE_STATE>(srcImage); |
| 3900 | auto *dst_image = Get<IMAGE_STATE>(dstImage); |
| 3901 | |
| 3902 | for (uint32_t region = 0; region < regionCount; region++) { |
| 3903 | const auto &resolve_region = pRegions[region]; |
| 3904 | if (src_image) { |
| 3905 | context->UpdateAccessState(*src_image, SYNC_TRANSFER_TRANSFER_READ, resolve_region.srcSubresource, |
| 3906 | resolve_region.srcOffset, resolve_region.extent, tag); |
| 3907 | } |
| 3908 | if (dst_image) { |
| 3909 | context->UpdateAccessState(*dst_image, SYNC_TRANSFER_TRANSFER_WRITE, resolve_region.dstSubresource, |
| 3910 | resolve_region.dstOffset, resolve_region.extent, tag); |
| 3911 | } |
| 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | bool SyncValidator::PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 3916 | VkDeviceSize dataSize, const void *pData) const { |
| 3917 | bool skip = false; |
| 3918 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3919 | assert(cb_access_context); |
| 3920 | if (!cb_access_context) return skip; |
| 3921 | |
| 3922 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3923 | assert(context); |
| 3924 | if (!context) return skip; |
| 3925 | |
| 3926 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3927 | |
| 3928 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3929 | // VK_WHOLE_SIZE not allowed |
| 3930 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3931 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 3932 | if (hazard.hazard) { |
John Zulauf | 1dae919 | 2020-06-16 15:46:44 -0600 | [diff] [blame] | 3933 | skip |= LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3934 | "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] | 3935 | report_data->FormatHandle(dstBuffer).c_str(), string_UsageTag(hazard).c_str()); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3936 | } |
| 3937 | } |
| 3938 | return skip; |
| 3939 | } |
| 3940 | |
| 3941 | void SyncValidator::PreCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 3942 | VkDeviceSize dataSize, const void *pData) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3943 | StateTracker::PreCallRecordCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3944 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3945 | assert(cb_access_context); |
| 3946 | const auto tag = cb_access_context->NextCommandTag(CMD_UPDATEBUFFER); |
| 3947 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3948 | assert(context); |
| 3949 | |
| 3950 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3951 | |
| 3952 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3953 | // VK_WHOLE_SIZE not allowed |
| 3954 | const ResourceAccessRange range = MakeRange(dstOffset, dataSize); |
locke-lunarg | e1a6702 | 2020-04-29 00:15:36 -0600 | [diff] [blame] | 3955 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range, tag); |
| 3956 | } |
| 3957 | } |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3958 | |
| 3959 | bool SyncValidator::PreCallValidateCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 3960 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) const { |
| 3961 | bool skip = false; |
| 3962 | const auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3963 | assert(cb_access_context); |
| 3964 | if (!cb_access_context) return skip; |
| 3965 | |
| 3966 | const auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3967 | assert(context); |
| 3968 | if (!context) return skip; |
| 3969 | |
| 3970 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3971 | |
| 3972 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3973 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3974 | auto hazard = context->DetectHazard(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range); |
| 3975 | if (hazard.hazard) { |
John Zulauf | 59e2507 | 2020-07-17 10:55:21 -0600 | [diff] [blame] | 3976 | skip |= |
| 3977 | LogError(dstBuffer, string_SyncHazardVUID(hazard.hazard), |
| 3978 | "vkCmdWriteBufferMarkerAMD: Hazard %s for dstBuffer %s. Access info %s.", string_SyncHazard(hazard.hazard), |
| 3979 | report_data->FormatHandle(dstBuffer).c_str(), string_UsageTag(hazard).c_str()); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3980 | } |
| 3981 | } |
| 3982 | return skip; |
| 3983 | } |
| 3984 | |
| 3985 | void SyncValidator::PreCallRecordCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 3986 | VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker) { |
locke-lunarg | 8ec1916 | 2020-06-16 18:48:34 -0600 | [diff] [blame] | 3987 | StateTracker::PreCallRecordCmdWriteBufferMarkerAMD(commandBuffer, pipelineStage, dstBuffer, dstOffset, marker); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3988 | auto *cb_access_context = GetAccessContext(commandBuffer); |
| 3989 | assert(cb_access_context); |
| 3990 | const auto tag = cb_access_context->NextCommandTag(CMD_WRITEBUFFERMARKERAMD); |
| 3991 | auto *context = cb_access_context->GetCurrentAccessContext(); |
| 3992 | assert(context); |
| 3993 | |
| 3994 | const auto *dst_buffer = Get<BUFFER_STATE>(dstBuffer); |
| 3995 | |
| 3996 | if (dst_buffer) { |
John Zulauf | 3e86bf0 | 2020-09-12 10:47:57 -0600 | [diff] [blame^] | 3997 | const ResourceAccessRange range = MakeRange(dstOffset, 4); |
locke-lunarg | ff255f9 | 2020-05-13 18:53:52 -0600 | [diff] [blame] | 3998 | context->UpdateAccessState(*dst_buffer, SYNC_TRANSFER_TRANSFER_WRITE, range, tag); |
| 3999 | } |
| 4000 | } |