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