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