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