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