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