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