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