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