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