sfricke-samsung | 486a51e | 2021-01-02 00:10:15 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2021 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2021 Valve Corporation |
| 3 | * Copyright (c) 2015-2021 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2021 Google Inc. |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 5 | * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved. |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * |
| 19 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 20 | * Author: Dave Houlton <daveh@lunarg.com> |
| 21 | * Shannon McPherson <shannon@lunarg.com> |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 22 | * Author: Tobias Hector <tobias.hector@amd.com> |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 23 | */ |
| 24 | |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 25 | #include <algorithm> |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 26 | #include <cmath> |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 27 | |
| 28 | #include "vk_enum_string_helper.h" |
| 29 | #include "vk_format_utils.h" |
| 30 | #include "vk_layer_data.h" |
| 31 | #include "vk_layer_utils.h" |
| 32 | #include "vk_layer_logging.h" |
| 33 | #include "vk_typemap_helper.h" |
| 34 | |
| 35 | #include "chassis.h" |
| 36 | #include "state_tracker.h" |
| 37 | #include "shader_validation.h" |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 38 | #include "sync_utils.h" |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 39 | |
John Zulauf | 890b50b | 2020-06-17 15:18:19 -0600 | [diff] [blame] | 40 | const char *CommandTypeString(CMD_TYPE type) { |
sfricke-samsung | 946027b | 2021-04-20 22:44:36 -0700 | [diff] [blame] | 41 | // Autogenerated as part of the command_validation.h codegen |
Mark Lobodzinski | 677dc0b | 2020-11-12 15:28:09 -0700 | [diff] [blame] | 42 | return kGeneratedCommandNameList[type]; |
John Zulauf | 890b50b | 2020-06-17 15:18:19 -0600 | [diff] [blame] | 43 | } |
| 44 | |
John Zulauf | d0ec59f | 2021-03-13 14:25:08 -0700 | [diff] [blame] | 45 | uint32_t GetSubpassDepthStencilAttachmentIndex(const safe_VkPipelineDepthStencilStateCreateInfo *pipe_ds_ci, |
| 46 | const safe_VkAttachmentReference2 *depth_stencil_ref) { |
| 47 | uint32_t depth_stencil_attachment = VK_ATTACHMENT_UNUSED; |
| 48 | if (pipe_ds_ci && depth_stencil_ref) { |
| 49 | depth_stencil_attachment = depth_stencil_ref->attachment; |
| 50 | } |
| 51 | return depth_stencil_attachment; |
| 52 | } |
| 53 | |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 54 | VkDynamicState ConvertToDynamicState(CBStatusFlagBits flag) { |
| 55 | switch (flag) { |
| 56 | case CBSTATUS_LINE_WIDTH_SET: |
| 57 | return VK_DYNAMIC_STATE_LINE_WIDTH; |
| 58 | case CBSTATUS_DEPTH_BIAS_SET: |
| 59 | return VK_DYNAMIC_STATE_DEPTH_BIAS; |
| 60 | case CBSTATUS_BLEND_CONSTANTS_SET: |
| 61 | return VK_DYNAMIC_STATE_BLEND_CONSTANTS; |
| 62 | case CBSTATUS_DEPTH_BOUNDS_SET: |
| 63 | return VK_DYNAMIC_STATE_DEPTH_BOUNDS; |
| 64 | case CBSTATUS_STENCIL_READ_MASK_SET: |
| 65 | return VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK; |
| 66 | case CBSTATUS_STENCIL_WRITE_MASK_SET: |
| 67 | return VK_DYNAMIC_STATE_STENCIL_WRITE_MASK; |
| 68 | case CBSTATUS_STENCIL_REFERENCE_SET: |
| 69 | return VK_DYNAMIC_STATE_STENCIL_REFERENCE; |
| 70 | case CBSTATUS_VIEWPORT_SET: |
| 71 | return VK_DYNAMIC_STATE_VIEWPORT; |
| 72 | case CBSTATUS_SCISSOR_SET: |
| 73 | return VK_DYNAMIC_STATE_SCISSOR; |
| 74 | case CBSTATUS_EXCLUSIVE_SCISSOR_SET: |
| 75 | return VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV; |
| 76 | case CBSTATUS_SHADING_RATE_PALETTE_SET: |
| 77 | return VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV; |
| 78 | case CBSTATUS_LINE_STIPPLE_SET: |
| 79 | return VK_DYNAMIC_STATE_LINE_STIPPLE_EXT; |
| 80 | case CBSTATUS_VIEWPORT_W_SCALING_SET: |
| 81 | return VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV; |
| 82 | case CBSTATUS_CULL_MODE_SET: |
| 83 | return VK_DYNAMIC_STATE_CULL_MODE_EXT; |
| 84 | case CBSTATUS_FRONT_FACE_SET: |
| 85 | return VK_DYNAMIC_STATE_FRONT_FACE_EXT; |
| 86 | case CBSTATUS_PRIMITIVE_TOPOLOGY_SET: |
| 87 | return VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT; |
| 88 | case CBSTATUS_VIEWPORT_WITH_COUNT_SET: |
| 89 | return VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT; |
| 90 | case CBSTATUS_SCISSOR_WITH_COUNT_SET: |
| 91 | return VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT; |
| 92 | case CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET: |
| 93 | return VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT; |
| 94 | case CBSTATUS_DEPTH_TEST_ENABLE_SET: |
| 95 | return VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT; |
| 96 | case CBSTATUS_DEPTH_WRITE_ENABLE_SET: |
| 97 | return VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT; |
| 98 | case CBSTATUS_DEPTH_COMPARE_OP_SET: |
| 99 | return VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT; |
| 100 | case CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET: |
| 101 | return VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT; |
| 102 | case CBSTATUS_STENCIL_TEST_ENABLE_SET: |
| 103 | return VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT; |
| 104 | case CBSTATUS_STENCIL_OP_SET: |
| 105 | return VK_DYNAMIC_STATE_STENCIL_OP_EXT; |
| 106 | case CBSTATUS_DISCARD_RECTANGLE_SET: |
| 107 | return VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT; |
| 108 | case CBSTATUS_SAMPLE_LOCATIONS_SET: |
| 109 | return VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT; |
| 110 | case CBSTATUS_COARSE_SAMPLE_ORDER_SET: |
| 111 | return VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV; |
Vikram Kushwaha | a57b0c3 | 2021-04-19 12:21:46 -0700 | [diff] [blame] | 112 | case CBSTATUS_PATCH_CONTROL_POINTS_SET: |
| 113 | return VK_DYNAMIC_STATE_PATCH_CONTROL_POINTS_EXT; |
| 114 | case CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET: |
| 115 | return VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE_EXT; |
| 116 | case CBSTATUS_DEPTH_BIAS_ENABLE_SET: |
| 117 | return VK_DYNAMIC_STATE_DEPTH_BIAS_ENABLE_EXT; |
| 118 | case CBSTATUS_LOGIC_OP_SET: |
| 119 | return VK_DYNAMIC_STATE_LOGIC_OP_EXT; |
| 120 | case CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET: |
| 121 | return VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE_EXT; |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 122 | default: |
| 123 | // CBSTATUS_INDEX_BUFFER_BOUND is not in VkDynamicState |
| 124 | return VK_DYNAMIC_STATE_MAX_ENUM; |
| 125 | } |
| 126 | return VK_DYNAMIC_STATE_MAX_ENUM; |
| 127 | } |
| 128 | |
| 129 | CBStatusFlagBits ConvertToCBStatusFlagBits(VkDynamicState state) { |
| 130 | switch (state) { |
| 131 | case VK_DYNAMIC_STATE_VIEWPORT: |
| 132 | return CBSTATUS_VIEWPORT_SET; |
| 133 | case VK_DYNAMIC_STATE_SCISSOR: |
| 134 | return CBSTATUS_SCISSOR_SET; |
| 135 | case VK_DYNAMIC_STATE_LINE_WIDTH: |
| 136 | return CBSTATUS_LINE_WIDTH_SET; |
| 137 | case VK_DYNAMIC_STATE_DEPTH_BIAS: |
| 138 | return CBSTATUS_DEPTH_BIAS_SET; |
| 139 | case VK_DYNAMIC_STATE_BLEND_CONSTANTS: |
| 140 | return CBSTATUS_BLEND_CONSTANTS_SET; |
| 141 | case VK_DYNAMIC_STATE_DEPTH_BOUNDS: |
| 142 | return CBSTATUS_DEPTH_BOUNDS_SET; |
| 143 | case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK: |
| 144 | return CBSTATUS_STENCIL_READ_MASK_SET; |
| 145 | case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK: |
| 146 | return CBSTATUS_STENCIL_WRITE_MASK_SET; |
| 147 | case VK_DYNAMIC_STATE_STENCIL_REFERENCE: |
| 148 | return CBSTATUS_STENCIL_REFERENCE_SET; |
| 149 | case VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV: |
| 150 | return CBSTATUS_VIEWPORT_W_SCALING_SET; |
| 151 | case VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT: |
| 152 | return CBSTATUS_DISCARD_RECTANGLE_SET; |
| 153 | case VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT: |
| 154 | return CBSTATUS_SAMPLE_LOCATIONS_SET; |
| 155 | case VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV: |
| 156 | return CBSTATUS_SHADING_RATE_PALETTE_SET; |
| 157 | case VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV: |
| 158 | return CBSTATUS_COARSE_SAMPLE_ORDER_SET; |
| 159 | case VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV: |
| 160 | return CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
| 161 | case VK_DYNAMIC_STATE_LINE_STIPPLE_EXT: |
| 162 | return CBSTATUS_LINE_STIPPLE_SET; |
| 163 | case VK_DYNAMIC_STATE_CULL_MODE_EXT: |
| 164 | return CBSTATUS_CULL_MODE_SET; |
| 165 | case VK_DYNAMIC_STATE_FRONT_FACE_EXT: |
| 166 | return CBSTATUS_FRONT_FACE_SET; |
| 167 | case VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT: |
| 168 | return CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 169 | case VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT: |
| 170 | return CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
| 171 | case VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT: |
| 172 | return CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 173 | case VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT: |
| 174 | return CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 175 | case VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT: |
| 176 | return CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 177 | case VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT: |
| 178 | return CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 179 | case VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT: |
| 180 | return CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 181 | case VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT: |
| 182 | return CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 183 | case VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT: |
| 184 | return CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 185 | case VK_DYNAMIC_STATE_STENCIL_OP_EXT: |
| 186 | return CBSTATUS_STENCIL_OP_SET; |
Vikram Kushwaha | a57b0c3 | 2021-04-19 12:21:46 -0700 | [diff] [blame] | 187 | case VK_DYNAMIC_STATE_PATCH_CONTROL_POINTS_EXT: |
| 188 | return CBSTATUS_PATCH_CONTROL_POINTS_SET; |
| 189 | case VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE_EXT: |
| 190 | return CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET; |
| 191 | case VK_DYNAMIC_STATE_DEPTH_BIAS_ENABLE_EXT: |
| 192 | return CBSTATUS_DEPTH_BIAS_ENABLE_SET; |
| 193 | case VK_DYNAMIC_STATE_LOGIC_OP_EXT: |
| 194 | return CBSTATUS_LOGIC_OP_SET; |
| 195 | case VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE_EXT: |
| 196 | return CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET; |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 197 | default: |
| 198 | return CBSTATUS_NONE; |
| 199 | } |
| 200 | return CBSTATUS_NONE; |
| 201 | } |
| 202 | |
Mark Lobodzinski | b4ab6ac | 2020-04-02 13:12:06 -0600 | [diff] [blame] | 203 | void ValidationStateTracker::InitDeviceValidationObject(bool add_obj, ValidationObject *inst_obj, ValidationObject *dev_obj) { |
| 204 | if (add_obj) { |
| 205 | instance_state = reinterpret_cast<ValidationStateTracker *>(GetValidationObject(inst_obj->object_dispatch, container_type)); |
| 206 | // Call base class |
| 207 | ValidationObject::InitDeviceValidationObject(add_obj, inst_obj, dev_obj); |
| 208 | } |
| 209 | } |
| 210 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 211 | uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) { |
| 212 | // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS |
| 213 | uint32_t mip_level_count = range->levelCount; |
| 214 | if (range->levelCount == VK_REMAINING_MIP_LEVELS) { |
| 215 | mip_level_count = mip_levels - range->baseMipLevel; |
| 216 | } |
| 217 | return mip_level_count; |
| 218 | } |
| 219 | |
| 220 | uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) { |
| 221 | // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS |
| 222 | uint32_t array_layer_count = range->layerCount; |
| 223 | if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 224 | array_layer_count = layers - range->baseArrayLayer; |
| 225 | } |
| 226 | return array_layer_count; |
| 227 | } |
| 228 | |
| 229 | VkImageSubresourceRange NormalizeSubresourceRange(const VkImageCreateInfo &image_create_info, |
| 230 | const VkImageSubresourceRange &range) { |
| 231 | VkImageSubresourceRange norm = range; |
| 232 | norm.levelCount = ResolveRemainingLevels(&range, image_create_info.mipLevels); |
| 233 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 234 | // Special case for 3D images with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT flag bit, where <extent.depth> and |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 235 | // <arrayLayers> can potentially alias. |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 236 | uint32_t layer_limit = (0 != (image_create_info.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT)) |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 237 | ? image_create_info.extent.depth |
| 238 | : image_create_info.arrayLayers; |
| 239 | norm.layerCount = ResolveRemainingLayers(&range, layer_limit); |
| 240 | |
| 241 | // For multiplanar formats, IMAGE_ASPECT_COLOR is equivalent to adding the aspect of the individual planes |
| 242 | VkImageAspectFlags &aspect_mask = norm.aspectMask; |
| 243 | if (FormatIsMultiplane(image_create_info.format)) { |
| 244 | if (aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 245 | aspect_mask &= ~VK_IMAGE_ASPECT_COLOR_BIT; |
| 246 | aspect_mask |= (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT); |
| 247 | if (FormatPlaneCount(image_create_info.format) > 2) { |
| 248 | aspect_mask |= VK_IMAGE_ASPECT_PLANE_2_BIT; |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | return norm; |
| 253 | } |
| 254 | |
| 255 | VkImageSubresourceRange NormalizeSubresourceRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &range) { |
| 256 | const VkImageCreateInfo &image_create_info = image_state.createInfo; |
| 257 | return NormalizeSubresourceRange(image_create_info, range); |
| 258 | } |
| 259 | |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 260 | // NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS" |
| 261 | // attachments won't persist past the API entry point exit. |
| 262 | std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin, |
| 263 | const FRAMEBUFFER_STATE &fb_state) { |
| 264 | const VkImageView *attachments = fb_state.createInfo.pAttachments; |
| 265 | uint32_t count = fb_state.createInfo.attachmentCount; |
| 266 | if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 267 | const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 268 | if (framebuffer_attachments) { |
| 269 | attachments = framebuffer_attachments->pAttachments; |
| 270 | count = framebuffer_attachments->attachmentCount; |
| 271 | } |
| 272 | } |
| 273 | return std::make_pair(count, attachments); |
| 274 | } |
| 275 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 276 | template <typename ImageViewPointer, typename Get> |
| 277 | std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state, |
| 278 | const Get &get_fn) { |
| 279 | std::vector<ImageViewPointer> views; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 280 | |
| 281 | const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state); |
| 282 | const auto attachment_count = count_attachment.first; |
| 283 | const auto *attachments = count_attachment.second; |
| 284 | views.resize(attachment_count, nullptr); |
| 285 | for (uint32_t i = 0; i < attachment_count; i++) { |
| 286 | if (attachments[i] != VK_NULL_HANDLE) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 287 | views[i] = get_fn(attachments[i]); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | return views; |
| 291 | } |
| 292 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 293 | std::vector<const IMAGE_VIEW_STATE *> ValidationStateTracker::GetAttachmentViews(const VkRenderPassBeginInfo &rp_begin, |
| 294 | const FRAMEBUFFER_STATE &fb_state) const { |
| 295 | auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); }; |
| 296 | return GetAttachmentViewsImpl<const IMAGE_VIEW_STATE *>(rp_begin, fb_state, get_fn); |
| 297 | } |
| 298 | |
| 299 | std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetSharedAttachmentViews( |
| 300 | const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const { |
| 301 | auto get_fn = [this](VkImageView handle) { return this->GetShared<IMAGE_VIEW_STATE>(handle); }; |
| 302 | return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn); |
| 303 | } |
| 304 | |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 305 | std::vector<const IMAGE_VIEW_STATE *> ValidationStateTracker::GetCurrentAttachmentViews(const CMD_BUFFER_STATE &cb_state) const { |
| 306 | // Only valid *after* RecordBeginRenderPass and *before* RecordEndRenderpass as it relies on cb_state for the renderpass info. |
| 307 | std::vector<const IMAGE_VIEW_STATE *> views; |
| 308 | |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 309 | const auto *rp_state = cb_state.activeRenderPass.get(); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 310 | if (!rp_state) return views; |
| 311 | const auto &rp_begin = *cb_state.activeRenderPassBeginInfo.ptr(); |
| 312 | const auto *fb_state = Get<FRAMEBUFFER_STATE>(rp_begin.framebuffer); |
| 313 | if (!fb_state) return views; |
| 314 | |
| 315 | return GetAttachmentViews(rp_begin, *fb_state); |
| 316 | } |
| 317 | |
locke-lunarg | 3e127c7 | 2020-06-09 17:45:28 -0600 | [diff] [blame] | 318 | PIPELINE_STATE *GetCurrentPipelineFromCommandBuffer(const CMD_BUFFER_STATE &cmd, VkPipelineBindPoint pipelineBindPoint) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 319 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 320 | return cmd.lastBound[lv_bind_point].pipeline_state; |
locke-lunarg | 3e127c7 | 2020-06-09 17:45:28 -0600 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(const CMD_BUFFER_STATE &cmd, VkPipelineBindPoint pipelineBindPoint, |
| 324 | const PIPELINE_STATE **rtn_pipe, |
| 325 | const std::vector<LAST_BOUND_STATE::PER_SET> **rtn_sets) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 326 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 327 | const auto &last_bound_it = cmd.lastBound[lv_bind_point]; |
| 328 | if (!last_bound_it.IsUsing()) { |
locke-lunarg | 3e127c7 | 2020-06-09 17:45:28 -0600 | [diff] [blame] | 329 | return; |
| 330 | } |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 331 | *rtn_pipe = last_bound_it.pipeline_state; |
| 332 | *rtn_sets = &(last_bound_it.per_set); |
locke-lunarg | 3e127c7 | 2020-06-09 17:45:28 -0600 | [diff] [blame] | 333 | } |
| 334 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 335 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 336 | // Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR |
| 337 | // This could also move into a seperate core_validation_android.cpp file... ? |
| 338 | |
| 339 | void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 340 | const VkExternalMemoryImageCreateInfo *emici = LvlFindInChain<VkExternalMemoryImageCreateInfo>(create_info->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 341 | if (emici && (emici->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) { |
Spencer Fricke | 224c985 | 2020-04-06 07:47:29 -0700 | [diff] [blame] | 342 | is_node->external_ahb = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 343 | } |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 344 | const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 345 | if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) { |
| 346 | is_node->has_ahb_format = true; |
| 347 | is_node->ahb_format = ext_fmt_android->externalFormat; |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 348 | // VUID 01894 will catch if not found in map |
| 349 | auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat); |
| 350 | if (it != ahb_ext_formats_map.end()) { |
| 351 | is_node->format_features = it->second; |
| 352 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 356 | void ValidationStateTracker::RecordCreateBufferANDROID(const VkBufferCreateInfo *create_info, BUFFER_STATE *bs_node) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 357 | const VkExternalMemoryBufferCreateInfo *embci = LvlFindInChain<VkExternalMemoryBufferCreateInfo>(create_info->pNext); |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 358 | if (embci && (embci->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) { |
| 359 | bs_node->external_ahb = true; |
| 360 | } |
| 361 | } |
| 362 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 363 | void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info, |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 364 | VkSamplerYcbcrConversion ycbcr_conversion, |
| 365 | SAMPLER_YCBCR_CONVERSION_STATE *ycbcr_state) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 366 | const VkExternalFormatANDROID *ext_format_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 367 | if (ext_format_android && (0 != ext_format_android->externalFormat)) { |
| 368 | ycbcr_conversion_ahb_fmt_map.emplace(ycbcr_conversion, ext_format_android->externalFormat); |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 369 | // VUID 01894 will catch if not found in map |
| 370 | auto it = ahb_ext_formats_map.find(ext_format_android->externalFormat); |
| 371 | if (it != ahb_ext_formats_map.end()) { |
| 372 | ycbcr_state->format_features = it->second; |
| 373 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 374 | } |
| 375 | }; |
| 376 | |
| 377 | void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion) { |
| 378 | ycbcr_conversion_ahb_fmt_map.erase(ycbcr_conversion); |
| 379 | }; |
| 380 | |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 381 | void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID( |
| 382 | VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) { |
| 383 | if (VK_SUCCESS != result) return; |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 384 | auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 385 | if (ahb_format_props) { |
Jeremy Gebben | fc6f815 | 2021-03-18 16:58:55 -0600 | [diff] [blame] | 386 | ahb_ext_formats_map.emplace(ahb_format_props->externalFormat, ahb_format_props->formatFeatures); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 390 | #else |
| 391 | |
| 392 | void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) {} |
| 393 | |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 394 | void ValidationStateTracker::RecordCreateBufferANDROID(const VkBufferCreateInfo *create_info, BUFFER_STATE *bs_node) {} |
| 395 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 396 | void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info, |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 397 | VkSamplerYcbcrConversion ycbcr_conversion, |
| 398 | SAMPLER_YCBCR_CONVERSION_STATE *ycbcr_state){}; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 399 | |
| 400 | void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion){}; |
| 401 | |
| 402 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 403 | |
Mark Lobodzinski | d3ec86f | 2020-03-18 11:23:04 -0600 | [diff] [blame] | 404 | std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> GetDslFromPipelineLayout(PIPELINE_LAYOUT_STATE const *layout_data, |
| 405 | uint32_t set) { |
| 406 | std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> dsl = nullptr; |
| 407 | if (layout_data && (set < layout_data->set_layouts.size())) { |
| 408 | dsl = layout_data->set_layouts[set]; |
| 409 | } |
| 410 | return dsl; |
| 411 | } |
| 412 | |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 413 | void AddImageStateProps(IMAGE_STATE &image_state, const VkDevice device, const VkPhysicalDevice physical_device) { |
| 414 | // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features) |
| 415 | // if format is AHB external format then the features are already set |
| 416 | if (image_state.has_ahb_format == false) { |
| 417 | const VkImageTiling image_tiling = image_state.createInfo.tiling; |
| 418 | const VkFormat image_format = image_state.createInfo.format; |
| 419 | if (image_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { |
| 420 | VkImageDrmFormatModifierPropertiesEXT drm_format_properties = { |
| 421 | VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, nullptr}; |
| 422 | DispatchGetImageDrmFormatModifierPropertiesEXT(device, image_state.image, &drm_format_properties); |
| 423 | |
| 424 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr}; |
| 425 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 426 | nullptr}; |
| 427 | format_properties_2.pNext = (void *)&drm_properties_list; |
| 428 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties_2); |
Lionel Landwerlin | 09351a7 | 2020-06-22 18:15:59 +0300 | [diff] [blame] | 429 | std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties; |
| 430 | drm_properties.resize(drm_properties_list.drmFormatModifierCount); |
| 431 | drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0]; |
| 432 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties_2); |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 433 | |
| 434 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 435 | if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == |
| 436 | drm_format_properties.drmFormatModifier) { |
| 437 | image_state.format_features = |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 438 | drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 439 | break; |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | } else { |
| 443 | VkFormatProperties format_properties; |
| 444 | DispatchGetPhysicalDeviceFormatProperties(physical_device, image_format, &format_properties); |
| 445 | image_state.format_features = (image_tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures |
| 446 | : format_properties.optimalTilingFeatures; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 451 | void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, |
| 452 | const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) { |
| 453 | if (VK_SUCCESS != result) return; |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 454 | auto is_node = std::make_shared<IMAGE_STATE>(device, *pImage, pCreateInfo); |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 455 | is_node->disjoint = ((pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT) != 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 456 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
| 457 | RecordCreateImageANDROID(pCreateInfo, is_node.get()); |
| 458 | } |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 459 | const auto swapchain_info = LvlFindInChain<VkImageSwapchainCreateInfoKHR>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 460 | if (swapchain_info) { |
| 461 | is_node->create_from_swapchain = swapchain_info->swapchain; |
| 462 | } |
| 463 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 464 | // Record the memory requirements in case they won't be queried |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 465 | // External AHB memory can't be queried until after memory is bound |
Spencer Fricke | 224c985 | 2020-04-06 07:47:29 -0700 | [diff] [blame] | 466 | if (is_node->external_ahb == false) { |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 467 | if (is_node->disjoint == false) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 468 | DispatchGetImageMemoryRequirements(device, *pImage, &is_node->requirements); |
| 469 | } else { |
| 470 | uint32_t plane_count = FormatPlaneCount(pCreateInfo->format); |
| 471 | VkImagePlaneMemoryRequirementsInfo image_plane_req = {VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO, nullptr}; |
| 472 | VkMemoryRequirements2 mem_reqs2 = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, nullptr}; |
| 473 | VkImageMemoryRequirementsInfo2 mem_req_info2 = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2}; |
| 474 | mem_req_info2.pNext = &image_plane_req; |
| 475 | mem_req_info2.image = *pImage; |
| 476 | |
| 477 | assert(plane_count != 0); // assumes each format has at least first plane |
| 478 | image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_0_BIT; |
| 479 | DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2); |
| 480 | is_node->plane0_requirements = mem_reqs2.memoryRequirements; |
| 481 | |
| 482 | if (plane_count >= 2) { |
| 483 | image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_1_BIT; |
| 484 | DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2); |
| 485 | is_node->plane1_requirements = mem_reqs2.memoryRequirements; |
| 486 | } |
| 487 | if (plane_count >= 3) { |
| 488 | image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_2_BIT; |
| 489 | DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2); |
| 490 | is_node->plane2_requirements = mem_reqs2.memoryRequirements; |
| 491 | } |
| 492 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 493 | } |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 494 | |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 495 | AddImageStateProps(*is_node, device, physical_device); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 496 | |
sfricke-samsung | edce77a | 2020-07-03 22:35:13 -0700 | [diff] [blame] | 497 | is_node->unprotected = ((pCreateInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT) == 0); |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 498 | imageMap.emplace(*pImage, std::move(is_node)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) { |
| 502 | if (!image) return; |
| 503 | IMAGE_STATE *image_state = GetImageState(image); |
| 504 | const VulkanTypedHandle obj_struct(image, kVulkanObjectTypeImage); |
| 505 | InvalidateCommandBuffers(image_state->cb_bindings, obj_struct); |
| 506 | // Clean up memory mapping, bindings and range references for image |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 507 | for (auto *mem_binding : image_state->GetBoundMemory()) { |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 508 | RemoveImageMemoryRange(image_state, mem_binding); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 509 | } |
| 510 | if (image_state->bind_swapchain) { |
| 511 | auto swapchain = GetSwapchainState(image_state->bind_swapchain); |
| 512 | if (swapchain) { |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 513 | swapchain->images[image_state->bind_swapchain_imageIndex].bound_images.erase(image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | RemoveAliasingImage(image_state); |
| 517 | ClearMemoryObjectBindings(obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 518 | image_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 519 | // Remove image from imageMap |
| 520 | imageMap.erase(image); |
| 521 | } |
| 522 | |
| 523 | void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, |
| 524 | VkImageLayout imageLayout, const VkClearColorValue *pColor, |
| 525 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 526 | auto cb_node = GetCBState(commandBuffer); |
| 527 | auto image_state = GetImageState(image); |
| 528 | if (cb_node && image_state) { |
| 529 | AddCommandBufferBindingImage(cb_node, image_state); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 534 | VkImageLayout imageLayout, |
| 535 | const VkClearDepthStencilValue *pDepthStencil, |
| 536 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 537 | auto cb_node = GetCBState(commandBuffer); |
| 538 | auto image_state = GetImageState(image); |
| 539 | if (cb_node && image_state) { |
| 540 | AddCommandBufferBindingImage(cb_node, image_state); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 545 | VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 546 | uint32_t regionCount, const VkImageCopy *pRegions) { |
| 547 | auto cb_node = GetCBState(commandBuffer); |
| 548 | auto src_image_state = GetImageState(srcImage); |
| 549 | auto dst_image_state = GetImageState(dstImage); |
| 550 | |
| 551 | // Update bindings between images and cmd buffer |
| 552 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 553 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 554 | } |
| 555 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 556 | void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 557 | const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 558 | auto cb_node = GetCBState(commandBuffer); |
| 559 | auto src_image_state = GetImageState(pCopyImageInfo->srcImage); |
| 560 | auto dst_image_state = GetImageState(pCopyImageInfo->dstImage); |
| 561 | |
| 562 | // Update bindings between images and cmd buffer |
| 563 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 564 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 565 | } |
| 566 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 567 | void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 568 | VkImageLayout srcImageLayout, VkImage dstImage, |
| 569 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 570 | const VkImageResolve *pRegions) { |
| 571 | auto cb_node = GetCBState(commandBuffer); |
| 572 | auto src_image_state = GetImageState(srcImage); |
| 573 | auto dst_image_state = GetImageState(dstImage); |
| 574 | |
| 575 | // Update bindings between images and cmd buffer |
| 576 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 577 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 578 | } |
| 579 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 580 | void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 581 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 582 | auto cb_node = GetCBState(commandBuffer); |
| 583 | auto src_image_state = GetImageState(pResolveImageInfo->srcImage); |
| 584 | auto dst_image_state = GetImageState(pResolveImageInfo->dstImage); |
| 585 | |
| 586 | // Update bindings between images and cmd buffer |
| 587 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 588 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 589 | } |
| 590 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 591 | void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 592 | VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 593 | uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) { |
| 594 | auto cb_node = GetCBState(commandBuffer); |
| 595 | auto src_image_state = GetImageState(srcImage); |
| 596 | auto dst_image_state = GetImageState(dstImage); |
| 597 | |
| 598 | // Update bindings between images and cmd buffer |
| 599 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 600 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 601 | } |
| 602 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 603 | void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 604 | const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 605 | auto cb_node = GetCBState(commandBuffer); |
| 606 | auto src_image_state = GetImageState(pBlitImageInfo->srcImage); |
| 607 | auto dst_image_state = GetImageState(pBlitImageInfo->dstImage); |
| 608 | |
| 609 | // Update bindings between images and cmd buffer |
| 610 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 611 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 612 | } |
| 613 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 614 | void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, |
| 615 | const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer, |
| 616 | VkResult result) { |
| 617 | if (result != VK_SUCCESS) return; |
| 618 | // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 619 | auto buffer_state = std::make_shared<BUFFER_STATE>(*pBuffer, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 620 | |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 621 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
| 622 | RecordCreateBufferANDROID(pCreateInfo, buffer_state.get()); |
| 623 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 624 | // Get a set of requirements in the case the app does not |
sfricke-samsung | ad90e72 | 2020-07-08 20:54:24 -0700 | [diff] [blame] | 625 | DispatchGetBufferMemoryRequirements(device, *pBuffer, &buffer_state->requirements); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 626 | |
sfricke-samsung | edce77a | 2020-07-03 22:35:13 -0700 | [diff] [blame] | 627 | buffer_state->unprotected = ((pCreateInfo->flags & VK_BUFFER_CREATE_PROTECTED_BIT) == 0); |
| 628 | |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 629 | bufferMap.emplace(*pBuffer, std::move(buffer_state)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo, |
| 633 | const VkAllocationCallbacks *pAllocator, VkBufferView *pView, |
| 634 | VkResult result) { |
| 635 | if (result != VK_SUCCESS) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 636 | auto buffer_state = GetBufferShared(pCreateInfo->buffer); |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 637 | auto buffer_view_state = std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo); |
| 638 | |
| 639 | VkFormatProperties format_properties; |
| 640 | DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties); |
| 641 | buffer_view_state->format_features = format_properties.bufferFeatures; |
| 642 | |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 643 | bufferViewMap.emplace(*pView, std::move(buffer_view_state)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, |
| 647 | const VkAllocationCallbacks *pAllocator, VkImageView *pView, |
| 648 | VkResult result) { |
| 649 | if (result != VK_SUCCESS) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 650 | auto image_state = GetImageShared(pCreateInfo->image); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 651 | auto image_view_state = std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo); |
| 652 | |
| 653 | // Add feature support according to Image View Format Features (vkspec.html#resources-image-view-format-features) |
| 654 | const VkImageTiling image_tiling = image_state->createInfo.tiling; |
| 655 | const VkFormat image_view_format = pCreateInfo->format; |
| 656 | if (image_state->has_ahb_format == true) { |
| 657 | // The ImageView uses same Image's format feature since they share same AHB |
| 658 | image_view_state->format_features = image_state->format_features; |
| 659 | } else if (image_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { |
| 660 | // Parameter validation should catch if this is used without VK_EXT_image_drm_format_modifier |
| 661 | assert(device_extensions.vk_ext_image_drm_format_modifier); |
| 662 | VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, |
| 663 | nullptr}; |
| 664 | DispatchGetImageDrmFormatModifierPropertiesEXT(device, image_state->image, &drm_format_properties); |
| 665 | |
| 666 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr}; |
| 667 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 668 | nullptr}; |
| 669 | format_properties_2.pNext = (void *)&drm_properties_list; |
nyorain | 38a9d23 | 2021-03-06 13:06:12 +0100 | [diff] [blame] | 670 | |
| 671 | // First call is to get the number of modifiers compatible with the queried format |
| 672 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_view_format, &format_properties_2); |
| 673 | |
| 674 | std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties; |
| 675 | drm_properties.resize(drm_properties_list.drmFormatModifierCount); |
| 676 | drm_properties_list.pDrmFormatModifierProperties = drm_properties.data(); |
| 677 | |
| 678 | // Second call, now with an allocated array in pDrmFormatModifierProperties, is to get the modifiers |
| 679 | // compatible with the queried format |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 680 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_view_format, &format_properties_2); |
| 681 | |
| 682 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 683 | if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) { |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 684 | image_view_state->format_features |= |
| 685 | drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 686 | break; |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | } else { |
| 690 | VkFormatProperties format_properties; |
| 691 | DispatchGetPhysicalDeviceFormatProperties(physical_device, image_view_format, &format_properties); |
| 692 | image_view_state->format_features = (image_tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures |
| 693 | : format_properties.optimalTilingFeatures; |
| 694 | } |
| 695 | |
sfricke-samsung | d23f6e6 | 2021-01-17 09:05:47 -0800 | [diff] [blame] | 696 | auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext); |
| 697 | image_view_state->inherited_usage = (usage_create_info) ? usage_create_info->usage : image_state->createInfo.usage; |
| 698 | |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 699 | // filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw. |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 700 | image_view_state->filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>(); |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 701 | if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) { |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 702 | auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>(); |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 703 | imageview_format_info.imageViewType = pCreateInfo->viewType; |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 704 | auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info); |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 705 | image_format_info.type = image_state->createInfo.imageType; |
| 706 | image_format_info.format = image_state->createInfo.format; |
| 707 | image_format_info.tiling = image_state->createInfo.tiling; |
sfricke-samsung | d23f6e6 | 2021-01-17 09:05:47 -0800 | [diff] [blame] | 708 | image_format_info.usage = image_view_state->inherited_usage; |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 709 | image_format_info.flags = image_state->createInfo.flags; |
| 710 | |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 711 | auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&image_view_state->filter_cubic_props); |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 712 | |
| 713 | DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties); |
| 714 | } |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 715 | imageViewMap.emplace(*pView, std::move(image_view_state)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 719 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
| 720 | auto cb_node = GetCBState(commandBuffer); |
| 721 | auto src_buffer_state = GetBufferState(srcBuffer); |
| 722 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 723 | |
| 724 | // Update bindings between buffers and cmd buffer |
| 725 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 726 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 727 | } |
| 728 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 729 | void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 730 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 731 | auto cb_node = GetCBState(commandBuffer); |
| 732 | auto src_buffer_state = GetBufferState(pCopyBufferInfos->srcBuffer); |
| 733 | auto dst_buffer_state = GetBufferState(pCopyBufferInfos->dstBuffer); |
| 734 | |
| 735 | // Update bindings between buffers and cmd buffer |
| 736 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 737 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 738 | } |
| 739 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 740 | void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView, |
| 741 | const VkAllocationCallbacks *pAllocator) { |
| 742 | IMAGE_VIEW_STATE *image_view_state = GetImageViewState(imageView); |
| 743 | if (!image_view_state) return; |
| 744 | const VulkanTypedHandle obj_struct(imageView, kVulkanObjectTypeImageView); |
| 745 | |
| 746 | // Any bound cmd buffers are now invalid |
| 747 | InvalidateCommandBuffers(image_view_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 748 | image_view_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 749 | imageViewMap.erase(imageView); |
| 750 | } |
| 751 | |
| 752 | void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) { |
| 753 | if (!buffer) return; |
| 754 | auto buffer_state = GetBufferState(buffer); |
| 755 | const VulkanTypedHandle obj_struct(buffer, kVulkanObjectTypeBuffer); |
| 756 | |
| 757 | InvalidateCommandBuffers(buffer_state->cb_bindings, obj_struct); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 758 | ClearMemoryObjectBindings(obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 759 | buffer_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 760 | bufferMap.erase(buffer_state->buffer); |
| 761 | } |
| 762 | |
| 763 | void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView, |
| 764 | const VkAllocationCallbacks *pAllocator) { |
| 765 | if (!bufferView) return; |
| 766 | auto buffer_view_state = GetBufferViewState(bufferView); |
| 767 | const VulkanTypedHandle obj_struct(bufferView, kVulkanObjectTypeBufferView); |
| 768 | |
| 769 | // Any bound cmd buffers are now invalid |
| 770 | InvalidateCommandBuffers(buffer_view_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 771 | buffer_view_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 772 | bufferViewMap.erase(bufferView); |
| 773 | } |
| 774 | |
| 775 | void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 776 | VkDeviceSize size, uint32_t data) { |
| 777 | auto cb_node = GetCBState(commandBuffer); |
| 778 | auto buffer_state = GetBufferState(dstBuffer); |
| 779 | // Update bindings between buffer and cmd buffer |
| 780 | AddCommandBufferBindingBuffer(cb_node, buffer_state); |
| 781 | } |
| 782 | |
| 783 | void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 784 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, |
| 785 | uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 786 | auto cb_node = GetCBState(commandBuffer); |
| 787 | auto src_image_state = GetImageState(srcImage); |
| 788 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 789 | |
| 790 | // Update bindings between buffer/image and cmd buffer |
| 791 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 792 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 793 | } |
| 794 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 795 | void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 796 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 797 | auto cb_node = GetCBState(commandBuffer); |
| 798 | auto src_image_state = GetImageState(pCopyImageToBufferInfo->srcImage); |
| 799 | auto dst_buffer_state = GetBufferState(pCopyImageToBufferInfo->dstBuffer); |
| 800 | |
| 801 | // Update bindings between buffer/image and cmd buffer |
| 802 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 803 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 804 | } |
| 805 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 806 | void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 807 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 808 | const VkBufferImageCopy *pRegions) { |
| 809 | auto cb_node = GetCBState(commandBuffer); |
| 810 | auto src_buffer_state = GetBufferState(srcBuffer); |
| 811 | auto dst_image_state = GetImageState(dstImage); |
| 812 | |
| 813 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 814 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 815 | } |
| 816 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 817 | void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 818 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 819 | auto cb_node = GetCBState(commandBuffer); |
| 820 | auto src_buffer_state = GetBufferState(pCopyBufferToImageInfo->srcBuffer); |
| 821 | auto dst_image_state = GetImageState(pCopyBufferToImageInfo->dstImage); |
| 822 | |
| 823 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 824 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 825 | } |
| 826 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 827 | // Get the image viewstate for a given framebuffer attachment |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 828 | IMAGE_VIEW_STATE *ValidationStateTracker::GetActiveAttachmentImageViewState(const CMD_BUFFER_STATE *cb, uint32_t index, |
| 829 | const CMD_BUFFER_STATE *primary_cb) { |
| 830 | if (primary_cb) { |
| 831 | assert(primary_cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < primary_cb->active_attachments->size())); |
| 832 | return primary_cb->active_attachments->at(index); |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 833 | } |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 834 | assert(cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < cb->active_attachments->size())); |
| 835 | return cb->active_attachments->at(index); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | // Get the image viewstate for a given framebuffer attachment |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 839 | const IMAGE_VIEW_STATE *ValidationStateTracker::GetActiveAttachmentImageViewState(const CMD_BUFFER_STATE *cb, uint32_t index, |
| 840 | const CMD_BUFFER_STATE *primary_cb) const { |
| 841 | if (primary_cb) { |
| 842 | assert(primary_cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < primary_cb->active_attachments->size())); |
| 843 | return primary_cb->active_attachments->at(index); |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 844 | } |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 845 | assert(cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < cb->active_attachments->size())); |
| 846 | return cb->active_attachments->at(index); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 847 | } |
| 848 | |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 849 | void ValidationStateTracker::AddAliasingImage(IMAGE_STATE *image_state, layer_data::unordered_set<IMAGE_STATE *> *bound_images) { |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 850 | assert(bound_images); |
| 851 | for (auto *bound_image : *bound_images) { |
| 852 | if (bound_image && (bound_image != image_state) && bound_image->IsCompatibleAliasing(image_state)) { |
| 853 | auto inserted = bound_image->aliasing_images.emplace(image_state); |
| 854 | if (inserted.second) { |
| 855 | image_state->aliasing_images.emplace(bound_image); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | void ValidationStateTracker::RemoveAliasingImage(IMAGE_STATE *image_state) { |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 862 | for (auto *alias_state : image_state->aliasing_images) { |
| 863 | assert(alias_state); |
| 864 | alias_state->aliasing_images.erase(image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 865 | } |
| 866 | image_state->aliasing_images.clear(); |
| 867 | } |
| 868 | |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 869 | void ValidationStateTracker::RemoveAliasingImages(const layer_data::unordered_set<IMAGE_STATE *> &bound_images) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 870 | // This is one way clear. Because the bound_images include cross references, the one way clear loop could clear the whole |
| 871 | // reference. It doesn't need two ways clear. |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 872 | for (auto *bound_image : bound_images) { |
| 873 | if (bound_image) { |
| 874 | bound_image->aliasing_images.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | } |
| 878 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 879 | const QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) const { |
| 880 | auto it = queueMap.find(queue); |
| 881 | if (it == queueMap.cend()) { |
| 882 | return nullptr; |
| 883 | } |
| 884 | return &it->second; |
| 885 | } |
| 886 | |
| 887 | QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) { |
| 888 | auto it = queueMap.find(queue); |
| 889 | if (it == queueMap.end()) { |
| 890 | return nullptr; |
| 891 | } |
| 892 | return &it->second; |
| 893 | } |
| 894 | |
| 895 | const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) const { |
| 896 | auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map); |
| 897 | auto it = phys_dev_map->find(phys); |
| 898 | if (it == phys_dev_map->end()) { |
| 899 | return nullptr; |
| 900 | } |
| 901 | return &it->second; |
| 902 | } |
| 903 | |
| 904 | PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) { |
| 905 | auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map); |
| 906 | auto it = phys_dev_map->find(phys); |
| 907 | if (it == phys_dev_map->end()) { |
| 908 | return nullptr; |
| 909 | } |
| 910 | return &it->second; |
| 911 | } |
| 912 | |
| 913 | PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() { return physical_device_state; } |
| 914 | const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() const { return physical_device_state; } |
| 915 | |
| 916 | // Return ptr to memory binding for given handle of specified type |
| 917 | template <typename State, typename Result> |
| 918 | static Result GetObjectMemBindingImpl(State state, const VulkanTypedHandle &typed_handle) { |
| 919 | switch (typed_handle.type) { |
| 920 | case kVulkanObjectTypeImage: |
| 921 | return state->GetImageState(typed_handle.Cast<VkImage>()); |
| 922 | case kVulkanObjectTypeBuffer: |
| 923 | return state->GetBufferState(typed_handle.Cast<VkBuffer>()); |
| 924 | case kVulkanObjectTypeAccelerationStructureNV: |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 925 | return state->GetAccelerationStructureStateNV(typed_handle.Cast<VkAccelerationStructureNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 926 | default: |
| 927 | break; |
| 928 | } |
| 929 | return nullptr; |
| 930 | } |
| 931 | |
| 932 | const BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) const { |
| 933 | return GetObjectMemBindingImpl<const ValidationStateTracker *, const BINDABLE *>(this, typed_handle); |
| 934 | } |
| 935 | |
| 936 | BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) { |
| 937 | return GetObjectMemBindingImpl<ValidationStateTracker *, BINDABLE *>(this, typed_handle); |
| 938 | } |
| 939 | |
| 940 | void ValidationStateTracker::AddMemObjInfo(void *object, const VkDeviceMemory mem, const VkMemoryAllocateInfo *pAllocateInfo) { |
| 941 | assert(object != NULL); |
| 942 | |
John Zulauf | 7995271 | 2020-04-07 11:25:54 -0600 | [diff] [blame] | 943 | auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize); |
| 944 | memObjMap[mem] = std::make_shared<DEVICE_MEMORY_STATE>(object, mem, pAllocateInfo, fake_address); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 945 | auto mem_info = memObjMap[mem].get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 946 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 947 | auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 948 | if (dedicated) { |
| 949 | mem_info->is_dedicated = true; |
| 950 | mem_info->dedicated_buffer = dedicated->buffer; |
| 951 | mem_info->dedicated_image = dedicated->image; |
| 952 | } |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 953 | auto export_info = LvlFindInChain<VkExportMemoryAllocateInfo>(pAllocateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 954 | if (export_info) { |
| 955 | mem_info->is_export = true; |
| 956 | mem_info->export_handle_type_flags = export_info->handleTypes; |
| 957 | } |
sfricke-samsung | 2306827 | 2020-06-21 14:49:51 -0700 | [diff] [blame] | 958 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 959 | auto alloc_flags = LvlFindInChain<VkMemoryAllocateFlagsInfo>(pAllocateInfo->pNext); |
Mark Lobodzinski | 7bda6ed | 2020-07-24 09:57:38 -0600 | [diff] [blame] | 960 | if (alloc_flags) { |
| 961 | auto dev_mask = alloc_flags->deviceMask; |
| 962 | if ((dev_mask != 0) && (dev_mask & (dev_mask - 1))) { |
| 963 | mem_info->multi_instance = true; |
| 964 | } |
| 965 | } |
| 966 | auto heap_index = phys_dev_mem_props.memoryTypes[mem_info->alloc_info.memoryTypeIndex].heapIndex; |
Tony-LunarG | b399fb0 | 2020-08-06 14:20:59 -0600 | [diff] [blame] | 967 | mem_info->multi_instance |= (((phys_dev_mem_props.memoryHeaps[heap_index].flags & VK_MEMORY_HEAP_MULTI_INSTANCE_BIT) != 0) && |
| 968 | physical_device_count > 1); |
Mark Lobodzinski | 7bda6ed | 2020-07-24 09:57:38 -0600 | [diff] [blame] | 969 | |
sfricke-samsung | 2306827 | 2020-06-21 14:49:51 -0700 | [diff] [blame] | 970 | // Assumes validation already for only a single import operation in the pNext |
| 971 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 972 | auto win32_import = LvlFindInChain<VkImportMemoryWin32HandleInfoKHR>(pAllocateInfo->pNext); |
sfricke-samsung | 2306827 | 2020-06-21 14:49:51 -0700 | [diff] [blame] | 973 | if (win32_import) { |
| 974 | mem_info->is_import = true; |
| 975 | mem_info->import_handle_type_flags = win32_import->handleType; |
| 976 | } |
| 977 | #endif |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 978 | auto fd_import = LvlFindInChain<VkImportMemoryFdInfoKHR>(pAllocateInfo->pNext); |
sfricke-samsung | 2306827 | 2020-06-21 14:49:51 -0700 | [diff] [blame] | 979 | if (fd_import) { |
| 980 | mem_info->is_import = true; |
| 981 | mem_info->import_handle_type_flags = fd_import->handleType; |
| 982 | } |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 983 | auto host_pointer_import = LvlFindInChain<VkImportMemoryHostPointerInfoEXT>(pAllocateInfo->pNext); |
sfricke-samsung | 2306827 | 2020-06-21 14:49:51 -0700 | [diff] [blame] | 984 | if (host_pointer_import) { |
| 985 | mem_info->is_import = true; |
| 986 | mem_info->import_handle_type_flags = host_pointer_import->handleType; |
| 987 | } |
| 988 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 989 | // AHB Import doesn't have handle in the pNext struct |
| 990 | // It should be assumed that all imported AHB can only have the same, single handleType |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 991 | auto ahb_import = LvlFindInChain<VkImportAndroidHardwareBufferInfoANDROID>(pAllocateInfo->pNext); |
sfricke-samsung | 2306827 | 2020-06-21 14:49:51 -0700 | [diff] [blame] | 992 | if ((ahb_import) && (ahb_import->buffer != nullptr)) { |
| 993 | mem_info->is_import_ahb = true; |
| 994 | mem_info->is_import = true; |
| 995 | mem_info->import_handle_type_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID; |
| 996 | } |
sfricke-samsung | 98acb88 | 2020-11-03 19:16:10 -0800 | [diff] [blame] | 997 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
sfricke-samsung | edce77a | 2020-07-03 22:35:13 -0700 | [diff] [blame] | 998 | |
| 999 | const VkMemoryType memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex]; |
| 1000 | mem_info->unprotected = ((memory_type.propertyFlags & VK_MEMORY_PROPERTY_PROTECTED_BIT) == 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | // Create binding link between given sampler and command buffer node |
| 1004 | void ValidationStateTracker::AddCommandBufferBindingSampler(CMD_BUFFER_STATE *cb_node, SAMPLER_STATE *sampler_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1005 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1006 | return; |
| 1007 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1008 | AddCommandBufferBinding(sampler_state->cb_bindings, |
| 1009 | VulkanTypedHandle(sampler_state->sampler, kVulkanObjectTypeSampler, sampler_state), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | // Create binding link between given image node and command buffer node |
| 1013 | void ValidationStateTracker::AddCommandBufferBindingImage(CMD_BUFFER_STATE *cb_node, IMAGE_STATE *image_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1014 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1015 | return; |
| 1016 | } |
| 1017 | // Skip validation if this image was created through WSI |
| 1018 | if (image_state->create_from_swapchain == VK_NULL_HANDLE) { |
| 1019 | // First update cb binding for image |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1020 | if (AddCommandBufferBinding(image_state->cb_bindings, |
| 1021 | VulkanTypedHandle(image_state->image, kVulkanObjectTypeImage, image_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1022 | // Now update CB binding in MemObj mini CB list |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1023 | for (auto *mem_binding : image_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1024 | // Now update CBInfo's Mem reference list |
| 1025 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 1026 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | // Create binding link between given image view node and its image with command buffer node |
| 1033 | void ValidationStateTracker::AddCommandBufferBindingImageView(CMD_BUFFER_STATE *cb_node, IMAGE_VIEW_STATE *view_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1034 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1035 | return; |
| 1036 | } |
| 1037 | // First add bindings for imageView |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1038 | if (AddCommandBufferBinding(view_state->cb_bindings, |
| 1039 | VulkanTypedHandle(view_state->image_view, kVulkanObjectTypeImageView, view_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1040 | // Only need to continue if this is a new item |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1041 | auto image_state = view_state->image_state.get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1042 | // Add bindings for image within imageView |
| 1043 | if (image_state) { |
| 1044 | AddCommandBufferBindingImage(cb_node, image_state); |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | // Create binding link between given buffer node and command buffer node |
| 1050 | void ValidationStateTracker::AddCommandBufferBindingBuffer(CMD_BUFFER_STATE *cb_node, BUFFER_STATE *buffer_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1051 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1052 | return; |
| 1053 | } |
| 1054 | // First update cb binding for buffer |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1055 | if (AddCommandBufferBinding(buffer_state->cb_bindings, |
| 1056 | VulkanTypedHandle(buffer_state->buffer, kVulkanObjectTypeBuffer, buffer_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1057 | // Now update CB binding in MemObj mini CB list |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1058 | for (auto *mem_binding : buffer_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1059 | // Now update CBInfo's Mem reference list |
| 1060 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 1061 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | // Create binding link between given buffer view node and its buffer with command buffer node |
| 1067 | void ValidationStateTracker::AddCommandBufferBindingBufferView(CMD_BUFFER_STATE *cb_node, BUFFER_VIEW_STATE *view_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1068 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1069 | return; |
| 1070 | } |
| 1071 | // First add bindings for bufferView |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1072 | if (AddCommandBufferBinding(view_state->cb_bindings, |
| 1073 | VulkanTypedHandle(view_state->buffer_view, kVulkanObjectTypeBufferView, view_state), cb_node)) { |
| 1074 | auto buffer_state = view_state->buffer_state.get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1075 | // Add bindings for buffer within bufferView |
| 1076 | if (buffer_state) { |
| 1077 | AddCommandBufferBindingBuffer(cb_node, buffer_state); |
| 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | // Create binding link between given acceleration structure and command buffer node |
| 1083 | void ValidationStateTracker::AddCommandBufferBindingAccelerationStructure(CMD_BUFFER_STATE *cb_node, |
| 1084 | ACCELERATION_STRUCTURE_STATE *as_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1085 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1086 | return; |
| 1087 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1088 | if (AddCommandBufferBinding( |
| 1089 | as_state->cb_bindings, |
| 1090 | VulkanTypedHandle(as_state->acceleration_structure, kVulkanObjectTypeAccelerationStructureNV, as_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1091 | // Now update CB binding in MemObj mini CB list |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1092 | for (auto *mem_binding : as_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1093 | // Now update CBInfo's Mem reference list |
| 1094 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 1095 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | } |
| 1099 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1100 | // Create binding link between given acceleration structure and command buffer node |
| 1101 | void ValidationStateTracker::AddCommandBufferBindingAccelerationStructure(CMD_BUFFER_STATE *cb_node, |
| 1102 | ACCELERATION_STRUCTURE_STATE_KHR *as_state) { |
| 1103 | if (disabled[command_buffer_state]) { |
| 1104 | return; |
| 1105 | } |
| 1106 | if (AddCommandBufferBinding( |
| 1107 | as_state->cb_bindings, |
| 1108 | VulkanTypedHandle(as_state->acceleration_structure, kVulkanObjectTypeAccelerationStructureKHR, as_state), cb_node)) { |
| 1109 | // Now update CB binding in MemObj mini CB list |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1110 | for (auto *mem_binding : as_state->GetBoundMemory()) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1111 | // Now update CBInfo's Mem reference list |
| 1112 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 1113 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1118 | // Clear a single object binding from given memory object |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 1119 | void ValidationStateTracker::ClearMemoryObjectBinding(const VulkanTypedHandle &typed_handle, DEVICE_MEMORY_STATE *mem_info) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1120 | // This obj is bound to a memory object. Remove the reference to this object in that memory object's list |
| 1121 | if (mem_info) { |
| 1122 | mem_info->obj_bindings.erase(typed_handle); |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | // ClearMemoryObjectBindings clears the binding of objects to memory |
| 1127 | // For the given object it pulls the memory bindings and makes sure that the bindings |
| 1128 | // no longer refer to the object being cleared. This occurs when objects are destroyed. |
| 1129 | void ValidationStateTracker::ClearMemoryObjectBindings(const VulkanTypedHandle &typed_handle) { |
| 1130 | BINDABLE *mem_binding = GetObjectMemBinding(typed_handle); |
| 1131 | if (mem_binding) { |
| 1132 | if (!mem_binding->sparse) { |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 1133 | ClearMemoryObjectBinding(typed_handle, mem_binding->binding.mem_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1134 | } else { // Sparse, clear all bindings |
| 1135 | for (auto &sparse_mem_binding : mem_binding->sparse_bindings) { |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 1136 | ClearMemoryObjectBinding(typed_handle, sparse_mem_binding.mem_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | // SetMemBinding is used to establish immutable, non-sparse binding between a single image/buffer object and memory object. |
| 1143 | // Corresponding valid usage checks are in ValidateSetMemBinding(). |
| 1144 | void ValidationStateTracker::SetMemBinding(VkDeviceMemory mem, BINDABLE *mem_binding, VkDeviceSize memory_offset, |
| 1145 | const VulkanTypedHandle &typed_handle) { |
| 1146 | assert(mem_binding); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1147 | |
| 1148 | if (mem != VK_NULL_HANDLE) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1149 | mem_binding->binding.mem_state = GetShared<DEVICE_MEMORY_STATE>(mem); |
| 1150 | if (mem_binding->binding.mem_state) { |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 1151 | mem_binding->binding.offset = memory_offset; |
| 1152 | mem_binding->binding.size = mem_binding->requirements.size; |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1153 | mem_binding->binding.mem_state->obj_bindings.insert(typed_handle); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1154 | // For image objects, make sure default memory state is correctly set |
| 1155 | // TODO : What's the best/correct way to handle this? |
| 1156 | if (kVulkanObjectTypeImage == typed_handle.type) { |
| 1157 | auto const image_state = reinterpret_cast<const IMAGE_STATE *>(mem_binding); |
| 1158 | if (image_state) { |
| 1159 | VkImageCreateInfo ici = image_state->createInfo; |
| 1160 | if (ici.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) { |
| 1161 | // TODO:: More memory state transition stuff. |
| 1162 | } |
| 1163 | } |
| 1164 | } |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1165 | mem_binding->UpdateBoundMemorySet(); // force recreation of cached set |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | // For NULL mem case, clear any previous binding Else... |
| 1171 | // Make sure given object is in its object map |
| 1172 | // IF a previous binding existed, update binding |
| 1173 | // Add reference from objectInfo to memoryInfo |
| 1174 | // Add reference off of object's binding info |
| 1175 | // Return VK_TRUE if addition is successful, VK_FALSE otherwise |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1176 | bool ValidationStateTracker::SetSparseMemBinding(const VkDeviceMemory mem, const VkDeviceSize mem_offset, |
| 1177 | const VkDeviceSize mem_size, const VulkanTypedHandle &typed_handle) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1178 | bool skip = VK_FALSE; |
| 1179 | // Handle NULL case separately, just clear previous binding & decrement reference |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1180 | if (mem == VK_NULL_HANDLE) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1181 | // TODO : This should cause the range of the resource to be unbound according to spec |
| 1182 | } else { |
| 1183 | BINDABLE *mem_binding = GetObjectMemBinding(typed_handle); |
| 1184 | assert(mem_binding); |
| 1185 | if (mem_binding) { // Invalid handles are reported by object tracker, but Get returns NULL for them, so avoid SEGV here |
| 1186 | assert(mem_binding->sparse); |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1187 | MEM_BINDING binding = {GetShared<DEVICE_MEMORY_STATE>(mem), mem_offset, mem_size}; |
| 1188 | if (binding.mem_state) { |
| 1189 | binding.mem_state->obj_bindings.insert(typed_handle); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1190 | // Need to set mem binding for this object |
| 1191 | mem_binding->sparse_bindings.insert(binding); |
| 1192 | mem_binding->UpdateBoundMemorySet(); |
| 1193 | } |
| 1194 | } |
| 1195 | } |
| 1196 | return skip; |
| 1197 | } |
| 1198 | |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1199 | void ValidationStateTracker::UpdateDrawState(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, const VkPipelineBindPoint bind_point, |
| 1200 | const char *function) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1201 | const auto lv_bind_point = ConvertToLvlBindPoint(bind_point); |
| 1202 | auto &state = cb_state->lastBound[lv_bind_point]; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1203 | PIPELINE_STATE *pipe = state.pipeline_state; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1204 | if (VK_NULL_HANDLE != state.pipeline_layout) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1205 | for (const auto &set_binding_pair : pipe->active_slots) { |
| 1206 | uint32_t set_index = set_binding_pair.first; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1207 | // Pull the set node |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1208 | cvdescriptorset::DescriptorSet *descriptor_set = state.per_set[set_index].bound_descriptor_set; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1209 | |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1210 | // For the "bindless" style resource usage with many descriptors, need to optimize command <-> descriptor binding |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1211 | |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1212 | // TODO: If recreating the reduced_map here shows up in profilinging, need to find a way of sharing with the |
| 1213 | // Validate pass. Though in the case of "many" descriptors, typically the descriptor count >> binding count |
| 1214 | cvdescriptorset::PrefilterBindRequestMap reduced_map(*descriptor_set, set_binding_pair.second); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1215 | const auto &binding_req_map = reduced_map.FilteredMap(*cb_state, *pipe); |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1216 | |
| 1217 | if (reduced_map.IsManyDescriptors()) { |
| 1218 | // Only update validate binding tags if we meet the "many" criteria in the Prefilter class |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1219 | descriptor_set->UpdateValidationCache(*cb_state, *pipe, binding_req_map); |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | // We can skip updating the state if "nothing" has changed since the last validation. |
| 1223 | // See CoreChecks::ValidateCmdBufDrawState for more details. |
| 1224 | bool descriptor_set_changed = |
| 1225 | !reduced_map.IsManyDescriptors() || |
| 1226 | // Update if descriptor set (or contents) has changed |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1227 | state.per_set[set_index].validated_set != descriptor_set || |
| 1228 | state.per_set[set_index].validated_set_change_count != descriptor_set->GetChangeCount() || |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1229 | (!disabled[image_layout_validation] && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1230 | state.per_set[set_index].validated_set_image_layout_change_count != cb_state->image_layout_change_count); |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1231 | bool need_update = descriptor_set_changed || |
| 1232 | // Update if previous bindingReqMap doesn't include new bindingReqMap |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1233 | !std::includes(state.per_set[set_index].validated_set_binding_req_map.begin(), |
| 1234 | state.per_set[set_index].validated_set_binding_req_map.end(), binding_req_map.begin(), |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1235 | binding_req_map.end()); |
| 1236 | |
| 1237 | if (need_update) { |
| 1238 | // Bind this set and its active descriptor resources to the command buffer |
| 1239 | if (!descriptor_set_changed && reduced_map.IsManyDescriptors()) { |
| 1240 | // Only record the bindings that haven't already been recorded |
| 1241 | BindingReqMap delta_reqs; |
| 1242 | std::set_difference(binding_req_map.begin(), binding_req_map.end(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1243 | state.per_set[set_index].validated_set_binding_req_map.begin(), |
| 1244 | state.per_set[set_index].validated_set_binding_req_map.end(), |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 1245 | layer_data::insert_iterator<BindingReqMap>(delta_reqs, delta_reqs.begin())); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1246 | descriptor_set->UpdateDrawState(this, cb_state, cmd_type, pipe, delta_reqs, function); |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1247 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1248 | descriptor_set->UpdateDrawState(this, cb_state, cmd_type, pipe, binding_req_map, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1249 | } |
| 1250 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1251 | state.per_set[set_index].validated_set = descriptor_set; |
| 1252 | state.per_set[set_index].validated_set_change_count = descriptor_set->GetChangeCount(); |
| 1253 | state.per_set[set_index].validated_set_image_layout_change_count = cb_state->image_layout_change_count; |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1254 | if (reduced_map.IsManyDescriptors()) { |
| 1255 | // Check whether old == new before assigning, the equality check is much cheaper than |
| 1256 | // freeing and reallocating the map. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1257 | if (state.per_set[set_index].validated_set_binding_req_map != set_binding_pair.second) { |
| 1258 | state.per_set[set_index].validated_set_binding_req_map = set_binding_pair.second; |
Jeff Bolz | 5630894 | 2019-10-06 22:05:23 -0500 | [diff] [blame] | 1259 | } |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1260 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1261 | state.per_set[set_index].validated_set_binding_req_map = BindingReqMap(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1266 | if (!pipe->vertex_binding_descriptions_.empty()) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1267 | cb_state->vertex_buffer_used = true; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | // Remove set from setMap and delete the set |
| 1272 | void ValidationStateTracker::FreeDescriptorSet(cvdescriptorset::DescriptorSet *descriptor_set) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 1273 | descriptor_set->destroyed = true; |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1274 | const VulkanTypedHandle obj_struct(descriptor_set->GetSet(), kVulkanObjectTypeDescriptorSet); |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1275 | // Any bound cmd buffers are now invalid |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1276 | InvalidateCommandBuffers(descriptor_set->cb_bindings, obj_struct); |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1277 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1278 | setMap.erase(descriptor_set->GetSet()); |
| 1279 | } |
| 1280 | |
| 1281 | // Free all DS Pools including their Sets & related sub-structs |
| 1282 | // NOTE : Calls to this function should be wrapped in mutex |
| 1283 | void ValidationStateTracker::DeleteDescriptorSetPools() { |
| 1284 | for (auto ii = descriptorPoolMap.begin(); ii != descriptorPoolMap.end();) { |
| 1285 | // Remove this pools' sets from setMap and delete them |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1286 | for (auto *ds : ii->second->sets) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1287 | FreeDescriptorSet(ds); |
| 1288 | } |
| 1289 | ii->second->sets.clear(); |
| 1290 | ii = descriptorPoolMap.erase(ii); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | // For given object struct return a ptr of BASE_NODE type for its wrapping struct |
| 1295 | BASE_NODE *ValidationStateTracker::GetStateStructPtrFromObject(const VulkanTypedHandle &object_struct) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1296 | if (object_struct.node) { |
| 1297 | #ifdef _DEBUG |
| 1298 | // assert that lookup would find the same object |
| 1299 | VulkanTypedHandle other = object_struct; |
| 1300 | other.node = nullptr; |
| 1301 | assert(object_struct.node == GetStateStructPtrFromObject(other)); |
| 1302 | #endif |
| 1303 | return object_struct.node; |
| 1304 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1305 | BASE_NODE *base_ptr = nullptr; |
| 1306 | switch (object_struct.type) { |
| 1307 | case kVulkanObjectTypeDescriptorSet: { |
| 1308 | base_ptr = GetSetNode(object_struct.Cast<VkDescriptorSet>()); |
| 1309 | break; |
| 1310 | } |
| 1311 | case kVulkanObjectTypeSampler: { |
| 1312 | base_ptr = GetSamplerState(object_struct.Cast<VkSampler>()); |
| 1313 | break; |
| 1314 | } |
| 1315 | case kVulkanObjectTypeQueryPool: { |
| 1316 | base_ptr = GetQueryPoolState(object_struct.Cast<VkQueryPool>()); |
| 1317 | break; |
| 1318 | } |
| 1319 | case kVulkanObjectTypePipeline: { |
| 1320 | base_ptr = GetPipelineState(object_struct.Cast<VkPipeline>()); |
| 1321 | break; |
| 1322 | } |
| 1323 | case kVulkanObjectTypeBuffer: { |
| 1324 | base_ptr = GetBufferState(object_struct.Cast<VkBuffer>()); |
| 1325 | break; |
| 1326 | } |
| 1327 | case kVulkanObjectTypeBufferView: { |
| 1328 | base_ptr = GetBufferViewState(object_struct.Cast<VkBufferView>()); |
| 1329 | break; |
| 1330 | } |
| 1331 | case kVulkanObjectTypeImage: { |
| 1332 | base_ptr = GetImageState(object_struct.Cast<VkImage>()); |
| 1333 | break; |
| 1334 | } |
| 1335 | case kVulkanObjectTypeImageView: { |
| 1336 | base_ptr = GetImageViewState(object_struct.Cast<VkImageView>()); |
| 1337 | break; |
| 1338 | } |
| 1339 | case kVulkanObjectTypeEvent: { |
| 1340 | base_ptr = GetEventState(object_struct.Cast<VkEvent>()); |
| 1341 | break; |
| 1342 | } |
| 1343 | case kVulkanObjectTypeDescriptorPool: { |
| 1344 | base_ptr = GetDescriptorPoolState(object_struct.Cast<VkDescriptorPool>()); |
| 1345 | break; |
| 1346 | } |
| 1347 | case kVulkanObjectTypeCommandPool: { |
| 1348 | base_ptr = GetCommandPoolState(object_struct.Cast<VkCommandPool>()); |
| 1349 | break; |
| 1350 | } |
| 1351 | case kVulkanObjectTypeFramebuffer: { |
| 1352 | base_ptr = GetFramebufferState(object_struct.Cast<VkFramebuffer>()); |
| 1353 | break; |
| 1354 | } |
| 1355 | case kVulkanObjectTypeRenderPass: { |
| 1356 | base_ptr = GetRenderPassState(object_struct.Cast<VkRenderPass>()); |
| 1357 | break; |
| 1358 | } |
| 1359 | case kVulkanObjectTypeDeviceMemory: { |
| 1360 | base_ptr = GetDevMemState(object_struct.Cast<VkDeviceMemory>()); |
| 1361 | break; |
| 1362 | } |
| 1363 | case kVulkanObjectTypeAccelerationStructureNV: { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1364 | base_ptr = GetAccelerationStructureStateNV(object_struct.Cast<VkAccelerationStructureNV>()); |
| 1365 | break; |
| 1366 | } |
| 1367 | case kVulkanObjectTypeAccelerationStructureKHR: { |
| 1368 | base_ptr = GetAccelerationStructureStateKHR(object_struct.Cast<VkAccelerationStructureKHR>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1369 | break; |
| 1370 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1371 | case kVulkanObjectTypeUnknown: |
| 1372 | // This can happen if an element of the object_bindings vector has been |
| 1373 | // zeroed out, after an object is destroyed. |
| 1374 | break; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1375 | default: |
| 1376 | // TODO : Any other objects to be handled here? |
| 1377 | assert(0); |
| 1378 | break; |
| 1379 | } |
| 1380 | return base_ptr; |
| 1381 | } |
| 1382 | |
sfricke-samsung | bf1a2ed | 2020-06-14 23:31:00 -0700 | [diff] [blame] | 1383 | // Gets union of all features defined by Potential Format Features |
| 1384 | // except, does not handle the external format case for AHB as that only can be used for sampled images |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 1385 | VkFormatFeatureFlags ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const { |
| 1386 | VkFormatFeatureFlags format_features = 0; |
| 1387 | |
| 1388 | if (format != VK_FORMAT_UNDEFINED) { |
| 1389 | VkFormatProperties format_properties; |
| 1390 | DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties); |
| 1391 | format_features |= format_properties.linearTilingFeatures; |
| 1392 | format_features |= format_properties.optimalTilingFeatures; |
| 1393 | if (device_extensions.vk_ext_image_drm_format_modifier) { |
| 1394 | // VK_KHR_get_physical_device_properties2 is required in this case |
| 1395 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; |
| 1396 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 1397 | nullptr}; |
| 1398 | format_properties_2.pNext = (void *)&drm_properties_list; |
Marc Alcala Prieto | 773871c | 2021-02-04 19:24:43 +0100 | [diff] [blame] | 1399 | |
| 1400 | // First call is to get the number of modifiers compatible with the queried format |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 1401 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2); |
Marc Alcala Prieto | 773871c | 2021-02-04 19:24:43 +0100 | [diff] [blame] | 1402 | |
| 1403 | std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties; |
| 1404 | drm_properties.resize(drm_properties_list.drmFormatModifierCount); |
| 1405 | drm_properties_list.pDrmFormatModifierProperties = drm_properties.data(); |
| 1406 | |
| 1407 | // Second call, now with an allocated array in pDrmFormatModifierProperties, is to get the modifiers |
| 1408 | // compatible with the queried format |
| 1409 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2); |
| 1410 | |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 1411 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
| 1412 | format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
| 1413 | } |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | return format_features; |
| 1418 | } |
| 1419 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1420 | // Tie the VulkanTypedHandle to the cmd buffer which includes: |
| 1421 | // Add object_binding to cmd buffer |
| 1422 | // Add cb_binding to object |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 1423 | bool ValidationStateTracker::AddCommandBufferBinding(BASE_NODE::BindingsType &cb_bindings, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1424 | const VulkanTypedHandle &obj, CMD_BUFFER_STATE *cb_node) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1425 | if (disabled[command_buffer_state]) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1426 | return false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1427 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1428 | // Insert the cb_binding with a default 'index' of -1. Then push the obj into the object_bindings |
| 1429 | // vector, and update cb_bindings[cb_node] with the index of that element of the vector. |
Jeremy Gebben | fc6f815 | 2021-03-18 16:58:55 -0600 | [diff] [blame] | 1430 | auto inserted = cb_bindings.emplace(cb_node, -1); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1431 | if (inserted.second) { |
| 1432 | cb_node->object_bindings.push_back(obj); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1433 | inserted.first->second = static_cast<int>(cb_node->object_bindings.size()) - 1; |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1434 | return true; |
| 1435 | } |
| 1436 | return false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | // For a given object, if cb_node is in that objects cb_bindings, remove cb_node |
| 1440 | void ValidationStateTracker::RemoveCommandBufferBinding(VulkanTypedHandle const &object, CMD_BUFFER_STATE *cb_node) { |
| 1441 | BASE_NODE *base_obj = GetStateStructPtrFromObject(object); |
| 1442 | if (base_obj) base_obj->cb_bindings.erase(cb_node); |
| 1443 | } |
| 1444 | |
| 1445 | // Reset the command buffer state |
| 1446 | // Maintain the createInfo and set state to CB_NEW, but clear all other state |
| 1447 | void ValidationStateTracker::ResetCommandBufferState(const VkCommandBuffer cb) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1448 | CMD_BUFFER_STATE *cb_state = GetCBState(cb); |
| 1449 | if (cb_state) { |
| 1450 | cb_state->in_use.store(0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1451 | // Reset CB state (note that createInfo is not cleared) |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1452 | cb_state->commandBuffer = cb; |
| 1453 | memset(&cb_state->beginInfo, 0, sizeof(VkCommandBufferBeginInfo)); |
| 1454 | memset(&cb_state->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo)); |
| 1455 | cb_state->hasDrawCmd = false; |
| 1456 | cb_state->hasTraceRaysCmd = false; |
| 1457 | cb_state->hasBuildAccelerationStructureCmd = false; |
| 1458 | cb_state->hasDispatchCmd = false; |
| 1459 | cb_state->state = CB_NEW; |
| 1460 | cb_state->commandCount = 0; |
| 1461 | cb_state->submitCount = 0; |
| 1462 | cb_state->image_layout_change_count = 1; // Start at 1. 0 is insert value for validation cache versions, s.t. new == dirty |
| 1463 | cb_state->status = 0; |
| 1464 | cb_state->static_status = 0; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 1465 | cb_state->inheritedViewportDepths.clear(); |
| 1466 | cb_state->usedViewportScissorCount = 0; |
| 1467 | cb_state->pipelineStaticViewportCount = 0; |
| 1468 | cb_state->pipelineStaticScissorCount = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1469 | cb_state->viewportMask = 0; |
| 1470 | cb_state->viewportWithCountMask = 0; |
| 1471 | cb_state->viewportWithCountCount = 0; |
| 1472 | cb_state->scissorMask = 0; |
| 1473 | cb_state->scissorWithCountMask = 0; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 1474 | cb_state->scissorWithCountCount = 0; |
| 1475 | cb_state->trashedViewportMask = 0; |
| 1476 | cb_state->trashedScissorMask = 0; |
| 1477 | cb_state->trashedViewportCount = false; |
| 1478 | cb_state->trashedScissorCount = false; |
| 1479 | cb_state->usedDynamicViewportCount = false; |
| 1480 | cb_state->usedDynamicScissorCount = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1481 | cb_state->primitiveTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1482 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1483 | for (auto &item : cb_state->lastBound) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1484 | item.reset(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1485 | } |
| 1486 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1487 | cb_state->activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo(); |
| 1488 | cb_state->activeRenderPass = nullptr; |
| 1489 | cb_state->active_attachments = nullptr; |
| 1490 | cb_state->active_subpasses = nullptr; |
| 1491 | cb_state->attachments_view_states.clear(); |
| 1492 | cb_state->activeSubpassContents = VK_SUBPASS_CONTENTS_INLINE; |
| 1493 | cb_state->activeSubpass = 0; |
| 1494 | cb_state->broken_bindings.clear(); |
| 1495 | cb_state->waitedEvents.clear(); |
| 1496 | cb_state->events.clear(); |
| 1497 | cb_state->writeEventsBeforeWait.clear(); |
| 1498 | cb_state->activeQueries.clear(); |
| 1499 | cb_state->startedQueries.clear(); |
| 1500 | cb_state->image_layout_map.clear(); |
| 1501 | cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.clear(); |
| 1502 | cb_state->vertex_buffer_used = false; |
| 1503 | cb_state->primaryCommandBuffer = VK_NULL_HANDLE; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1504 | // If secondary, invalidate any primary command buffer that may call us. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1505 | if (cb_state->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
| 1506 | InvalidateLinkedCommandBuffers(cb_state->linkedCommandBuffers, VulkanTypedHandle(cb, kVulkanObjectTypeCommandBuffer)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | // Remove reverse command buffer links. |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1510 | for (auto *sub_cb : cb_state->linkedCommandBuffers) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1511 | sub_cb->linkedCommandBuffers.erase(cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1512 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1513 | cb_state->linkedCommandBuffers.clear(); |
| 1514 | cb_state->queue_submit_functions.clear(); |
| 1515 | cb_state->cmd_execute_commands_functions.clear(); |
| 1516 | cb_state->eventUpdates.clear(); |
| 1517 | cb_state->queryUpdates.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1518 | |
| 1519 | // Remove object bindings |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1520 | for (const auto &obj : cb_state->object_bindings) { |
| 1521 | RemoveCommandBufferBinding(obj, cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1522 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1523 | cb_state->object_bindings.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1524 | // Remove this cmdBuffer's reference from each FrameBuffer's CB ref list |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1525 | for (auto &framebuffer : cb_state->framebuffers) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1526 | framebuffer->cb_bindings.erase(cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1527 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1528 | cb_state->framebuffers.clear(); |
| 1529 | cb_state->activeFramebuffer = VK_NULL_HANDLE; |
| 1530 | cb_state->index_buffer_binding.reset(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1531 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1532 | cb_state->qfo_transfer_image_barriers.Reset(); |
| 1533 | cb_state->qfo_transfer_buffer_barriers.Reset(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1534 | |
| 1535 | // Clean up the label data |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1536 | ResetCmdDebugUtilsLabel(report_data, cb_state->commandBuffer); |
| 1537 | cb_state->debug_label.Reset(); |
| 1538 | cb_state->validate_descriptorsets_in_queuesubmit.clear(); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1539 | |
| 1540 | // Best practices info |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1541 | cb_state->small_indexed_draw_call_count = 0; |
Jeremy Hayes | 9bda85a | 2020-05-21 16:36:17 -0600 | [diff] [blame] | 1542 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1543 | cb_state->transform_feedback_active = false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1544 | } |
| 1545 | if (command_buffer_reset_callback) { |
| 1546 | (*command_buffer_reset_callback)(cb); |
| 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 1551 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, |
| 1552 | VkResult result) { |
| 1553 | if (VK_SUCCESS != result) return; |
| 1554 | |
Locke Lin | f387354 | 2021-04-26 11:25:10 -0600 | [diff] [blame] | 1555 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 1556 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type); |
| 1557 | ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data); |
| 1558 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1559 | const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures; |
| 1560 | if (nullptr == enabled_features_found) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1561 | const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1562 | if (features2) { |
| 1563 | enabled_features_found = &(features2->features); |
Locke Lin | f387354 | 2021-04-26 11:25:10 -0600 | [diff] [blame] | 1564 | |
| 1565 | const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(features2->pNext); |
| 1566 | if (provoking_vertex_features) { |
| 1567 | state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features; |
| 1568 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1569 | } |
| 1570 | } |
| 1571 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1572 | if (nullptr == enabled_features_found) { |
| 1573 | state_tracker->enabled_features.core = {}; |
| 1574 | } else { |
| 1575 | state_tracker->enabled_features.core = *enabled_features_found; |
| 1576 | } |
| 1577 | |
| 1578 | // Make sure that queue_family_properties are obtained for this device's physical_device, even if the app has not |
| 1579 | // previously set them through an explicit API call. |
| 1580 | uint32_t count; |
| 1581 | auto pd_state = GetPhysicalDeviceState(gpu); |
| 1582 | DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr); |
| 1583 | pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count)); |
| 1584 | DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, &pd_state->queue_family_properties[0]); |
| 1585 | // Save local link to this device's physical device state |
| 1586 | state_tracker->physical_device_state = pd_state; |
| 1587 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1588 | const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1589 | if (vulkan_12_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1590 | state_tracker->enabled_features.core12 = *vulkan_12_features; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1591 | } else { |
sfricke-samsung | 27c7072 | 2020-05-02 08:42:39 -0700 | [diff] [blame] | 1592 | // Set Extension Feature Aliases to false as there is no struct to check |
| 1593 | state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE; |
| 1594 | state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE; |
| 1595 | state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE; |
| 1596 | state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE; |
| 1597 | state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE; |
| 1598 | state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE; |
sfricke-samsung | a4143ac | 2020-12-18 00:00:53 -0800 | [diff] [blame] | 1599 | state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE; |
sfricke-samsung | 27c7072 | 2020-05-02 08:42:39 -0700 | [diff] [blame] | 1600 | |
| 1601 | // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1602 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1603 | const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1604 | if (eight_bit_storage_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1605 | state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess; |
| 1606 | state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess = |
| 1607 | eight_bit_storage_features->uniformAndStorageBuffer8BitAccess; |
| 1608 | state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1611 | const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1612 | if (float16_int8_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1613 | state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16; |
| 1614 | state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1617 | const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1618 | if (descriptor_indexing_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1619 | state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing = |
| 1620 | descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing; |
| 1621 | state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing = |
| 1622 | descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing; |
| 1623 | state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing = |
| 1624 | descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing; |
| 1625 | state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing = |
| 1626 | descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing; |
| 1627 | state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing = |
| 1628 | descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing; |
| 1629 | state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing = |
| 1630 | descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing; |
| 1631 | state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing = |
| 1632 | descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing; |
| 1633 | state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing = |
| 1634 | descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing; |
| 1635 | state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing = |
| 1636 | descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing; |
| 1637 | state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing = |
| 1638 | descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing; |
| 1639 | state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind = |
| 1640 | descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind; |
| 1641 | state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind = |
| 1642 | descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind; |
| 1643 | state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind = |
| 1644 | descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind; |
| 1645 | state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind = |
| 1646 | descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind; |
| 1647 | state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind = |
| 1648 | descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind; |
| 1649 | state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind = |
| 1650 | descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind; |
| 1651 | state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending = |
| 1652 | descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending; |
| 1653 | state_tracker->enabled_features.core12.descriptorBindingPartiallyBound = |
| 1654 | descriptor_indexing_features->descriptorBindingPartiallyBound; |
| 1655 | state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount = |
| 1656 | descriptor_indexing_features->descriptorBindingVariableDescriptorCount; |
| 1657 | state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1660 | const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1661 | if (scalar_block_layout_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1662 | state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | const auto *imageless_framebuffer_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1666 | LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1667 | if (imageless_framebuffer_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1668 | state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | const auto *uniform_buffer_standard_layout_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1672 | LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1673 | if (uniform_buffer_standard_layout_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1674 | state_tracker->enabled_features.core12.uniformBufferStandardLayout = |
| 1675 | uniform_buffer_standard_layout_features->uniformBufferStandardLayout; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | const auto *subgroup_extended_types_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1679 | LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1680 | if (subgroup_extended_types_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1681 | state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes = |
| 1682 | subgroup_extended_types_features->shaderSubgroupExtendedTypes; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | const auto *separate_depth_stencil_layouts_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1686 | LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1687 | if (separate_depth_stencil_layouts_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1688 | state_tracker->enabled_features.core12.separateDepthStencilLayouts = |
| 1689 | separate_depth_stencil_layouts_features->separateDepthStencilLayouts; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1692 | const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1693 | if (host_query_reset_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1694 | state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1697 | const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1698 | if (timeline_semaphore_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1699 | state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1700 | } |
| 1701 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1702 | const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1703 | if (buffer_device_address) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1704 | state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress; |
| 1705 | state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay = |
| 1706 | buffer_device_address->bufferDeviceAddressCaptureReplay; |
| 1707 | state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice = |
| 1708 | buffer_device_address->bufferDeviceAddressMultiDevice; |
| 1709 | } |
sfricke-samsung | a4143ac | 2020-12-18 00:00:53 -0800 | [diff] [blame] | 1710 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1711 | const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext); |
sfricke-samsung | a4143ac | 2020-12-18 00:00:53 -0800 | [diff] [blame] | 1712 | if (atomic_int64_features) { |
| 1713 | state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics; |
| 1714 | state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics; |
| 1715 | } |
| 1716 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1717 | const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext); |
sfricke-samsung | a4143ac | 2020-12-18 00:00:53 -0800 | [diff] [blame] | 1718 | if (memory_model_features) { |
| 1719 | state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel; |
| 1720 | state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope = |
| 1721 | memory_model_features->vulkanMemoryModelDeviceScope; |
| 1722 | state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains = |
| 1723 | memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains; |
| 1724 | } |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1727 | const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1728 | if (vulkan_11_features) { |
| 1729 | state_tracker->enabled_features.core11 = *vulkan_11_features; |
| 1730 | } else { |
| 1731 | // These structs are only allowed in pNext chain if there is no kPhysicalDeviceVulkan11Features |
| 1732 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1733 | const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1734 | if (sixteen_bit_storage_features) { |
| 1735 | state_tracker->enabled_features.core11.storageBuffer16BitAccess = |
| 1736 | sixteen_bit_storage_features->storageBuffer16BitAccess; |
| 1737 | state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess = |
| 1738 | sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess; |
| 1739 | state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16; |
| 1740 | state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16; |
| 1741 | } |
| 1742 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1743 | const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1744 | if (multiview_features) { |
| 1745 | state_tracker->enabled_features.core11.multiview = multiview_features->multiview; |
| 1746 | state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader; |
| 1747 | state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader; |
| 1748 | } |
| 1749 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1750 | const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1751 | if (variable_pointers_features) { |
| 1752 | state_tracker->enabled_features.core11.variablePointersStorageBuffer = |
| 1753 | variable_pointers_features->variablePointersStorageBuffer; |
| 1754 | state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers; |
| 1755 | } |
| 1756 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1757 | const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1758 | if (protected_memory_features) { |
| 1759 | state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory; |
| 1760 | } |
| 1761 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1762 | const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1763 | if (ycbcr_conversion_features) { |
| 1764 | state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion; |
| 1765 | } |
| 1766 | |
| 1767 | const auto *shader_draw_parameters_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1768 | LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1769 | if (shader_draw_parameters_features) { |
| 1770 | state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1771 | } |
| 1772 | } |
| 1773 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1774 | const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext); |
Tony-LunarG | ca4891a | 2020-08-10 15:46:46 -0600 | [diff] [blame] | 1775 | if (device_group_ci) { |
| 1776 | state_tracker->physical_device_count = device_group_ci->physicalDeviceCount; |
| 1777 | state_tracker->device_group_create_info = *device_group_ci; |
| 1778 | } else { |
| 1779 | state_tracker->physical_device_count = 1; |
| 1780 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1781 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1782 | const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1783 | if (exclusive_scissor_features) { |
| 1784 | state_tracker->enabled_features.exclusive_scissor = *exclusive_scissor_features; |
| 1785 | } |
| 1786 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1787 | const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1788 | if (shading_rate_image_features) { |
| 1789 | state_tracker->enabled_features.shading_rate_image = *shading_rate_image_features; |
| 1790 | } |
| 1791 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1792 | const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1793 | if (mesh_shader_features) { |
| 1794 | state_tracker->enabled_features.mesh_shader = *mesh_shader_features; |
| 1795 | } |
| 1796 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1797 | const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1798 | if (inline_uniform_block_features) { |
| 1799 | state_tracker->enabled_features.inline_uniform_block = *inline_uniform_block_features; |
| 1800 | } |
| 1801 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1802 | const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1803 | if (transform_feedback_features) { |
| 1804 | state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features; |
| 1805 | } |
| 1806 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1807 | const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1808 | if (vtx_attrib_div_features) { |
| 1809 | state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features; |
| 1810 | } |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1811 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1812 | const auto *buffer_device_address_ext = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext); |
Jeff Bolz | 4563f2a | 2019-12-10 13:30:30 -0600 | [diff] [blame] | 1813 | if (buffer_device_address_ext) { |
Jeff Bolz | 33fc672 | 2020-03-31 12:58:16 -0500 | [diff] [blame] | 1814 | state_tracker->enabled_features.buffer_device_address_ext = *buffer_device_address_ext; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1815 | } |
| 1816 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1817 | const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1818 | if (cooperative_matrix_features) { |
| 1819 | state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features; |
| 1820 | } |
| 1821 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1822 | const auto *compute_shader_derivatives_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1823 | LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1824 | if (compute_shader_derivatives_features) { |
| 1825 | state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features; |
| 1826 | } |
| 1827 | |
| 1828 | const auto *fragment_shader_barycentric_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1829 | LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1830 | if (fragment_shader_barycentric_features) { |
| 1831 | state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features; |
| 1832 | } |
| 1833 | |
| 1834 | const auto *shader_image_footprint_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1835 | LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1836 | if (shader_image_footprint_features) { |
| 1837 | state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features; |
| 1838 | } |
| 1839 | |
| 1840 | const auto *fragment_shader_interlock_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1841 | LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1842 | if (fragment_shader_interlock_features) { |
| 1843 | state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features; |
| 1844 | } |
| 1845 | |
| 1846 | const auto *demote_to_helper_invocation_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1847 | LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1848 | if (demote_to_helper_invocation_features) { |
| 1849 | state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features; |
| 1850 | } |
| 1851 | |
| 1852 | const auto *texel_buffer_alignment_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1853 | LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1854 | if (texel_buffer_alignment_features) { |
| 1855 | state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features; |
| 1856 | } |
| 1857 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1858 | const auto *pipeline_exe_props_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1859 | LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1860 | if (pipeline_exe_props_features) { |
| 1861 | state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features; |
| 1862 | } |
| 1863 | |
Jeff Bolz | 82f854d | 2019-09-17 14:56:47 -0500 | [diff] [blame] | 1864 | const auto *dedicated_allocation_image_aliasing_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1865 | LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext); |
Jeff Bolz | 82f854d | 2019-09-17 14:56:47 -0500 | [diff] [blame] | 1866 | if (dedicated_allocation_image_aliasing_features) { |
| 1867 | state_tracker->enabled_features.dedicated_allocation_image_aliasing_features = |
| 1868 | *dedicated_allocation_image_aliasing_features; |
| 1869 | } |
| 1870 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1871 | const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext); |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 1872 | if (performance_query_features) { |
| 1873 | state_tracker->enabled_features.performance_query_features = *performance_query_features; |
| 1874 | } |
| 1875 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1876 | const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext); |
Tobias Hector | 782bcde | 2019-11-28 16:19:42 +0000 | [diff] [blame] | 1877 | if (device_coherent_memory_features) { |
| 1878 | state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features; |
| 1879 | } |
| 1880 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1881 | const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext); |
sfricke-samsung | cead080 | 2020-01-30 22:20:10 -0800 | [diff] [blame] | 1882 | if (ycbcr_image_array_features) { |
| 1883 | state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features; |
| 1884 | } |
| 1885 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1886 | const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1887 | if (ray_query_features) { |
| 1888 | state_tracker->enabled_features.ray_query_features = *ray_query_features; |
| 1889 | } |
| 1890 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1891 | const auto *ray_tracing_pipeline_features = LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1892 | if (ray_tracing_pipeline_features) { |
| 1893 | state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features; |
| 1894 | } |
| 1895 | |
| 1896 | const auto *ray_tracing_acceleration_structure_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1897 | LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1898 | if (ray_tracing_acceleration_structure_features) { |
| 1899 | state_tracker->enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features; |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 1900 | } |
| 1901 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1902 | const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 1903 | if (robustness2_features) { |
| 1904 | state_tracker->enabled_features.robustness2_features = *robustness2_features; |
| 1905 | } |
| 1906 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1907 | const auto *fragment_density_map_features = LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext); |
janharaldfredriksen-arm | 3b79377 | 2020-05-12 18:55:53 +0200 | [diff] [blame] | 1908 | if (fragment_density_map_features) { |
| 1909 | state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features; |
| 1910 | } |
| 1911 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1912 | const auto *fragment_density_map_features2 = LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext); |
janharaldfredriksen-arm | 36e1757 | 2020-07-07 13:59:28 +0200 | [diff] [blame] | 1913 | if (fragment_density_map_features2) { |
| 1914 | state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2; |
| 1915 | } |
| 1916 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1917 | const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext); |
sfricke-samsung | 0c4a06f | 2020-06-27 01:24:32 -0700 | [diff] [blame] | 1918 | if (astc_decode_features) { |
| 1919 | state_tracker->enabled_features.astc_decode_features = *astc_decode_features; |
| 1920 | } |
| 1921 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1922 | const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext); |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 1923 | if (custom_border_color_features) { |
| 1924 | state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features; |
| 1925 | } |
| 1926 | |
sfricke-samsung | fd661d6 | 2020-05-16 00:57:27 -0700 | [diff] [blame] | 1927 | const auto *pipeline_creation_cache_control_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1928 | LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext); |
sfricke-samsung | fd661d6 | 2020-05-16 00:57:27 -0700 | [diff] [blame] | 1929 | if (pipeline_creation_cache_control_features) { |
| 1930 | state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features; |
| 1931 | } |
| 1932 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1933 | const auto *fragment_shading_rate_features = LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext); |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 1934 | if (fragment_shading_rate_features) { |
| 1935 | state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features; |
| 1936 | } |
| 1937 | |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 1938 | const auto *extended_dynamic_state_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1939 | LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext); |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 1940 | if (extended_dynamic_state_features) { |
| 1941 | state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features; |
| 1942 | } |
| 1943 | |
Vikram Kushwaha | a57b0c3 | 2021-04-19 12:21:46 -0700 | [diff] [blame] | 1944 | const auto *extended_dynamic_state2_features = |
| 1945 | LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext); |
| 1946 | if (extended_dynamic_state2_features) { |
| 1947 | state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features; |
| 1948 | } |
| 1949 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1950 | const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext); |
locke-lunarg | 3fa463a | 2020-10-23 16:39:04 -0600 | [diff] [blame] | 1951 | if (multiview_features) { |
| 1952 | state_tracker->enabled_features.multiview_features = *multiview_features; |
| 1953 | } |
| 1954 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1955 | const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext); |
Nathaniel Cesario | b3f2d70 | 2020-11-09 09:20:49 -0700 | [diff] [blame] | 1956 | if (portability_features) { |
| 1957 | state_tracker->enabled_features.portability_subset_features = *portability_features; |
| 1958 | } |
| 1959 | |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1960 | const auto *shader_integer_functions2_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1961 | LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext); |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1962 | if (shader_integer_functions2_features) { |
| 1963 | state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features; |
| 1964 | } |
| 1965 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1966 | const auto *shader_sm_builtins_feature = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext); |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1967 | if (shader_sm_builtins_feature) { |
| 1968 | state_tracker->enabled_features.shader_sm_builtins_feature = *shader_sm_builtins_feature; |
| 1969 | } |
| 1970 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1971 | const auto *shader_atomic_float_feature = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext); |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1972 | if (shader_atomic_float_feature) { |
| 1973 | state_tracker->enabled_features.shader_atomic_float_feature = *shader_atomic_float_feature; |
| 1974 | } |
| 1975 | |
| 1976 | const auto *shader_image_atomic_int64_feature = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1977 | LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext); |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1978 | if (shader_image_atomic_int64_feature) { |
| 1979 | state_tracker->enabled_features.shader_image_atomic_int64_feature = *shader_image_atomic_int64_feature; |
| 1980 | } |
| 1981 | |
sfricke-samsung | 486a51e | 2021-01-02 00:10:15 -0800 | [diff] [blame] | 1982 | const auto *shader_clock_feature = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext); |
| 1983 | if (shader_clock_feature) { |
| 1984 | state_tracker->enabled_features.shader_clock_feature = *shader_clock_feature; |
| 1985 | } |
| 1986 | |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 1987 | const auto *conditional_rendering_features = |
| 1988 | LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext); |
| 1989 | if (conditional_rendering_features) { |
| 1990 | state_tracker->enabled_features.conditional_rendering = *conditional_rendering_features; |
| 1991 | } |
| 1992 | |
Shannon McPherson | db287d4 | 2021-02-02 15:27:32 -0700 | [diff] [blame] | 1993 | const auto *workgroup_memory_explicit_layout_features = |
| 1994 | LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext); |
| 1995 | if (workgroup_memory_explicit_layout_features) { |
| 1996 | state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features; |
| 1997 | } |
| 1998 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1999 | const auto *synchronization2_features = |
| 2000 | LvlFindInChain<VkPhysicalDeviceSynchronization2FeaturesKHR>(pCreateInfo->pNext); |
| 2001 | if (synchronization2_features) { |
| 2002 | state_tracker->enabled_features.synchronization2_features = *synchronization2_features; |
| 2003 | } |
| 2004 | |
Locke Lin | f387354 | 2021-04-26 11:25:10 -0600 | [diff] [blame] | 2005 | const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext); |
| 2006 | if (provoking_vertex_features) { |
| 2007 | state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features; |
| 2008 | } |
| 2009 | |
Piers Daniell | cb6d803 | 2021-04-19 18:51:26 -0600 | [diff] [blame] | 2010 | const auto *vertex_input_dynamic_state_features = |
| 2011 | LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext); |
| 2012 | if (vertex_input_dynamic_state_features) { |
| 2013 | state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features; |
| 2014 | } |
| 2015 | |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2016 | const auto *inherited_viewport_scissor_features = |
| 2017 | LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext); |
| 2018 | if (inherited_viewport_scissor_features) { |
| 2019 | state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features; |
| 2020 | } |
| 2021 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2022 | // Store physical device properties and physical device mem limits into CoreChecks structs |
| 2023 | DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props); |
| 2024 | DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2025 | GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2, |
| 2026 | &state_tracker->phys_dev_props_core11); |
| 2027 | GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2, |
| 2028 | &state_tracker->phys_dev_props_core12); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2029 | |
| 2030 | const auto &dev_ext = state_tracker->device_extensions; |
| 2031 | auto *phys_dev_props = &state_tracker->phys_dev_ext_props; |
| 2032 | |
| 2033 | if (dev_ext.vk_khr_push_descriptor) { |
| 2034 | // Get the needed push_descriptor limits |
| 2035 | VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor_prop; |
| 2036 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &push_descriptor_prop); |
| 2037 | phys_dev_props->max_push_descriptors = push_descriptor_prop.maxPushDescriptors; |
| 2038 | } |
| 2039 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2040 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_ext_descriptor_indexing) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2041 | VkPhysicalDeviceDescriptorIndexingProperties descriptor_indexing_prop; |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2042 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop); |
| 2043 | state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools = |
| 2044 | descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools; |
| 2045 | state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative = |
| 2046 | descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative; |
| 2047 | state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative = |
| 2048 | descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative; |
| 2049 | state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative = |
| 2050 | descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative; |
| 2051 | state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative = |
| 2052 | descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative; |
| 2053 | state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative = |
| 2054 | descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative; |
| 2055 | state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind = |
| 2056 | descriptor_indexing_prop.robustBufferAccessUpdateAfterBind; |
| 2057 | state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod; |
| 2058 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers = |
| 2059 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers; |
| 2060 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers = |
| 2061 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers; |
| 2062 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers = |
| 2063 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers; |
| 2064 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages = |
| 2065 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages; |
| 2066 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages = |
| 2067 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages; |
| 2068 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments = |
| 2069 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments; |
| 2070 | state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources = |
| 2071 | descriptor_indexing_prop.maxPerStageUpdateAfterBindResources; |
| 2072 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers = |
| 2073 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers; |
| 2074 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers = |
| 2075 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers; |
| 2076 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic = |
| 2077 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic; |
| 2078 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers = |
| 2079 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers; |
| 2080 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic = |
| 2081 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic; |
| 2082 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages = |
| 2083 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages; |
| 2084 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages = |
| 2085 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages; |
| 2086 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments = |
| 2087 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments; |
| 2088 | } |
| 2089 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2090 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props); |
| 2091 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props); |
| 2092 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props); |
| 2093 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2094 | |
| 2095 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_depth_stencil_resolve) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2096 | VkPhysicalDeviceDepthStencilResolveProperties depth_stencil_resolve_props; |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2097 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props); |
| 2098 | state_tracker->phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes; |
| 2099 | state_tracker->phys_dev_props_core12.supportedStencilResolveModes = |
| 2100 | depth_stencil_resolve_props.supportedStencilResolveModes; |
| 2101 | state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone; |
| 2102 | state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve; |
| 2103 | } |
| 2104 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2105 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props); |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2106 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2107 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR); |
| 2108 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2109 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props); |
| 2110 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props); |
janharaldfredriksen-arm | 36e1757 | 2020-07-07 13:59:28 +0200 | [diff] [blame] | 2111 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map_2, &phys_dev_props->fragment_density_map2_props); |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2112 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props); |
sfricke-samsung | 8f658d4 | 2020-05-03 20:12:24 -0700 | [diff] [blame] | 2113 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props); |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 2114 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props); |
locke-lunarg | 3fa463a | 2020-10-23 16:39:04 -0600 | [diff] [blame] | 2115 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props); |
Nathaniel Cesario | 3291c91 | 2020-11-17 16:54:41 -0700 | [diff] [blame] | 2116 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2117 | |
| 2118 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_timeline_semaphore) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2119 | VkPhysicalDeviceTimelineSemaphoreProperties timeline_semaphore_props; |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2120 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props); |
| 2121 | state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference = |
| 2122 | timeline_semaphore_props.maxTimelineSemaphoreValueDifference; |
| 2123 | } |
| 2124 | |
| 2125 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_shader_float_controls) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2126 | VkPhysicalDeviceFloatControlsProperties float_controls_props; |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2127 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props); |
| 2128 | state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence; |
| 2129 | state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence; |
| 2130 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 = |
| 2131 | float_controls_props.shaderSignedZeroInfNanPreserveFloat16; |
| 2132 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 = |
| 2133 | float_controls_props.shaderSignedZeroInfNanPreserveFloat32; |
| 2134 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 = |
| 2135 | float_controls_props.shaderSignedZeroInfNanPreserveFloat64; |
| 2136 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16; |
| 2137 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32; |
| 2138 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64; |
| 2139 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16; |
| 2140 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32; |
| 2141 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64; |
| 2142 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16; |
| 2143 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32; |
| 2144 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64; |
| 2145 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16; |
| 2146 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32; |
| 2147 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64; |
| 2148 | } |
Mark Lobodzinski | e4a2b7f | 2019-12-20 12:51:30 -0700 | [diff] [blame] | 2149 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2150 | if (state_tracker->device_extensions.vk_nv_cooperative_matrix) { |
| 2151 | // Get the needed cooperative_matrix properties |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 2152 | auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>(); |
| 2153 | auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2154 | instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2); |
| 2155 | state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props; |
| 2156 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2157 | uint32_t num_cooperative_matrix_properties = 0; |
| 2158 | instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL); |
| 2159 | state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties, |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 2160 | LvlInitStruct<VkCooperativeMatrixPropertiesNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2161 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2162 | instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2163 | state_tracker->cooperative_matrix_properties.data()); |
| 2164 | } |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2165 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && state_tracker->api_version >= VK_API_VERSION_1_1) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2166 | // Get the needed subgroup limits |
Locke Lin | f387354 | 2021-04-26 11:25:10 -0600 | [diff] [blame] | 2167 | auto provoking_vertex_prop = LvlInitStruct<VkPhysicalDeviceProvokingVertexPropertiesEXT>(); |
| 2168 | auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>(&provoking_vertex_prop); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 2169 | auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&subgroup_prop); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2170 | instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2); |
| 2171 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2172 | state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize; |
| 2173 | state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages; |
| 2174 | state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations; |
| 2175 | state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages; |
Locke Lin | f387354 | 2021-04-26 11:25:10 -0600 | [diff] [blame] | 2176 | state_tracker->phys_dev_ext_props.provoking_vertex_props = provoking_vertex_prop; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2177 | } |
| 2178 | |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2179 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props); |
| 2180 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2181 | // Store queue family data |
| 2182 | if (pCreateInfo->pQueueCreateInfos != nullptr) { |
| 2183 | for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) { |
sfricke-samsung | 590ae1e | 2020-04-25 01:18:05 -0700 | [diff] [blame] | 2184 | const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i]; |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 2185 | state_tracker->queue_family_index_map.emplace(queue_create_info.queueFamilyIndex, queue_create_info.queueCount); |
| 2186 | state_tracker->queue_family_create_flags_map.emplace( queue_create_info.queueFamilyIndex, queue_create_info.flags); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2187 | } |
| 2188 | } |
| 2189 | } |
| 2190 | |
| 2191 | void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
| 2192 | if (!device) return; |
| 2193 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2194 | // Reset all command buffers before destroying them, to unlink object_bindings. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2195 | for (auto &command_buffer : commandBufferMap) { |
| 2196 | ResetCommandBufferState(command_buffer.first); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2197 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 2198 | pipelineMap.clear(); |
| 2199 | renderPassMap.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2200 | commandBufferMap.clear(); |
| 2201 | |
| 2202 | // This will also delete all sets in the pool & remove them from setMap |
| 2203 | DeleteDescriptorSetPools(); |
| 2204 | // All sets should be removed |
| 2205 | assert(setMap.empty()); |
| 2206 | descriptorSetLayoutMap.clear(); |
| 2207 | imageViewMap.clear(); |
| 2208 | imageMap.clear(); |
| 2209 | bufferViewMap.clear(); |
| 2210 | bufferMap.clear(); |
| 2211 | // Queues persist until device is destroyed |
| 2212 | queueMap.clear(); |
| 2213 | } |
| 2214 | |
| 2215 | // Loop through bound objects and increment their in_use counts. |
| 2216 | void ValidationStateTracker::IncrementBoundObjects(CMD_BUFFER_STATE const *cb_node) { |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2217 | for (const auto &obj : cb_node->object_bindings) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2218 | auto base_obj = GetStateStructPtrFromObject(obj); |
| 2219 | if (base_obj) { |
| 2220 | base_obj->in_use.fetch_add(1); |
| 2221 | } |
| 2222 | } |
| 2223 | } |
| 2224 | |
| 2225 | // Track which resources are in-flight by atomically incrementing their "in_use" count |
| 2226 | void ValidationStateTracker::IncrementResources(CMD_BUFFER_STATE *cb_node) { |
| 2227 | cb_node->submitCount++; |
| 2228 | cb_node->in_use.fetch_add(1); |
| 2229 | |
| 2230 | // First Increment for all "generic" objects bound to cmd buffer, followed by special-case objects below |
| 2231 | IncrementBoundObjects(cb_node); |
| 2232 | // TODO : We should be able to remove the NULL look-up checks from the code below as long as |
| 2233 | // all the corresponding cases are verified to cause CB_INVALID state and the CB_INVALID state |
| 2234 | // should then be flagged prior to calling this function |
| 2235 | for (auto event : cb_node->writeEventsBeforeWait) { |
| 2236 | auto event_state = GetEventState(event); |
| 2237 | if (event_state) event_state->write_in_use++; |
| 2238 | } |
| 2239 | } |
| 2240 | |
| 2241 | // Decrement in-use count for objects bound to command buffer |
| 2242 | void ValidationStateTracker::DecrementBoundResources(CMD_BUFFER_STATE const *cb_node) { |
| 2243 | BASE_NODE *base_obj = nullptr; |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2244 | for (const auto &obj : cb_node->object_bindings) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2245 | base_obj = GetStateStructPtrFromObject(obj); |
| 2246 | if (base_obj) { |
| 2247 | base_obj->in_use.fetch_sub(1); |
| 2248 | } |
| 2249 | } |
| 2250 | } |
| 2251 | |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2252 | void ValidationStateTracker::RetireWorkOnQueue(QUEUE_STATE *pQueue, uint64_t seq) { |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 2253 | layer_data::unordered_map<VkQueue, uint64_t> other_queue_seqs; |
| 2254 | layer_data::unordered_map<VkSemaphore, uint64_t> timeline_semaphore_counters; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2255 | |
| 2256 | // Roll this queue forward, one submission at a time. |
| 2257 | while (pQueue->seq < seq) { |
| 2258 | auto &submission = pQueue->submissions.front(); |
| 2259 | |
| 2260 | for (auto &wait : submission.waitSemaphores) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2261 | auto semaphore_state = GetSemaphoreState(wait.semaphore); |
| 2262 | if (semaphore_state) { |
| 2263 | semaphore_state->in_use.fetch_sub(1); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2264 | } |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2265 | if (wait.type == VK_SEMAPHORE_TYPE_TIMELINE) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2266 | auto &last_counter = timeline_semaphore_counters[wait.semaphore]; |
| 2267 | last_counter = std::max(last_counter, wait.payload); |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 2268 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2269 | auto &last_seq = other_queue_seqs[wait.queue]; |
| 2270 | last_seq = std::max(last_seq, wait.seq); |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 2271 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2272 | } |
| 2273 | |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 2274 | for (auto &signal : submission.signalSemaphores) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2275 | auto semaphore_state = GetSemaphoreState(signal.semaphore); |
| 2276 | if (semaphore_state) { |
| 2277 | semaphore_state->in_use.fetch_sub(1); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2278 | if (semaphore_state->type == VK_SEMAPHORE_TYPE_TIMELINE && semaphore_state->payload < signal.payload) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2279 | semaphore_state->payload = signal.payload; |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 2280 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | for (auto &semaphore : submission.externalSemaphores) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2285 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2286 | if (semaphore_state) { |
| 2287 | semaphore_state->in_use.fetch_sub(1); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2288 | } |
| 2289 | } |
| 2290 | |
| 2291 | for (auto cb : submission.cbs) { |
| 2292 | auto cb_node = GetCBState(cb); |
| 2293 | if (!cb_node) { |
| 2294 | continue; |
| 2295 | } |
| 2296 | // First perform decrement on general case bound objects |
| 2297 | DecrementBoundResources(cb_node); |
| 2298 | for (auto event : cb_node->writeEventsBeforeWait) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2299 | auto event_node = eventMap.find(event); |
| 2300 | if (event_node != eventMap.end()) { |
John Zulauf | 4805732 | 2020-12-02 11:59:31 -0700 | [diff] [blame] | 2301 | event_node->second->write_in_use--; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2302 | } |
| 2303 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2304 | QueryMap local_query_to_state_map; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 2305 | VkQueryPool first_pool = VK_NULL_HANDLE; |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 2306 | for (auto &function : cb_node->queryUpdates) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2307 | function(nullptr, /*do_validate*/ false, first_pool, submission.perf_submit_pass, &local_query_to_state_map); |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 2308 | } |
| 2309 | |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2310 | for (const auto &query_state_pair : local_query_to_state_map) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2311 | if (query_state_pair.second == QUERYSTATE_ENDED) { |
| 2312 | queryToStateMap[query_state_pair.first] = QUERYSTATE_AVAILABLE; |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2313 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2314 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2315 | cb_node->in_use.fetch_sub(1); |
| 2316 | } |
| 2317 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2318 | auto fence_state = GetFenceState(submission.fence); |
| 2319 | if (fence_state && fence_state->scope == kSyncScopeInternal) { |
| 2320 | fence_state->state = FENCE_RETIRED; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | pQueue->submissions.pop_front(); |
| 2324 | pQueue->seq++; |
| 2325 | } |
| 2326 | |
| 2327 | // Roll other queues forward to the highest seq we saw a wait for |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2328 | for (const auto &qs : other_queue_seqs) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2329 | RetireWorkOnQueue(GetQueueState(qs.first), qs.second); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2330 | } |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2331 | for (const auto &sc : timeline_semaphore_counters) { |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 2332 | RetireTimelineSemaphore(sc.first, sc.second); |
| 2333 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | // Submit a fence to a queue, delimiting previous fences and previous untracked |
| 2337 | // work by it. |
| 2338 | static void SubmitFence(QUEUE_STATE *pQueue, FENCE_STATE *pFence, uint64_t submitCount) { |
| 2339 | pFence->state = FENCE_INFLIGHT; |
| 2340 | pFence->signaler.first = pQueue->queue; |
| 2341 | pFence->signaler.second = pQueue->seq + pQueue->submissions.size() + submitCount; |
| 2342 | } |
| 2343 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2344 | uint64_t ValidationStateTracker::RecordSubmitFence(QUEUE_STATE *queue_state, VkFence fence, uint32_t submit_count) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2345 | auto fence_state = GetFenceState(fence); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2346 | uint64_t early_retire_seq = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2347 | if (fence_state) { |
| 2348 | if (fence_state->scope == kSyncScopeInternal) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2349 | // Mark fence in use |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2350 | SubmitFence(queue_state, fence_state, std::max(1u, submit_count)); |
| 2351 | if (!submit_count) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2352 | // If no submissions, but just dropping a fence on the end of the queue, |
| 2353 | // record an empty submission with just the fence, so we can determine |
| 2354 | // its completion. |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2355 | CB_SUBMISSION submission; |
| 2356 | submission.fence = fence; |
| 2357 | queue_state->submissions.emplace_back(std::move(submission)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2358 | } |
| 2359 | } else { |
| 2360 | // Retire work up until this fence early, we will not see the wait that corresponds to this signal |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2361 | early_retire_seq = queue_state->seq + queue_state->submissions.size(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2362 | } |
| 2363 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2364 | return early_retire_seq; |
| 2365 | } |
| 2366 | |
| 2367 | void ValidationStateTracker::RecordSubmitCommandBuffer(CB_SUBMISSION &submission, VkCommandBuffer command_buffer) { |
| 2368 | auto cb_node = GetCBState(command_buffer); |
| 2369 | if (cb_node) { |
| 2370 | submission.cbs.push_back(command_buffer); |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2371 | for (auto *secondary_cmd_buffer : cb_node->linkedCommandBuffers) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2372 | submission.cbs.push_back(secondary_cmd_buffer->commandBuffer); |
| 2373 | IncrementResources(secondary_cmd_buffer); |
| 2374 | } |
| 2375 | IncrementResources(cb_node); |
| 2376 | |
| 2377 | VkQueryPool first_pool = VK_NULL_HANDLE; |
| 2378 | EventToStageMap local_event_to_stage_map; |
| 2379 | QueryMap local_query_to_state_map; |
| 2380 | for (auto &function : cb_node->queryUpdates) { |
| 2381 | function(nullptr, /*do_validate*/ false, first_pool, submission.perf_submit_pass, &local_query_to_state_map); |
| 2382 | } |
| 2383 | |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2384 | for (const auto &query_state_pair : local_query_to_state_map) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2385 | queryToStateMap[query_state_pair.first] = query_state_pair.second; |
| 2386 | } |
| 2387 | |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2388 | for (const auto &function : cb_node->eventUpdates) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2389 | function(nullptr, /*do_validate*/ false, &local_event_to_stage_map); |
| 2390 | } |
| 2391 | |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2392 | for (const auto &eventStagePair : local_event_to_stage_map) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2393 | eventMap[eventStagePair.first]->stageMask = eventStagePair.second; |
| 2394 | } |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | void ValidationStateTracker::RecordSubmitWaitSemaphore(CB_SUBMISSION &submission, VkQueue queue, VkSemaphore semaphore, |
| 2399 | uint64_t value, uint64_t next_seq) { |
| 2400 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2401 | if (semaphore_state) { |
| 2402 | if (semaphore_state->scope == kSyncScopeInternal) { |
| 2403 | SEMAPHORE_WAIT wait; |
| 2404 | wait.semaphore = semaphore; |
| 2405 | wait.type = semaphore_state->type; |
| 2406 | if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY) { |
| 2407 | if (semaphore_state->signaler.first != VK_NULL_HANDLE) { |
| 2408 | wait.queue = semaphore_state->signaler.first; |
| 2409 | wait.seq = semaphore_state->signaler.second; |
| 2410 | submission.waitSemaphores.emplace_back(std::move(wait)); |
| 2411 | semaphore_state->in_use.fetch_add(1); |
| 2412 | } |
| 2413 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
| 2414 | semaphore_state->signaled = false; |
| 2415 | } else if (semaphore_state->payload < value) { |
| 2416 | wait.queue = queue; |
| 2417 | wait.seq = next_seq; |
| 2418 | wait.payload = value; |
| 2419 | submission.waitSemaphores.emplace_back(std::move(wait)); |
| 2420 | semaphore_state->in_use.fetch_add(1); |
| 2421 | } |
| 2422 | } else { |
| 2423 | submission.externalSemaphores.push_back(semaphore); |
| 2424 | semaphore_state->in_use.fetch_add(1); |
| 2425 | if (semaphore_state->scope == kSyncScopeExternalTemporary) { |
| 2426 | semaphore_state->scope = kSyncScopeInternal; |
| 2427 | } |
| 2428 | } |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | bool ValidationStateTracker::RecordSubmitSignalSemaphore(CB_SUBMISSION &submission, VkQueue queue, VkSemaphore semaphore, |
| 2433 | uint64_t value, uint64_t next_seq) { |
| 2434 | bool retire_early = false; |
| 2435 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2436 | if (semaphore_state) { |
| 2437 | if (semaphore_state->scope == kSyncScopeInternal) { |
| 2438 | SEMAPHORE_SIGNAL signal; |
| 2439 | signal.semaphore = semaphore; |
| 2440 | signal.seq = next_seq; |
| 2441 | if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY) { |
| 2442 | semaphore_state->signaler.first = queue; |
| 2443 | semaphore_state->signaler.second = next_seq; |
| 2444 | semaphore_state->signaled = true; |
| 2445 | } else { |
| 2446 | signal.payload = value; |
| 2447 | } |
| 2448 | semaphore_state->in_use.fetch_add(1); |
| 2449 | submission.signalSemaphores.emplace_back(std::move(signal)); |
| 2450 | } else { |
| 2451 | // Retire work up until this submit early, we will not see the wait that corresponds to this signal |
| 2452 | retire_early = true; |
| 2453 | } |
| 2454 | } |
| 2455 | return retire_early; |
| 2456 | } |
| 2457 | |
| 2458 | void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, |
| 2459 | VkFence fence, VkResult result) { |
| 2460 | if (result != VK_SUCCESS) return; |
| 2461 | auto queue_state = GetQueueState(queue); |
| 2462 | |
| 2463 | uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, submitCount); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2464 | |
| 2465 | // Now process each individual submit |
| 2466 | for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2467 | CB_SUBMISSION submission; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2468 | const VkSubmitInfo *submit = &pSubmits[submit_idx]; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2469 | const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1; |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2470 | auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2471 | for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) { |
Jeremy Gebben | 4ae5cc7 | 2021-03-10 15:34:44 -0700 | [diff] [blame] | 2472 | uint64_t value = 0; |
| 2473 | if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr && |
| 2474 | (i < timeline_semaphore_submit->waitSemaphoreValueCount)) { |
| 2475 | value = timeline_semaphore_submit->pWaitSemaphoreValues[i]; |
| 2476 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2477 | RecordSubmitWaitSemaphore(submission, queue, submit->pWaitSemaphores[i], value, next_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2478 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2479 | |
| 2480 | bool retire_early = false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2481 | for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) { |
Jeremy Gebben | 4ae5cc7 | 2021-03-10 15:34:44 -0700 | [diff] [blame] | 2482 | uint64_t value = 0; |
| 2483 | if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr && |
| 2484 | (i < timeline_semaphore_submit->signalSemaphoreValueCount)) { |
| 2485 | value = timeline_semaphore_submit->pSignalSemaphoreValues[i]; |
| 2486 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2487 | retire_early |= RecordSubmitSignalSemaphore(submission, queue, submit->pSignalSemaphores[i], value, next_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2488 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2489 | if (retire_early) { |
| 2490 | early_retire_seq = std::max(early_retire_seq, next_seq); |
| 2491 | } |
| 2492 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2493 | const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2494 | submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 2495 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2496 | for (uint32_t i = 0; i < submit->commandBufferCount; i++) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2497 | RecordSubmitCommandBuffer(submission, submit->pCommandBuffers[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2498 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2499 | submission.fence = submit_idx == (submitCount - 1) ? fence : VK_NULL_HANDLE; |
| 2500 | queue_state->submissions.emplace_back(std::move(submission)); |
| 2501 | } |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2502 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2503 | if (early_retire_seq) { |
| 2504 | RetireWorkOnQueue(queue_state, early_retire_seq); |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 2509 | VkFence fence, VkResult result) { |
| 2510 | if (result != VK_SUCCESS) return; |
| 2511 | auto queue_state = GetQueueState(queue); |
| 2512 | |
| 2513 | uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, submitCount); |
| 2514 | |
| 2515 | // Now process each individual submit |
| 2516 | for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) { |
| 2517 | CB_SUBMISSION submission; |
| 2518 | const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx]; |
| 2519 | const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1; |
| 2520 | for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) { |
| 2521 | const auto &sem_info = submit->pWaitSemaphoreInfos[i]; |
| 2522 | RecordSubmitWaitSemaphore(submission, queue, sem_info.semaphore, sem_info.value, next_seq); |
| 2523 | } |
| 2524 | bool retire_early = false; |
| 2525 | for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) { |
| 2526 | const auto &sem_info = submit->pSignalSemaphoreInfos[i]; |
| 2527 | retire_early |= RecordSubmitSignalSemaphore(submission, queue, sem_info.semaphore, sem_info.value, next_seq); |
| 2528 | } |
| 2529 | if (retire_early) { |
| 2530 | early_retire_seq = std::max(early_retire_seq, next_seq); |
| 2531 | } |
| 2532 | const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext); |
| 2533 | submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0; |
| 2534 | |
| 2535 | for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) { |
| 2536 | RecordSubmitCommandBuffer(submission, submit->pCommandBufferInfos[i].commandBuffer); |
| 2537 | } |
| 2538 | submission.fence = submit_idx == (submitCount - 1) ? fence : VK_NULL_HANDLE; |
| 2539 | queue_state->submissions.emplace_back(std::move(submission)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | if (early_retire_seq) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2543 | RetireWorkOnQueue(queue_state, early_retire_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, |
| 2548 | const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory, |
| 2549 | VkResult result) { |
| 2550 | if (VK_SUCCESS == result) { |
| 2551 | AddMemObjInfo(device, *pMemory, pAllocateInfo); |
| 2552 | } |
| 2553 | return; |
| 2554 | } |
| 2555 | |
| 2556 | void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) { |
| 2557 | if (!mem) return; |
| 2558 | DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem); |
| 2559 | const VulkanTypedHandle obj_struct(mem, kVulkanObjectTypeDeviceMemory); |
| 2560 | |
| 2561 | // Clear mem binding for any bound objects |
| 2562 | for (const auto &obj : mem_info->obj_bindings) { |
| 2563 | BINDABLE *bindable_state = nullptr; |
| 2564 | switch (obj.type) { |
| 2565 | case kVulkanObjectTypeImage: |
| 2566 | bindable_state = GetImageState(obj.Cast<VkImage>()); |
| 2567 | break; |
| 2568 | case kVulkanObjectTypeBuffer: |
| 2569 | bindable_state = GetBufferState(obj.Cast<VkBuffer>()); |
| 2570 | break; |
| 2571 | case kVulkanObjectTypeAccelerationStructureNV: |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2572 | bindable_state = GetAccelerationStructureStateNV(obj.Cast<VkAccelerationStructureNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2573 | break; |
| 2574 | |
| 2575 | default: |
| 2576 | // Should only have acceleration structure, buffer, or image objects bound to memory |
| 2577 | assert(0); |
| 2578 | } |
| 2579 | |
| 2580 | if (bindable_state) { |
Jeff Bolz | 41e2905 | 2020-03-29 22:33:55 -0500 | [diff] [blame] | 2581 | // Remove any sparse bindings bound to the resource that use this memory. |
| 2582 | for (auto it = bindable_state->sparse_bindings.begin(); it != bindable_state->sparse_bindings.end();) { |
| 2583 | auto nextit = it; |
| 2584 | nextit++; |
| 2585 | |
| 2586 | auto &sparse_mem_binding = *it; |
| 2587 | if (sparse_mem_binding.mem_state.get() == mem_info) { |
| 2588 | bindable_state->sparse_bindings.erase(it); |
| 2589 | } |
| 2590 | |
| 2591 | it = nextit; |
| 2592 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2593 | bindable_state->UpdateBoundMemorySet(); |
| 2594 | } |
| 2595 | } |
| 2596 | // Any bound cmd buffers are now invalid |
| 2597 | InvalidateCommandBuffers(mem_info->cb_bindings, obj_struct); |
| 2598 | RemoveAliasingImages(mem_info->bound_images); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2599 | mem_info->destroyed = true; |
John Zulauf | 7995271 | 2020-04-07 11:25:54 -0600 | [diff] [blame] | 2600 | fake_memory.Free(mem_info->fake_base_address); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2601 | memObjMap.erase(mem); |
| 2602 | } |
| 2603 | |
| 2604 | void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo, |
| 2605 | VkFence fence, VkResult result) { |
| 2606 | if (result != VK_SUCCESS) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2607 | auto queue_state = GetQueueState(queue); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2608 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2609 | uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, bindInfoCount); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2610 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2611 | for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) { |
| 2612 | const VkBindSparseInfo &bind_info = pBindInfo[bind_idx]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2613 | // Track objects tied to memory |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2614 | for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) { |
| 2615 | for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) { |
| 2616 | auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k]; |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 2617 | SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, sparse_binding.size, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2618 | VulkanTypedHandle(bind_info.pBufferBinds[j].buffer, kVulkanObjectTypeBuffer)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2619 | } |
| 2620 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2621 | for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) { |
| 2622 | for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) { |
| 2623 | auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k]; |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 2624 | SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, sparse_binding.size, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2625 | VulkanTypedHandle(bind_info.pImageOpaqueBinds[j].image, kVulkanObjectTypeImage)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2626 | } |
| 2627 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2628 | for (uint32_t j = 0; j < bind_info.imageBindCount; j++) { |
| 2629 | for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) { |
| 2630 | auto sparse_binding = bind_info.pImageBinds[j].pBinds[k]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2631 | // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data |
| 2632 | VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4; |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 2633 | SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, size, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2634 | VulkanTypedHandle(bind_info.pImageBinds[j].image, kVulkanObjectTypeImage)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2635 | } |
| 2636 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2637 | CB_SUBMISSION submission; |
| 2638 | const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2639 | for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2640 | RecordSubmitWaitSemaphore(submission, queue, bind_info.pWaitSemaphores[i], 0, next_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2641 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2642 | bool retire_early = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2643 | for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2644 | retire_early |= RecordSubmitSignalSemaphore(submission, queue, bind_info.pSignalSemaphores[i], 0, next_seq); |
| 2645 | } |
| 2646 | // Retire work up until this submit early, we will not see the wait that corresponds to this signal |
| 2647 | if (retire_early) { |
| 2648 | early_retire_seq = std::max(early_retire_seq, queue_state->seq + queue_state->submissions.size() + 1); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2649 | } |
| 2650 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 2651 | submission.fence = bind_idx == (bindInfoCount - 1) ? fence : VK_NULL_HANDLE; |
| 2652 | queue_state->submissions.emplace_back(std::move(submission)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | if (early_retire_seq) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2656 | RetireWorkOnQueue(queue_state, early_retire_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2657 | } |
| 2658 | } |
| 2659 | |
| 2660 | void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo, |
| 2661 | const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore, |
| 2662 | VkResult result) { |
| 2663 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2664 | auto semaphore_state = std::make_shared<SEMAPHORE_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2665 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
| 2666 | semaphore_state->signaler.second = 0; |
| 2667 | semaphore_state->signaled = false; |
| 2668 | semaphore_state->scope = kSyncScopeInternal; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2669 | semaphore_state->type = VK_SEMAPHORE_TYPE_BINARY; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2670 | semaphore_state->payload = 0; |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2671 | auto semaphore_type_create_info = LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext); |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2672 | if (semaphore_type_create_info) { |
| 2673 | semaphore_state->type = semaphore_type_create_info->semaphoreType; |
| 2674 | semaphore_state->payload = semaphore_type_create_info->initialValue; |
| 2675 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2676 | semaphoreMap[*pSemaphore] = std::move(semaphore_state); |
| 2677 | } |
| 2678 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2679 | void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type, |
| 2680 | VkSemaphoreImportFlags flags) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2681 | SEMAPHORE_STATE *sema_node = GetSemaphoreState(semaphore); |
| 2682 | if (sema_node && sema_node->scope != kSyncScopeExternalPermanent) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2683 | if ((handle_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT) && |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2684 | sema_node->scope == kSyncScopeInternal) { |
| 2685 | sema_node->scope = kSyncScopeExternalTemporary; |
| 2686 | } else { |
| 2687 | sema_node->scope = kSyncScopeExternalPermanent; |
| 2688 | } |
| 2689 | } |
| 2690 | } |
| 2691 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2692 | void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo, |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2693 | VkResult result) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2694 | auto *semaphore_state = GetSemaphoreState(pSignalInfo->semaphore); |
| 2695 | semaphore_state->payload = pSignalInfo->value; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2696 | } |
| 2697 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2698 | void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) { |
| 2699 | auto mem_info = GetDevMemState(mem); |
| 2700 | if (mem_info) { |
| 2701 | mem_info->mapped_range.offset = offset; |
| 2702 | mem_info->mapped_range.size = size; |
| 2703 | mem_info->p_driver_data = *ppData; |
| 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | void ValidationStateTracker::RetireFence(VkFence fence) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2708 | auto fence_state = GetFenceState(fence); |
| 2709 | if (fence_state && fence_state->scope == kSyncScopeInternal) { |
| 2710 | if (fence_state->signaler.first != VK_NULL_HANDLE) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2711 | // Fence signaller is a queue -- use this as proof that prior operations on that queue have completed. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2712 | RetireWorkOnQueue(GetQueueState(fence_state->signaler.first), fence_state->signaler.second); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2713 | } else { |
| 2714 | // Fence signaller is the WSI. We're not tracking what the WSI op actually /was/ in CV yet, but we need to mark |
| 2715 | // the fence as retired. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2716 | fence_state->state = FENCE_RETIRED; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2717 | } |
| 2718 | } |
| 2719 | } |
| 2720 | |
| 2721 | void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, |
| 2722 | VkBool32 waitAll, uint64_t timeout, VkResult result) { |
| 2723 | if (VK_SUCCESS != result) return; |
| 2724 | |
| 2725 | // When we know that all fences are complete we can clean/remove their CBs |
| 2726 | if ((VK_TRUE == waitAll) || (1 == fenceCount)) { |
| 2727 | for (uint32_t i = 0; i < fenceCount; i++) { |
| 2728 | RetireFence(pFences[i]); |
| 2729 | } |
| 2730 | } |
| 2731 | // NOTE : Alternate case not handled here is when some fences have completed. In |
| 2732 | // this case for app to guarantee which fences completed it will have to call |
| 2733 | // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete. |
| 2734 | } |
| 2735 | |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2736 | void ValidationStateTracker::RetireTimelineSemaphore(VkSemaphore semaphore, uint64_t until_payload) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2737 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2738 | if (semaphore_state) { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2739 | for (auto &pair : queueMap) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2740 | QUEUE_STATE &queue_state = pair.second; |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2741 | uint64_t max_seq = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2742 | for (const auto &submission : queue_state.submissions) { |
| 2743 | for (const auto &signal_semaphore : submission.signalSemaphores) { |
| 2744 | if (signal_semaphore.semaphore == semaphore && signal_semaphore.payload <= until_payload) { |
| 2745 | if (signal_semaphore.seq > max_seq) { |
| 2746 | max_seq = signal_semaphore.seq; |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2747 | } |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2748 | } |
| 2749 | } |
| 2750 | } |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2751 | if (max_seq) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2752 | RetireWorkOnQueue(&queue_state, max_seq); |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2753 | } |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2754 | } |
| 2755 | } |
| 2756 | } |
| 2757 | |
John Zulauf | f89de66 | 2020-04-13 18:57:34 -0600 | [diff] [blame] | 2758 | void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout, |
| 2759 | VkResult result) { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2760 | if (VK_SUCCESS != result) return; |
| 2761 | |
| 2762 | for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) { |
| 2763 | RetireTimelineSemaphore(pWaitInfo->pSemaphores[i], pWaitInfo->pValues[i]); |
| 2764 | } |
| 2765 | } |
| 2766 | |
John Zulauf | f89de66 | 2020-04-13 18:57:34 -0600 | [diff] [blame] | 2767 | void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout, |
| 2768 | VkResult result) { |
| 2769 | RecordWaitSemaphores(device, pWaitInfo, timeout, result); |
| 2770 | } |
| 2771 | |
| 2772 | void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, |
| 2773 | uint64_t timeout, VkResult result) { |
| 2774 | RecordWaitSemaphores(device, pWaitInfo, timeout, result); |
| 2775 | } |
| 2776 | |
Adrian Coca Lorente | c7d7610 | 2020-09-28 13:58:16 +0200 | [diff] [blame] | 2777 | void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 2778 | VkResult result) { |
| 2779 | if (VK_SUCCESS != result) return; |
| 2780 | |
| 2781 | RetireTimelineSemaphore(semaphore, *pValue); |
| 2782 | } |
| 2783 | |
| 2784 | void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 2785 | VkResult result) { |
| 2786 | RecordGetSemaphoreCounterValue(device, semaphore, pValue, result); |
| 2787 | } |
| 2788 | void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 2789 | VkResult result) { |
| 2790 | RecordGetSemaphoreCounterValue(device, semaphore, pValue, result); |
| 2791 | } |
| 2792 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2793 | void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) { |
| 2794 | if (VK_SUCCESS != result) return; |
| 2795 | RetireFence(fence); |
| 2796 | } |
| 2797 | |
| 2798 | void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkQueue queue) { |
| 2799 | // Add queue to tracking set only if it is new |
| 2800 | auto queue_is_new = queues.emplace(queue); |
| 2801 | if (queue_is_new.second == true) { |
| 2802 | QUEUE_STATE *queue_state = &queueMap[queue]; |
| 2803 | queue_state->queue = queue; |
| 2804 | queue_state->queueFamilyIndex = queue_family_index; |
| 2805 | queue_state->seq = 0; |
| 2806 | } |
| 2807 | } |
| 2808 | |
| 2809 | void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, |
| 2810 | VkQueue *pQueue) { |
| 2811 | RecordGetDeviceQueueState(queueFamilyIndex, *pQueue); |
| 2812 | } |
| 2813 | |
| 2814 | void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) { |
| 2815 | RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, *pQueue); |
| 2816 | } |
| 2817 | |
| 2818 | void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) { |
| 2819 | if (VK_SUCCESS != result) return; |
| 2820 | QUEUE_STATE *queue_state = GetQueueState(queue); |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2821 | RetireWorkOnQueue(queue_state, queue_state->seq + queue_state->submissions.size()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) { |
| 2825 | if (VK_SUCCESS != result) return; |
| 2826 | for (auto &queue : queueMap) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2827 | RetireWorkOnQueue(&queue.second, queue.second.seq + queue.second.submissions.size()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2828 | } |
| 2829 | } |
| 2830 | |
| 2831 | void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) { |
| 2832 | if (!fence) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2833 | auto fence_state = GetFenceState(fence); |
| 2834 | fence_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2835 | fenceMap.erase(fence); |
| 2836 | } |
| 2837 | |
| 2838 | void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore, |
| 2839 | const VkAllocationCallbacks *pAllocator) { |
| 2840 | if (!semaphore) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2841 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2842 | semaphore_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2843 | semaphoreMap.erase(semaphore); |
| 2844 | } |
| 2845 | |
| 2846 | void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 2847 | if (!event) return; |
John Zulauf | 4805732 | 2020-12-02 11:59:31 -0700 | [diff] [blame] | 2848 | EVENT_STATE *event_state = Get<EVENT_STATE>(event); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2849 | const VulkanTypedHandle obj_struct(event, kVulkanObjectTypeEvent); |
| 2850 | InvalidateCommandBuffers(event_state->cb_bindings, obj_struct); |
John Zulauf | 4805732 | 2020-12-02 11:59:31 -0700 | [diff] [blame] | 2851 | event_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2852 | eventMap.erase(event); |
| 2853 | } |
| 2854 | |
| 2855 | void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool, |
| 2856 | const VkAllocationCallbacks *pAllocator) { |
| 2857 | if (!queryPool) return; |
| 2858 | QUERY_POOL_STATE *qp_state = GetQueryPoolState(queryPool); |
| 2859 | const VulkanTypedHandle obj_struct(queryPool, kVulkanObjectTypeQueryPool); |
| 2860 | InvalidateCommandBuffers(qp_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2861 | qp_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2862 | queryPoolMap.erase(queryPool); |
| 2863 | } |
| 2864 | |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 2865 | void ValidationStateTracker::InsertImageMemoryRange(IMAGE_STATE *image_state, DEVICE_MEMORY_STATE *mem_info, |
| 2866 | VkDeviceSize mem_offset) { |
| 2867 | mem_info->bound_images.insert(image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2868 | } |
| 2869 | |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 2870 | void ValidationStateTracker::RemoveImageMemoryRange(IMAGE_STATE *image_state, DEVICE_MEMORY_STATE *mem_info) { |
| 2871 | mem_info->bound_images.erase(image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2872 | } |
| 2873 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2874 | void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) { |
| 2875 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 2876 | if (buffer_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2877 | // Track objects tied to memory |
| 2878 | SetMemBinding(mem, buffer_state, memoryOffset, VulkanTypedHandle(buffer, kVulkanObjectTypeBuffer)); |
| 2879 | } |
| 2880 | } |
| 2881 | |
| 2882 | void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem, |
| 2883 | VkDeviceSize memoryOffset, VkResult result) { |
| 2884 | if (VK_SUCCESS != result) return; |
| 2885 | UpdateBindBufferMemoryState(buffer, mem, memoryOffset); |
| 2886 | } |
| 2887 | |
| 2888 | void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2889 | const VkBindBufferMemoryInfo *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2890 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 2891 | UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset); |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2896 | const VkBindBufferMemoryInfo *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2897 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 2898 | UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset); |
| 2899 | } |
| 2900 | } |
| 2901 | |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2902 | void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2903 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 2904 | if (buffer_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2905 | buffer_state->memory_requirements_checked = true; |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer, |
| 2910 | VkMemoryRequirements *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2911 | RecordGetBufferMemoryRequirementsState(buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2915 | const VkBufferMemoryRequirementsInfo2 *pInfo, |
| 2916 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2917 | RecordGetBufferMemoryRequirementsState(pInfo->buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2921 | const VkBufferMemoryRequirementsInfo2 *pInfo, |
| 2922 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2923 | RecordGetBufferMemoryRequirementsState(pInfo->buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2924 | } |
| 2925 | |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2926 | void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2927 | const VkImagePlaneMemoryRequirementsInfo *plane_info = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2928 | (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2929 | IMAGE_STATE *image_state = GetImageState(image); |
| 2930 | if (image_state) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2931 | if (plane_info != nullptr) { |
| 2932 | // Multi-plane image |
| 2933 | image_state->memory_requirements_checked = false; // Each image plane needs to be checked itself |
| 2934 | if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) { |
| 2935 | image_state->plane0_memory_requirements_checked = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2936 | } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) { |
| 2937 | image_state->plane1_memory_requirements_checked = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2938 | } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) { |
| 2939 | image_state->plane2_memory_requirements_checked = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2940 | } |
| 2941 | } else { |
| 2942 | // Single Plane image |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2943 | image_state->memory_requirements_checked = true; |
| 2944 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2945 | } |
| 2946 | } |
| 2947 | |
| 2948 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image, |
| 2949 | VkMemoryRequirements *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2950 | RecordGetImageMemoryRequirementsState(image, nullptr); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2951 | } |
| 2952 | |
| 2953 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo, |
| 2954 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2955 | RecordGetImageMemoryRequirementsState(pInfo->image, pInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device, |
| 2959 | const VkImageMemoryRequirementsInfo2 *pInfo, |
| 2960 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2961 | RecordGetImageMemoryRequirementsState(pInfo->image, pInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | static void RecordGetImageSparseMemoryRequirementsState(IMAGE_STATE *image_state, |
| 2965 | VkSparseImageMemoryRequirements *sparse_image_memory_requirements) { |
| 2966 | image_state->sparse_requirements.emplace_back(*sparse_image_memory_requirements); |
| 2967 | if (sparse_image_memory_requirements->formatProperties.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 2968 | image_state->sparse_metadata_required = true; |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements( |
| 2973 | VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount, |
| 2974 | VkSparseImageMemoryRequirements *pSparseMemoryRequirements) { |
| 2975 | auto image_state = GetImageState(image); |
| 2976 | image_state->get_sparse_reqs_called = true; |
| 2977 | if (!pSparseMemoryRequirements) return; |
| 2978 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2979 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i]); |
| 2980 | } |
| 2981 | } |
| 2982 | |
| 2983 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2984 | VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount, |
| 2985 | VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2986 | auto image_state = GetImageState(pInfo->image); |
| 2987 | image_state->get_sparse_reqs_called = true; |
| 2988 | if (!pSparseMemoryRequirements) return; |
| 2989 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2990 | assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it |
| 2991 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements); |
| 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2996 | VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount, |
| 2997 | VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2998 | auto image_state = GetImageState(pInfo->image); |
| 2999 | image_state->get_sparse_reqs_called = true; |
| 3000 | if (!pSparseMemoryRequirements) return; |
| 3001 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 3002 | assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it |
| 3003 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements); |
| 3004 | } |
| 3005 | } |
| 3006 | |
| 3007 | void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, |
| 3008 | const VkAllocationCallbacks *pAllocator) { |
| 3009 | if (!shaderModule) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3010 | auto shader_module_state = GetShaderModuleState(shaderModule); |
| 3011 | shader_module_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3012 | shaderModuleMap.erase(shaderModule); |
| 3013 | } |
| 3014 | |
| 3015 | void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline, |
| 3016 | const VkAllocationCallbacks *pAllocator) { |
| 3017 | if (!pipeline) return; |
| 3018 | PIPELINE_STATE *pipeline_state = GetPipelineState(pipeline); |
| 3019 | const VulkanTypedHandle obj_struct(pipeline, kVulkanObjectTypePipeline); |
| 3020 | // Any bound cmd buffers are now invalid |
| 3021 | InvalidateCommandBuffers(pipeline_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3022 | pipeline_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3023 | pipelineMap.erase(pipeline); |
| 3024 | } |
| 3025 | |
| 3026 | void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, |
| 3027 | const VkAllocationCallbacks *pAllocator) { |
| 3028 | if (!pipelineLayout) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3029 | auto pipeline_layout_state = GetPipelineLayout(pipelineLayout); |
| 3030 | pipeline_layout_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3031 | pipelineLayoutMap.erase(pipelineLayout); |
| 3032 | } |
| 3033 | |
| 3034 | void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler, |
| 3035 | const VkAllocationCallbacks *pAllocator) { |
| 3036 | if (!sampler) return; |
| 3037 | SAMPLER_STATE *sampler_state = GetSamplerState(sampler); |
| 3038 | const VulkanTypedHandle obj_struct(sampler, kVulkanObjectTypeSampler); |
| 3039 | // Any bound cmd buffers are now invalid |
| 3040 | if (sampler_state) { |
| 3041 | InvalidateCommandBuffers(sampler_state->cb_bindings, obj_struct); |
Yuly Novikov | 424cdd5 | 2020-05-26 16:45:12 -0400 | [diff] [blame] | 3042 | |
| 3043 | if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT || |
| 3044 | sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) { |
| 3045 | custom_border_color_sampler_count--; |
| 3046 | } |
| 3047 | |
| 3048 | sampler_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3049 | } |
| 3050 | samplerMap.erase(sampler); |
| 3051 | } |
| 3052 | |
| 3053 | void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, |
| 3054 | const VkAllocationCallbacks *pAllocator) { |
| 3055 | if (!descriptorSetLayout) return; |
| 3056 | auto layout_it = descriptorSetLayoutMap.find(descriptorSetLayout); |
| 3057 | if (layout_it != descriptorSetLayoutMap.end()) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 3058 | layout_it->second.get()->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3059 | descriptorSetLayoutMap.erase(layout_it); |
| 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, |
| 3064 | const VkAllocationCallbacks *pAllocator) { |
| 3065 | if (!descriptorPool) return; |
| 3066 | DESCRIPTOR_POOL_STATE *desc_pool_state = GetDescriptorPoolState(descriptorPool); |
| 3067 | const VulkanTypedHandle obj_struct(descriptorPool, kVulkanObjectTypeDescriptorPool); |
| 3068 | if (desc_pool_state) { |
| 3069 | // Any bound cmd buffers are now invalid |
| 3070 | InvalidateCommandBuffers(desc_pool_state->cb_bindings, obj_struct); |
| 3071 | // Free sets that were in this pool |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 3072 | for (auto *ds : desc_pool_state->sets) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3073 | FreeDescriptorSet(ds); |
| 3074 | } |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3075 | desc_pool_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3076 | descriptorPoolMap.erase(descriptorPool); |
| 3077 | } |
| 3078 | } |
| 3079 | |
| 3080 | // Free all command buffers in given list, removing all references/links to them using ResetCommandBufferState |
| 3081 | void ValidationStateTracker::FreeCommandBufferStates(COMMAND_POOL_STATE *pool_state, const uint32_t command_buffer_count, |
| 3082 | const VkCommandBuffer *command_buffers) { |
| 3083 | for (uint32_t i = 0; i < command_buffer_count; i++) { |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3084 | // Allow any derived class to clean up command buffer state |
| 3085 | if (command_buffer_free_callback) { |
| 3086 | (*command_buffer_free_callback)(command_buffers[i]); |
| 3087 | } |
| 3088 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3089 | auto cb_state = GetCBState(command_buffers[i]); |
| 3090 | // Remove references to command buffer's state and delete |
| 3091 | if (cb_state) { |
| 3092 | // reset prior to delete, removing various references to it. |
| 3093 | // TODO: fix this, it's insane. |
| 3094 | ResetCommandBufferState(cb_state->commandBuffer); |
| 3095 | // Remove the cb_state's references from COMMAND_POOL_STATEs |
| 3096 | pool_state->commandBuffers.erase(command_buffers[i]); |
| 3097 | // Remove the cb debug labels |
| 3098 | EraseCmdDebugUtilsLabel(report_data, cb_state->commandBuffer); |
| 3099 | // Remove CBState from CB map |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3100 | cb_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3101 | commandBufferMap.erase(cb_state->commandBuffer); |
| 3102 | } |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, |
| 3107 | uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3108 | auto pool = GetCommandPoolState(commandPool); |
| 3109 | FreeCommandBufferStates(pool, commandBufferCount, pCommandBuffers); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo, |
| 3113 | const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool, |
| 3114 | VkResult result) { |
| 3115 | if (VK_SUCCESS != result) return; |
sfricke-samsung | c154337 | 2020-08-18 22:37:27 -0700 | [diff] [blame] | 3116 | VkCommandPool command_pool = *pCommandPool; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3117 | auto cmd_pool_state = std::make_shared<COMMAND_POOL_STATE>(); |
sfricke-samsung | c154337 | 2020-08-18 22:37:27 -0700 | [diff] [blame] | 3118 | cmd_pool_state->commandPool = command_pool; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3119 | cmd_pool_state->createFlags = pCreateInfo->flags; |
| 3120 | cmd_pool_state->queueFamilyIndex = pCreateInfo->queueFamilyIndex; |
sfricke-samsung | 0c45edc | 2020-07-01 22:19:53 -0700 | [diff] [blame] | 3121 | cmd_pool_state->unprotected = ((pCreateInfo->flags & VK_COMMAND_POOL_CREATE_PROTECTED_BIT) == 0); |
sfricke-samsung | c154337 | 2020-08-18 22:37:27 -0700 | [diff] [blame] | 3122 | commandPoolMap[command_pool] = std::move(cmd_pool_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo, |
| 3126 | const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool, |
| 3127 | VkResult result) { |
| 3128 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3129 | auto query_pool_state = std::make_shared<QUERY_POOL_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3130 | query_pool_state->createInfo = *pCreateInfo; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3131 | query_pool_state->pool = *pQueryPool; |
| 3132 | if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 3133 | const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext); |
Mark Lobodzinski | 7e948e4 | 2020-09-09 10:23:36 -0600 | [diff] [blame] | 3134 | query_pool_state->perf_counter_index_count = perf->counterIndexCount; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3135 | |
Mark Lobodzinski | 7e948e4 | 2020-09-09 10:23:36 -0600 | [diff] [blame] | 3136 | const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex]; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3137 | for (uint32_t i = 0; i < perf->counterIndexCount; i++) { |
| 3138 | const auto &counter = counters.counters[perf->pCounterIndices[i]]; |
| 3139 | switch (counter.scope) { |
| 3140 | case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR: |
| 3141 | query_pool_state->has_perf_scope_command_buffer = true; |
| 3142 | break; |
| 3143 | case VK_QUERY_SCOPE_RENDER_PASS_KHR: |
| 3144 | query_pool_state->has_perf_scope_render_pass = true; |
| 3145 | break; |
| 3146 | default: |
| 3147 | break; |
| 3148 | } |
| 3149 | } |
| 3150 | |
| 3151 | DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->phys_device, perf, |
| 3152 | &query_pool_state->n_performance_passes); |
| 3153 | } |
| 3154 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3155 | queryPoolMap[*pQueryPool] = std::move(query_pool_state); |
| 3156 | |
| 3157 | QueryObject query_obj{*pQueryPool, 0u}; |
| 3158 | for (uint32_t i = 0; i < pCreateInfo->queryCount; ++i) { |
| 3159 | query_obj.query = i; |
| 3160 | queryToStateMap[query_obj] = QUERYSTATE_UNKNOWN; |
| 3161 | } |
| 3162 | } |
| 3163 | |
| 3164 | void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool, |
| 3165 | const VkAllocationCallbacks *pAllocator) { |
| 3166 | if (!commandPool) return; |
| 3167 | COMMAND_POOL_STATE *cp_state = GetCommandPoolState(commandPool); |
| 3168 | // Remove cmdpool from cmdpoolmap, after freeing layer data for the command buffers |
| 3169 | // "When a pool is destroyed, all command buffers allocated from the pool are freed." |
| 3170 | if (cp_state) { |
| 3171 | // Create a vector, as FreeCommandBufferStates deletes from cp_state->commandBuffers during iteration. |
| 3172 | std::vector<VkCommandBuffer> cb_vec{cp_state->commandBuffers.begin(), cp_state->commandBuffers.end()}; |
| 3173 | FreeCommandBufferStates(cp_state, static_cast<uint32_t>(cb_vec.size()), cb_vec.data()); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3174 | cp_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3175 | commandPoolMap.erase(commandPool); |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool, |
| 3180 | VkCommandPoolResetFlags flags, VkResult result) { |
| 3181 | if (VK_SUCCESS != result) return; |
| 3182 | // Reset all of the CBs allocated from this pool |
| 3183 | auto command_pool_state = GetCommandPoolState(commandPool); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3184 | for (auto cmd_buffer : command_pool_state->commandBuffers) { |
| 3185 | ResetCommandBufferState(cmd_buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, |
| 3190 | VkResult result) { |
| 3191 | for (uint32_t i = 0; i < fenceCount; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3192 | auto fence_state = GetFenceState(pFences[i]); |
| 3193 | if (fence_state) { |
| 3194 | if (fence_state->scope == kSyncScopeInternal) { |
| 3195 | fence_state->state = FENCE_UNSIGNALED; |
| 3196 | } else if (fence_state->scope == kSyncScopeExternalTemporary) { |
| 3197 | fence_state->scope = kSyncScopeInternal; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3198 | } |
| 3199 | } |
| 3200 | } |
| 3201 | } |
| 3202 | |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3203 | // For given cb_nodes, invalidate them and track object causing invalidation. |
| 3204 | // InvalidateCommandBuffers and InvalidateLinkedCommandBuffers are essentially |
| 3205 | // the same, except one takes a map and one takes a set, and InvalidateCommandBuffers |
| 3206 | // can also unlink objects from command buffers. |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 3207 | void ValidationStateTracker::InvalidateCommandBuffers(BASE_NODE::BindingsType &cb_nodes, |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3208 | const VulkanTypedHandle &obj, bool unlink) { |
| 3209 | for (const auto &cb_node_pair : cb_nodes) { |
| 3210 | auto &cb_node = cb_node_pair.first; |
| 3211 | if (cb_node->state == CB_RECORDING) { |
| 3212 | cb_node->state = CB_INVALID_INCOMPLETE; |
| 3213 | } else if (cb_node->state == CB_RECORDED) { |
| 3214 | cb_node->state = CB_INVALID_COMPLETE; |
| 3215 | } |
| 3216 | cb_node->broken_bindings.push_back(obj); |
| 3217 | |
| 3218 | // if secondary, then propagate the invalidation to the primaries that will call us. |
| 3219 | if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
| 3220 | InvalidateLinkedCommandBuffers(cb_node->linkedCommandBuffers, obj); |
| 3221 | } |
| 3222 | if (unlink) { |
| 3223 | int index = cb_node_pair.second; |
| 3224 | assert(cb_node->object_bindings[index] == obj); |
| 3225 | cb_node->object_bindings[index] = VulkanTypedHandle(); |
| 3226 | } |
| 3227 | } |
| 3228 | if (unlink) { |
| 3229 | cb_nodes.clear(); |
| 3230 | } |
| 3231 | } |
| 3232 | |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 3233 | void ValidationStateTracker::InvalidateLinkedCommandBuffers(layer_data::unordered_set<CMD_BUFFER_STATE *> &cb_nodes, |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3234 | const VulkanTypedHandle &obj) { |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 3235 | for (auto *cb_node : cb_nodes) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3236 | if (cb_node->state == CB_RECORDING) { |
| 3237 | cb_node->state = CB_INVALID_INCOMPLETE; |
| 3238 | } else if (cb_node->state == CB_RECORDED) { |
| 3239 | cb_node->state = CB_INVALID_COMPLETE; |
| 3240 | } |
| 3241 | cb_node->broken_bindings.push_back(obj); |
| 3242 | |
| 3243 | // if secondary, then propagate the invalidation to the primaries that will call us. |
| 3244 | if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3245 | InvalidateLinkedCommandBuffers(cb_node->linkedCommandBuffers, obj); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3246 | } |
| 3247 | } |
| 3248 | } |
| 3249 | |
| 3250 | void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, |
| 3251 | const VkAllocationCallbacks *pAllocator) { |
| 3252 | if (!framebuffer) return; |
| 3253 | FRAMEBUFFER_STATE *framebuffer_state = GetFramebufferState(framebuffer); |
| 3254 | const VulkanTypedHandle obj_struct(framebuffer, kVulkanObjectTypeFramebuffer); |
| 3255 | InvalidateCommandBuffers(framebuffer_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3256 | framebuffer_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3257 | frameBufferMap.erase(framebuffer); |
| 3258 | } |
| 3259 | |
| 3260 | void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass, |
| 3261 | const VkAllocationCallbacks *pAllocator) { |
| 3262 | if (!renderPass) return; |
| 3263 | RENDER_PASS_STATE *rp_state = GetRenderPassState(renderPass); |
| 3264 | const VulkanTypedHandle obj_struct(renderPass, kVulkanObjectTypeRenderPass); |
| 3265 | InvalidateCommandBuffers(rp_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3266 | rp_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3267 | renderPassMap.erase(renderPass); |
| 3268 | } |
| 3269 | |
| 3270 | void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo, |
| 3271 | const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) { |
| 3272 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3273 | auto fence_state = std::make_shared<FENCE_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3274 | fence_state->fence = *pFence; |
| 3275 | fence_state->createInfo = *pCreateInfo; |
| 3276 | fence_state->state = (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) ? FENCE_RETIRED : FENCE_UNSIGNALED; |
| 3277 | fenceMap[*pFence] = std::move(fence_state); |
| 3278 | } |
| 3279 | |
| 3280 | bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 3281 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 3282 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3283 | void *cgpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3284 | // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use. |
| 3285 | create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data); |
| 3286 | cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis |
| 3287 | cgpl_state->pipe_state.reserve(count); |
| 3288 | for (uint32_t i = 0; i < count; i++) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3289 | cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 3290 | (cgpl_state->pipe_state)[i]->initGraphicsPipeline(this, &pCreateInfos[i], GetRenderPassShared(pCreateInfos[i].renderPass)); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3291 | (cgpl_state->pipe_state)[i]->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3292 | } |
| 3293 | return false; |
| 3294 | } |
| 3295 | |
| 3296 | void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 3297 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 3298 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 3299 | VkResult result, void *cgpl_state_data) { |
| 3300 | create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data); |
| 3301 | // This API may create pipelines regardless of the return value |
| 3302 | for (uint32_t i = 0; i < count; i++) { |
| 3303 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3304 | (cgpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3305 | pipelineMap[pPipelines[i]] = std::move((cgpl_state->pipe_state)[i]); |
| 3306 | } |
| 3307 | } |
| 3308 | cgpl_state->pipe_state.clear(); |
| 3309 | } |
| 3310 | |
| 3311 | bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 3312 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 3313 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3314 | void *ccpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3315 | auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data); |
| 3316 | ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis |
| 3317 | ccpl_state->pipe_state.reserve(count); |
| 3318 | for (uint32_t i = 0; i < count; i++) { |
| 3319 | // Create and initialize internal tracking data structure |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3320 | ccpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3321 | ccpl_state->pipe_state.back()->initComputePipeline(this, &pCreateInfos[i]); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3322 | ccpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3323 | } |
| 3324 | return false; |
| 3325 | } |
| 3326 | |
| 3327 | void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 3328 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 3329 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 3330 | VkResult result, void *ccpl_state_data) { |
| 3331 | create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data); |
| 3332 | |
| 3333 | // This API may create pipelines regardless of the return value |
| 3334 | for (uint32_t i = 0; i < count; i++) { |
| 3335 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3336 | (ccpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3337 | pipelineMap[pPipelines[i]] = std::move((ccpl_state->pipe_state)[i]); |
| 3338 | } |
| 3339 | } |
| 3340 | ccpl_state->pipe_state.clear(); |
| 3341 | } |
| 3342 | |
| 3343 | bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, |
| 3344 | uint32_t count, |
| 3345 | const VkRayTracingPipelineCreateInfoNV *pCreateInfos, |
| 3346 | const VkAllocationCallbacks *pAllocator, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3347 | VkPipeline *pPipelines, void *crtpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3348 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data); |
| 3349 | crtpl_state->pipe_state.reserve(count); |
| 3350 | for (uint32_t i = 0; i < count; i++) { |
| 3351 | // Create and initialize internal tracking data structure |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3352 | crtpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 3353 | crtpl_state->pipe_state.back()->initRayTracingPipeline(this, &pCreateInfos[i]); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3354 | crtpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3355 | } |
| 3356 | return false; |
| 3357 | } |
| 3358 | |
| 3359 | void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV( |
| 3360 | VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos, |
| 3361 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) { |
| 3362 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data); |
| 3363 | // This API may create pipelines regardless of the return value |
| 3364 | for (uint32_t i = 0; i < count; i++) { |
| 3365 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3366 | (crtpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3367 | pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]); |
| 3368 | } |
| 3369 | } |
| 3370 | crtpl_state->pipe_state.clear(); |
| 3371 | } |
| 3372 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3373 | bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation, |
| 3374 | VkPipelineCache pipelineCache, uint32_t count, |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 3375 | const VkRayTracingPipelineCreateInfoKHR *pCreateInfos, |
| 3376 | const VkAllocationCallbacks *pAllocator, |
| 3377 | VkPipeline *pPipelines, void *crtpl_state_data) const { |
| 3378 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
| 3379 | crtpl_state->pipe_state.reserve(count); |
| 3380 | for (uint32_t i = 0; i < count; i++) { |
| 3381 | // Create and initialize internal tracking data structure |
| 3382 | crtpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
| 3383 | crtpl_state->pipe_state.back()->initRayTracingPipeline(this, &pCreateInfos[i]); |
| 3384 | crtpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
| 3385 | } |
| 3386 | return false; |
| 3387 | } |
| 3388 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3389 | void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation, |
| 3390 | VkPipelineCache pipelineCache, uint32_t count, |
| 3391 | const VkRayTracingPipelineCreateInfoKHR *pCreateInfos, |
| 3392 | const VkAllocationCallbacks *pAllocator, |
| 3393 | VkPipeline *pPipelines, VkResult result, |
| 3394 | void *crtpl_state_data) { |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 3395 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
| 3396 | // This API may create pipelines regardless of the return value |
| 3397 | for (uint32_t i = 0; i < count; i++) { |
| 3398 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3399 | (crtpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3400 | pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]); |
| 3401 | } |
| 3402 | } |
| 3403 | crtpl_state->pipe_state.clear(); |
| 3404 | } |
| 3405 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3406 | void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, |
| 3407 | const VkAllocationCallbacks *pAllocator, VkSampler *pSampler, |
| 3408 | VkResult result) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3409 | samplerMap[*pSampler] = std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3410 | if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT || |
| 3411 | pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) { |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 3412 | custom_border_color_sampler_count++; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3413 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device, |
| 3417 | const VkDescriptorSetLayoutCreateInfo *pCreateInfo, |
| 3418 | const VkAllocationCallbacks *pAllocator, |
| 3419 | VkDescriptorSetLayout *pSetLayout, VkResult result) { |
| 3420 | if (VK_SUCCESS != result) return; |
| 3421 | descriptorSetLayoutMap[*pSetLayout] = std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout); |
| 3422 | } |
| 3423 | |
| 3424 | // For repeatable sorting, not very useful for "memory in range" search |
| 3425 | struct PushConstantRangeCompare { |
| 3426 | bool operator()(const VkPushConstantRange *lhs, const VkPushConstantRange *rhs) const { |
| 3427 | if (lhs->offset == rhs->offset) { |
| 3428 | if (lhs->size == rhs->size) { |
| 3429 | // The comparison is arbitrary, but avoids false aliasing by comparing all fields. |
| 3430 | return lhs->stageFlags < rhs->stageFlags; |
| 3431 | } |
| 3432 | // If the offsets are the same then sorting by the end of range is useful for validation |
| 3433 | return lhs->size < rhs->size; |
| 3434 | } |
| 3435 | return lhs->offset < rhs->offset; |
| 3436 | } |
| 3437 | }; |
| 3438 | |
| 3439 | static PushConstantRangesDict push_constant_ranges_dict; |
| 3440 | |
| 3441 | PushConstantRangesId GetCanonicalId(const VkPipelineLayoutCreateInfo *info) { |
| 3442 | if (!info->pPushConstantRanges) { |
| 3443 | // Hand back the empty entry (creating as needed)... |
| 3444 | return push_constant_ranges_dict.look_up(PushConstantRanges()); |
| 3445 | } |
| 3446 | |
| 3447 | // Sort the input ranges to ensure equivalent ranges map to the same id |
| 3448 | std::set<const VkPushConstantRange *, PushConstantRangeCompare> sorted; |
| 3449 | for (uint32_t i = 0; i < info->pushConstantRangeCount; i++) { |
| 3450 | sorted.insert(info->pPushConstantRanges + i); |
| 3451 | } |
| 3452 | |
Jeremy Hayes | f34b9fb | 2019-12-06 09:37:03 -0700 | [diff] [blame] | 3453 | PushConstantRanges ranges; |
| 3454 | ranges.reserve(sorted.size()); |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 3455 | for (const auto *range : sorted) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3456 | ranges.emplace_back(*range); |
| 3457 | } |
| 3458 | return push_constant_ranges_dict.look_up(std::move(ranges)); |
| 3459 | } |
| 3460 | |
| 3461 | // Dictionary of canoncial form of the pipeline set layout of descriptor set layouts |
| 3462 | static PipelineLayoutSetLayoutsDict pipeline_layout_set_layouts_dict; |
| 3463 | |
| 3464 | // Dictionary of canonical form of the "compatible for set" records |
| 3465 | static PipelineLayoutCompatDict pipeline_layout_compat_dict; |
| 3466 | |
| 3467 | static PipelineLayoutCompatId GetCanonicalId(const uint32_t set_index, const PushConstantRangesId pcr_id, |
| 3468 | const PipelineLayoutSetLayoutsId set_layouts_id) { |
| 3469 | return pipeline_layout_compat_dict.look_up(PipelineLayoutCompatDef(set_index, pcr_id, set_layouts_id)); |
| 3470 | } |
| 3471 | |
| 3472 | void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo, |
| 3473 | const VkAllocationCallbacks *pAllocator, |
| 3474 | VkPipelineLayout *pPipelineLayout, VkResult result) { |
| 3475 | if (VK_SUCCESS != result) return; |
| 3476 | |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3477 | auto pipeline_layout_state = std::make_shared<PIPELINE_LAYOUT_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3478 | pipeline_layout_state->layout = *pPipelineLayout; |
| 3479 | pipeline_layout_state->set_layouts.resize(pCreateInfo->setLayoutCount); |
| 3480 | PipelineLayoutSetLayoutsDef set_layouts(pCreateInfo->setLayoutCount); |
| 3481 | for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 3482 | pipeline_layout_state->set_layouts[i] = GetDescriptorSetLayoutShared(pCreateInfo->pSetLayouts[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3483 | set_layouts[i] = pipeline_layout_state->set_layouts[i]->GetLayoutId(); |
| 3484 | } |
| 3485 | |
| 3486 | // Get canonical form IDs for the "compatible for set" contents |
| 3487 | pipeline_layout_state->push_constant_ranges = GetCanonicalId(pCreateInfo); |
| 3488 | auto set_layouts_id = pipeline_layout_set_layouts_dict.look_up(set_layouts); |
| 3489 | pipeline_layout_state->compat_for_set.reserve(pCreateInfo->setLayoutCount); |
| 3490 | |
| 3491 | // Create table of "compatible for set N" cannonical forms for trivial accept validation |
| 3492 | for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) { |
| 3493 | pipeline_layout_state->compat_for_set.emplace_back( |
| 3494 | GetCanonicalId(i, pipeline_layout_state->push_constant_ranges, set_layouts_id)); |
| 3495 | } |
| 3496 | pipelineLayoutMap[*pPipelineLayout] = std::move(pipeline_layout_state); |
| 3497 | } |
| 3498 | |
| 3499 | void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo, |
| 3500 | const VkAllocationCallbacks *pAllocator, |
| 3501 | VkDescriptorPool *pDescriptorPool, VkResult result) { |
| 3502 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3503 | descriptorPoolMap[*pDescriptorPool] = std::make_shared<DESCRIPTOR_POOL_STATE>(*pDescriptorPool, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, |
| 3507 | VkDescriptorPoolResetFlags flags, VkResult result) { |
| 3508 | if (VK_SUCCESS != result) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3509 | DESCRIPTOR_POOL_STATE *pool = GetDescriptorPoolState(descriptorPool); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3510 | // TODO: validate flags |
| 3511 | // For every set off of this pool, clear it, remove from setMap, and free cvdescriptorset::DescriptorSet |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 3512 | for (auto *ds : pool->sets) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3513 | FreeDescriptorSet(ds); |
| 3514 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3515 | pool->sets.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3516 | // Reset available count for each type and available sets for this pool |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3517 | for (auto it = pool->availableDescriptorTypeCount.begin(); it != pool->availableDescriptorTypeCount.end(); ++it) { |
| 3518 | pool->availableDescriptorTypeCount[it->first] = pool->maxDescriptorTypeCount[it->first]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3519 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3520 | pool->availableSets = pool->maxSets; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3521 | } |
| 3522 | |
| 3523 | bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device, |
| 3524 | const VkDescriptorSetAllocateInfo *pAllocateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3525 | VkDescriptorSet *pDescriptorSets, void *ads_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3526 | // Always update common data |
| 3527 | cvdescriptorset::AllocateDescriptorSetsData *ads_state = |
| 3528 | reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data); |
| 3529 | UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state); |
| 3530 | |
| 3531 | return false; |
| 3532 | } |
| 3533 | |
| 3534 | // Allocation state was good and call down chain was made so update state based on allocating descriptor sets |
| 3535 | void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, |
| 3536 | VkDescriptorSet *pDescriptorSets, VkResult result, |
| 3537 | void *ads_state_data) { |
| 3538 | if (VK_SUCCESS != result) return; |
| 3539 | // All the updates are contained in a single cvdescriptorset function |
| 3540 | cvdescriptorset::AllocateDescriptorSetsData *ads_state = |
| 3541 | reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data); |
| 3542 | PerformAllocateDescriptorSets(pAllocateInfo, pDescriptorSets, ads_state); |
| 3543 | } |
| 3544 | |
| 3545 | void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, |
| 3546 | const VkDescriptorSet *pDescriptorSets) { |
| 3547 | DESCRIPTOR_POOL_STATE *pool_state = GetDescriptorPoolState(descriptorPool); |
| 3548 | // Update available descriptor sets in pool |
| 3549 | pool_state->availableSets += count; |
| 3550 | |
| 3551 | // For each freed descriptor add its resources back into the pool as available and remove from pool and setMap |
| 3552 | for (uint32_t i = 0; i < count; ++i) { |
| 3553 | if (pDescriptorSets[i] != VK_NULL_HANDLE) { |
| 3554 | auto descriptor_set = setMap[pDescriptorSets[i]].get(); |
| 3555 | uint32_t type_index = 0, descriptor_count = 0; |
| 3556 | for (uint32_t j = 0; j < descriptor_set->GetBindingCount(); ++j) { |
| 3557 | type_index = static_cast<uint32_t>(descriptor_set->GetTypeFromIndex(j)); |
| 3558 | descriptor_count = descriptor_set->GetDescriptorCountFromIndex(j); |
| 3559 | pool_state->availableDescriptorTypeCount[type_index] += descriptor_count; |
| 3560 | } |
| 3561 | FreeDescriptorSet(descriptor_set); |
| 3562 | pool_state->sets.erase(descriptor_set); |
| 3563 | } |
| 3564 | } |
| 3565 | } |
| 3566 | |
| 3567 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, |
| 3568 | const VkWriteDescriptorSet *pDescriptorWrites, |
| 3569 | uint32_t descriptorCopyCount, |
| 3570 | const VkCopyDescriptorSet *pDescriptorCopies) { |
| 3571 | cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, |
| 3572 | pDescriptorCopies); |
| 3573 | } |
| 3574 | |
| 3575 | void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo, |
| 3576 | VkCommandBuffer *pCommandBuffer, VkResult result) { |
| 3577 | if (VK_SUCCESS != result) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3578 | auto pool = GetCommandPoolShared(pCreateInfo->commandPool); |
| 3579 | if (pool) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3580 | for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) { |
| 3581 | // Add command buffer to its commandPool map |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3582 | pool->commandBuffers.insert(pCommandBuffer[i]); |
| 3583 | auto cb_state = std::make_shared<CMD_BUFFER_STATE>(); |
| 3584 | cb_state->createInfo = *pCreateInfo; |
| 3585 | cb_state->command_pool = pool; |
| 3586 | cb_state->unprotected = pool->unprotected; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3587 | // Add command buffer to map |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3588 | commandBufferMap[pCommandBuffer[i]] = std::move(cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3589 | ResetCommandBufferState(pCommandBuffer[i]); |
| 3590 | } |
| 3591 | } |
| 3592 | } |
| 3593 | |
| 3594 | // Add bindings between the given cmd buffer & framebuffer and the framebuffer's children |
| 3595 | void ValidationStateTracker::AddFramebufferBinding(CMD_BUFFER_STATE *cb_state, FRAMEBUFFER_STATE *fb_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3596 | AddCommandBufferBinding(fb_state->cb_bindings, VulkanTypedHandle(fb_state->framebuffer, kVulkanObjectTypeFramebuffer, fb_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3597 | cb_state); |
Mark Lobodzinski | 544b3dd | 2019-12-03 14:44:54 -0700 | [diff] [blame] | 3598 | // If imageless fb, skip fb binding |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3599 | if (!fb_state || fb_state->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3600 | const uint32_t attachment_count = fb_state->createInfo.attachmentCount; |
| 3601 | for (uint32_t attachment = 0; attachment < attachment_count; ++attachment) { |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3602 | auto view_state = GetActiveAttachmentImageViewState(cb_state, attachment); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3603 | if (view_state) { |
| 3604 | AddCommandBufferBindingImageView(cb_state, view_state); |
| 3605 | } |
| 3606 | } |
| 3607 | } |
| 3608 | |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3609 | void UpdateSubpassAttachments(const safe_VkSubpassDescription2 &subpass, std::vector<SUBPASS_INFO> &subpasses) { |
| 3610 | for (uint32_t index = 0; index < subpass.inputAttachmentCount; ++index) { |
| 3611 | const uint32_t attachment_index = subpass.pInputAttachments[index].attachment; |
| 3612 | if (attachment_index != VK_ATTACHMENT_UNUSED) { |
| 3613 | subpasses[attachment_index].used = true; |
| 3614 | subpasses[attachment_index].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; |
| 3615 | subpasses[attachment_index].layout = subpass.pInputAttachments[index].layout; |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | for (uint32_t index = 0; index < subpass.colorAttachmentCount; ++index) { |
| 3620 | const uint32_t attachment_index = subpass.pColorAttachments[index].attachment; |
| 3621 | if (attachment_index != VK_ATTACHMENT_UNUSED) { |
| 3622 | subpasses[attachment_index].used = true; |
| 3623 | subpasses[attachment_index].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 3624 | subpasses[attachment_index].layout = subpass.pColorAttachments[index].layout; |
| 3625 | } |
| 3626 | if (subpass.pResolveAttachments) { |
| 3627 | const uint32_t attachment_index2 = subpass.pResolveAttachments[index].attachment; |
| 3628 | if (attachment_index2 != VK_ATTACHMENT_UNUSED) { |
| 3629 | subpasses[attachment_index2].used = true; |
| 3630 | subpasses[attachment_index2].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 3631 | subpasses[attachment_index2].layout = subpass.pResolveAttachments[index].layout; |
| 3632 | } |
| 3633 | } |
| 3634 | } |
| 3635 | |
| 3636 | if (subpass.pDepthStencilAttachment) { |
| 3637 | const uint32_t attachment_index = subpass.pDepthStencilAttachment->attachment; |
| 3638 | if (attachment_index != VK_ATTACHMENT_UNUSED) { |
| 3639 | subpasses[attachment_index].used = true; |
| 3640 | subpasses[attachment_index].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 3641 | subpasses[attachment_index].layout = subpass.pDepthStencilAttachment->layout; |
| 3642 | } |
| 3643 | } |
| 3644 | } |
| 3645 | |
| 3646 | void UpdateAttachmentsView(ValidationStateTracker &tracker, CMD_BUFFER_STATE &cb_state, const FRAMEBUFFER_STATE &framebuffer, |
| 3647 | const VkRenderPassBeginInfo *pRenderPassBegin) { |
| 3648 | auto &attachments = *(cb_state.active_attachments.get()); |
| 3649 | const bool imageless = (framebuffer.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) ? true : false; |
| 3650 | const VkRenderPassAttachmentBeginInfo *attachment_info_struct = nullptr; |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 3651 | if (pRenderPassBegin) attachment_info_struct = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3652 | |
| 3653 | for (uint32_t i = 0; i < attachments.size(); ++i) { |
| 3654 | if (imageless) { |
| 3655 | if (attachment_info_struct && i < attachment_info_struct->attachmentCount) { |
| 3656 | auto res = cb_state.attachments_view_states.insert( |
| 3657 | tracker.GetShared<IMAGE_VIEW_STATE>(attachment_info_struct->pAttachments[i])); |
| 3658 | attachments[i] = res.first->get(); |
| 3659 | } |
| 3660 | } else { |
| 3661 | auto res = cb_state.attachments_view_states.insert(framebuffer.attachments_view_state[i]); |
| 3662 | attachments[i] = res.first->get(); |
| 3663 | } |
| 3664 | } |
| 3665 | } |
| 3666 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3667 | void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, |
| 3668 | const VkCommandBufferBeginInfo *pBeginInfo) { |
| 3669 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3670 | if (!cb_state) return; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3671 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3672 | if (CB_RECORDED == cb_state->state || CB_INVALID_COMPLETE == cb_state->state) { |
| 3673 | ResetCommandBufferState(commandBuffer); |
| 3674 | } |
| 3675 | // Set updated state here in case implicit reset occurs above |
| 3676 | cb_state->state = CB_RECORDING; |
| 3677 | cb_state->beginInfo = *pBeginInfo; |
Tony-LunarG | 3c287f6 | 2020-12-17 12:39:49 -0700 | [diff] [blame] | 3678 | if (cb_state->beginInfo.pInheritanceInfo && (cb_state->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3679 | cb_state->inheritanceInfo = *(cb_state->beginInfo.pInheritanceInfo); |
| 3680 | cb_state->beginInfo.pInheritanceInfo = &cb_state->inheritanceInfo; |
| 3681 | // If we are a secondary command-buffer and inheriting. Update the items we should inherit. |
| 3682 | if ((cb_state->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) && |
| 3683 | (cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) { |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 3684 | cb_state->activeRenderPass = GetShared<RENDER_PASS_STATE>(cb_state->beginInfo.pInheritanceInfo->renderPass); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3685 | cb_state->activeSubpass = cb_state->beginInfo.pInheritanceInfo->subpass; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3686 | |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 3687 | if (cb_state->beginInfo.pInheritanceInfo->framebuffer) { |
| 3688 | cb_state->activeFramebuffer = GetShared<FRAMEBUFFER_STATE>(cb_state->beginInfo.pInheritanceInfo->framebuffer); |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3689 | cb_state->active_subpasses = nullptr; |
| 3690 | cb_state->active_attachments = nullptr; |
| 3691 | |
| 3692 | if (cb_state->activeFramebuffer) { |
| 3693 | cb_state->framebuffers.insert(cb_state->activeFramebuffer); |
| 3694 | |
| 3695 | // Set cb_state->active_subpasses |
| 3696 | cb_state->active_subpasses = |
| 3697 | std::make_shared<std::vector<SUBPASS_INFO>>(cb_state->activeFramebuffer->createInfo.attachmentCount); |
| 3698 | const auto &subpass = cb_state->activeRenderPass->createInfo.pSubpasses[cb_state->activeSubpass]; |
| 3699 | UpdateSubpassAttachments(subpass, *cb_state->active_subpasses); |
| 3700 | |
| 3701 | // Set cb_state->active_attachments & cb_state->attachments_view_states |
| 3702 | cb_state->active_attachments = |
| 3703 | std::make_shared<std::vector<IMAGE_VIEW_STATE *>>(cb_state->activeFramebuffer->createInfo.attachmentCount); |
| 3704 | UpdateAttachmentsView(*this, *cb_state, *cb_state->activeFramebuffer, nullptr); |
| 3705 | |
| 3706 | // Connect this framebuffer and its children to this cmdBuffer |
| 3707 | AddFramebufferBinding(cb_state, cb_state->activeFramebuffer.get()); |
| 3708 | } |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 3709 | } |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3710 | |
| 3711 | // Check for VkCommandBufferInheritanceViewportScissorInfoNV (VK_NV_inherited_viewport_scissor) |
| 3712 | auto p_inherited_viewport_scissor_info = |
| 3713 | LvlFindInChain<VkCommandBufferInheritanceViewportScissorInfoNV>(cb_state->beginInfo.pInheritanceInfo->pNext); |
| 3714 | if (p_inherited_viewport_scissor_info != nullptr && p_inherited_viewport_scissor_info->viewportScissor2D) { |
| 3715 | auto pViewportDepths = p_inherited_viewport_scissor_info->pViewportDepths; |
| 3716 | cb_state->inheritedViewportDepths.assign( |
| 3717 | pViewportDepths, pViewportDepths + p_inherited_viewport_scissor_info->viewportDepthCount); |
| 3718 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3719 | } |
| 3720 | } |
| 3721 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 3722 | auto chained_device_group_struct = LvlFindInChain<VkDeviceGroupCommandBufferBeginInfo>(pBeginInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3723 | if (chained_device_group_struct) { |
| 3724 | cb_state->initial_device_mask = chained_device_group_struct->deviceMask; |
| 3725 | } else { |
| 3726 | cb_state->initial_device_mask = (1 << physical_device_count) - 1; |
| 3727 | } |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3728 | |
| 3729 | cb_state->performance_lock_acquired = performance_lock_acquired; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) { |
| 3733 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3734 | if (!cb_state) return; |
| 3735 | // Cached validation is specific to a specific recording of a specific command buffer. |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 3736 | for (auto *descriptor_set : cb_state->validated_descriptor_sets) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3737 | descriptor_set->ClearCachedValidation(cb_state); |
| 3738 | } |
| 3739 | cb_state->validated_descriptor_sets.clear(); |
| 3740 | if (VK_SUCCESS == result) { |
| 3741 | cb_state->state = CB_RECORDED; |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags, |
| 3746 | VkResult result) { |
| 3747 | if (VK_SUCCESS == result) { |
| 3748 | ResetCommandBufferState(commandBuffer); |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) { |
| 3753 | // initially assume everything is static state |
| 3754 | CBStatusFlags flags = CBSTATUS_ALL_STATE_SET; |
| 3755 | |
| 3756 | if (ds) { |
| 3757 | for (uint32_t i = 0; i < ds->dynamicStateCount; i++) { |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 3758 | flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3759 | } |
| 3760 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3761 | return flags; |
| 3762 | } |
| 3763 | |
| 3764 | // Validation cache: |
| 3765 | // CV is the bottommost implementor of this extension. Don't pass calls down. |
| 3766 | // utility function to set collective state for pipeline |
| 3767 | void SetPipelineState(PIPELINE_STATE *pPipe) { |
| 3768 | // If any attachment used by this pipeline has blendEnable, set top-level blendEnable |
| 3769 | if (pPipe->graphicsPipelineCI.pColorBlendState) { |
| 3770 | for (size_t i = 0; i < pPipe->attachments.size(); ++i) { |
| 3771 | if (VK_TRUE == pPipe->attachments[i].blendEnable) { |
| 3772 | if (((pPipe->attachments[i].dstAlphaBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3773 | (pPipe->attachments[i].dstAlphaBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 3774 | ((pPipe->attachments[i].dstColorBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3775 | (pPipe->attachments[i].dstColorBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 3776 | ((pPipe->attachments[i].srcAlphaBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3777 | (pPipe->attachments[i].srcAlphaBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 3778 | ((pPipe->attachments[i].srcColorBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3779 | (pPipe->attachments[i].srcColorBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA))) { |
| 3780 | pPipe->blendConstantsEnabled = true; |
| 3781 | } |
| 3782 | } |
| 3783 | } |
| 3784 | } |
sfricke-samsung | 8f658d4 | 2020-05-03 20:12:24 -0700 | [diff] [blame] | 3785 | // Check if sample location is enabled |
| 3786 | if (pPipe->graphicsPipelineCI.pMultisampleState) { |
| 3787 | const VkPipelineSampleLocationsStateCreateInfoEXT *sample_location_state = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 3788 | LvlFindInChain<VkPipelineSampleLocationsStateCreateInfoEXT>(pPipe->graphicsPipelineCI.pMultisampleState->pNext); |
sfricke-samsung | 8f658d4 | 2020-05-03 20:12:24 -0700 | [diff] [blame] | 3789 | if (sample_location_state != nullptr) { |
| 3790 | pPipe->sample_location_enabled = sample_location_state->sampleLocationsEnable; |
| 3791 | } |
| 3792 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3793 | } |
| 3794 | |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 3795 | void UpdateSamplerDescriptorsUsedByImage(LAST_BOUND_STATE &last_bound_state) { |
| 3796 | if (!last_bound_state.pipeline_state) return; |
| 3797 | if (last_bound_state.per_set.empty()) return; |
| 3798 | |
| 3799 | for (auto &slot : last_bound_state.pipeline_state->active_slots) { |
| 3800 | for (auto &req : slot.second) { |
| 3801 | for (auto &samplers : req.second.samplers_used_by_image) { |
| 3802 | for (auto &sampler : samplers) { |
| 3803 | if (sampler.first.sampler_slot.first < last_bound_state.per_set.size() && |
| 3804 | last_bound_state.per_set[sampler.first.sampler_slot.first].bound_descriptor_set) { |
| 3805 | sampler.second = last_bound_state.per_set[sampler.first.sampler_slot.first] |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 3806 | .bound_descriptor_set->GetDescriptorFromBinding(sampler.first.sampler_slot.second, |
| 3807 | sampler.first.sampler_index); |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 3808 | } |
| 3809 | } |
| 3810 | } |
| 3811 | } |
| 3812 | } |
| 3813 | } |
| 3814 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3815 | void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 3816 | VkPipeline pipeline) { |
| 3817 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3818 | assert(cb_state); |
| 3819 | |
| 3820 | auto pipe_state = GetPipelineState(pipeline); |
| 3821 | if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) { |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame^] | 3822 | bool rasterization_enabled = VK_FALSE == pipe_state->graphicsPipelineCI.ptr()->pRasterizationState->rasterizerDiscardEnable; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3823 | const auto* viewport_state = pipe_state->graphicsPipelineCI.ptr()->pViewportState; |
| 3824 | const auto* dynamic_state = pipe_state->graphicsPipelineCI.ptr()->pDynamicState; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3825 | cb_state->status &= ~cb_state->static_status; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3826 | cb_state->static_status = MakeStaticStateMask(dynamic_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3827 | cb_state->status |= cb_state->static_status; |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 3828 | cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status); |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3829 | |
| 3830 | // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline. |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame^] | 3831 | // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at |
| 3832 | // this time), then these are set to 0 to disable this checking. |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3833 | auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame^] | 3834 | auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3835 | cb_state->pipelineStaticViewportCount = |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame^] | 3836 | has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3837 | cb_state->pipelineStaticScissorCount = |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame^] | 3838 | has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3839 | |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame^] | 3840 | // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization. |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3841 | // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites |
| 3842 | // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count. |
| 3843 | // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver. |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3844 | if (!has_dynamic_viewport_count) { |
| 3845 | cb_state->trashedViewportCount = true; |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame^] | 3846 | if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) { |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3847 | cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u; |
| 3848 | // should become = ~uint32_t(0) if the other interpretation is correct. |
| 3849 | } |
| 3850 | } |
| 3851 | if (!has_dynamic_scissor_count) { |
| 3852 | cb_state->trashedScissorCount = true; |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame^] | 3853 | if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) { |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3854 | cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u; |
| 3855 | // should become = ~uint32_t(0) if the other interpretation is correct. |
| 3856 | } |
| 3857 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3858 | } |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 3859 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 3860 | cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3861 | SetPipelineState(pipe_state); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3862 | AddCommandBufferBinding(pipe_state->cb_bindings, VulkanTypedHandle(pipeline, kVulkanObjectTypePipeline), cb_state); |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 3863 | |
| 3864 | for (auto &slot : pipe_state->active_slots) { |
| 3865 | for (auto &req : slot.second) { |
| 3866 | for (auto &sampler : req.second.samplers_used_by_image) { |
| 3867 | for (auto &des : sampler) { |
| 3868 | des.second = nullptr; |
| 3869 | } |
| 3870 | } |
| 3871 | } |
| 3872 | } |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 3873 | UpdateSamplerDescriptorsUsedByImage(cb_state->lastBound[lv_bind_point]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 3877 | uint32_t viewportCount, const VkViewport *pViewports) { |
| 3878 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3879 | uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport; |
| 3880 | cb_state->viewportMask |= bits; |
| 3881 | cb_state->trashedViewportMask &= ~bits; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3882 | cb_state->status |= CBSTATUS_VIEWPORT_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3883 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_SET; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3884 | |
| 3885 | cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size())); |
| 3886 | for (size_t i = 0; i < viewportCount; ++i) { |
| 3887 | cb_state->dynamicViewports[firstViewport + i] = pViewports[i]; |
| 3888 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor, |
| 3892 | uint32_t exclusiveScissorCount, |
| 3893 | const VkRect2D *pExclusiveScissors) { |
| 3894 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3895 | // TODO: We don't have VUIDs for validating that all exclusive scissors have been set. |
| 3896 | // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor; |
| 3897 | cb_state->status |= CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3898 | cb_state->static_status &= ~CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3899 | } |
| 3900 | |
| 3901 | void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView, |
| 3902 | VkImageLayout imageLayout) { |
| 3903 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3904 | |
| 3905 | if (imageView != VK_NULL_HANDLE) { |
| 3906 | auto view_state = GetImageViewState(imageView); |
| 3907 | AddCommandBufferBindingImageView(cb_state, view_state); |
| 3908 | } |
| 3909 | } |
| 3910 | |
| 3911 | void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 3912 | uint32_t viewportCount, |
| 3913 | const VkShadingRatePaletteNV *pShadingRatePalettes) { |
| 3914 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3915 | // TODO: We don't have VUIDs for validating that all shading rate palettes have been set. |
| 3916 | // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport; |
| 3917 | cb_state->status |= CBSTATUS_SHADING_RATE_PALETTE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3918 | cb_state->static_status &= ~CBSTATUS_SHADING_RATE_PALETTE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device, |
| 3922 | const VkAccelerationStructureCreateInfoNV *pCreateInfo, |
| 3923 | const VkAllocationCallbacks *pAllocator, |
| 3924 | VkAccelerationStructureNV *pAccelerationStructure, |
| 3925 | VkResult result) { |
| 3926 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3927 | auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3928 | |
| 3929 | // Query the requirements in case the application doesn't (to avoid bind/validation time query) |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 3930 | auto as_memory_requirements_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3931 | as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV; |
| 3932 | as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure; |
| 3933 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements); |
| 3934 | |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 3935 | auto scratch_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3936 | scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV; |
| 3937 | scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure; |
| 3938 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info, |
| 3939 | &as_state->build_scratch_memory_requirements); |
| 3940 | |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 3941 | auto update_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3942 | update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV; |
| 3943 | update_memory_req_info.accelerationStructure = as_state->acceleration_structure; |
| 3944 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info, |
| 3945 | &as_state->update_scratch_memory_requirements); |
Mark Lobodzinski | 17dc460 | 2020-05-29 07:48:40 -0600 | [diff] [blame] | 3946 | as_state->allocator = pAllocator; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3947 | accelerationStructureMap[*pAccelerationStructure] = std::move(as_state); |
| 3948 | } |
| 3949 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3950 | void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device, |
| 3951 | const VkAccelerationStructureCreateInfoKHR *pCreateInfo, |
| 3952 | const VkAllocationCallbacks *pAllocator, |
| 3953 | VkAccelerationStructureKHR *pAccelerationStructure, |
| 3954 | VkResult result) { |
| 3955 | if (VK_SUCCESS != result) return; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3956 | auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo); |
Mark Lobodzinski | 17dc460 | 2020-05-29 07:48:40 -0600 | [diff] [blame] | 3957 | as_state->allocator = pAllocator; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3958 | accelerationStructureMap_khr[*pAccelerationStructure] = std::move(as_state); |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3959 | } |
| 3960 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3961 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR( |
| 3962 | VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, |
| 3963 | const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) { |
| 3964 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3965 | if (cb_state == nullptr) { |
| 3966 | return; |
| 3967 | } |
| 3968 | for (uint32_t i = 0; i < infoCount; ++i) { |
| 3969 | ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure); |
| 3970 | ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure); |
| 3971 | if (dst_as_state != nullptr) { |
| 3972 | dst_as_state->built = true; |
| 3973 | dst_as_state->build_info_khr.initialize(&pInfos[i]); |
| 3974 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 3975 | } |
| 3976 | if (src_as_state != nullptr) { |
| 3977 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 3978 | } |
| 3979 | } |
| 3980 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 3981 | } |
| 3982 | |
| 3983 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR( |
| 3984 | VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, |
| 3985 | const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides, |
| 3986 | const uint32_t *const *ppMaxPrimitiveCounts) { |
| 3987 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3988 | if (cb_state == nullptr) { |
| 3989 | return; |
| 3990 | } |
| 3991 | for (uint32_t i = 0; i < infoCount; ++i) { |
| 3992 | ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure); |
| 3993 | ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure); |
| 3994 | if (dst_as_state != nullptr) { |
| 3995 | dst_as_state->built = true; |
| 3996 | dst_as_state->build_info_khr.initialize(&pInfos[i]); |
| 3997 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 3998 | } |
| 3999 | if (src_as_state != nullptr) { |
| 4000 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 4001 | } |
| 4002 | } |
| 4003 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 4004 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4005 | void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4006 | VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4007 | ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(pInfo->accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4008 | if (as_state != nullptr) { |
| 4009 | if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) { |
| 4010 | as_state->memory_requirements = *pMemoryRequirements; |
| 4011 | as_state->memory_requirements_checked = true; |
| 4012 | } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) { |
| 4013 | as_state->build_scratch_memory_requirements = *pMemoryRequirements; |
| 4014 | as_state->build_scratch_memory_requirements_checked = true; |
| 4015 | } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) { |
| 4016 | as_state->update_scratch_memory_requirements = *pMemoryRequirements; |
| 4017 | as_state->update_scratch_memory_requirements_checked = true; |
| 4018 | } |
| 4019 | } |
| 4020 | } |
| 4021 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4022 | void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV( |
| 4023 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4024 | if (VK_SUCCESS != result) return; |
| 4025 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4026 | const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4027 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4028 | ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(info.accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4029 | if (as_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4030 | // Track objects tied to memory |
| 4031 | SetMemBinding(info.memory, as_state, info.memoryOffset, |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4032 | VulkanTypedHandle(info.accelerationStructure, kVulkanObjectTypeAccelerationStructureNV)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4033 | |
| 4034 | // GPU validation of top level acceleration structure building needs acceleration structure handles. |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 4035 | // XXX TODO: Query device address for KHR extension |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4036 | if (enabled[gpu_validation]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4037 | DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle); |
| 4038 | } |
| 4039 | } |
| 4040 | } |
| 4041 | } |
| 4042 | |
| 4043 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV( |
| 4044 | VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset, |
| 4045 | VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) { |
| 4046 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4047 | if (cb_state == nullptr) { |
| 4048 | return; |
| 4049 | } |
| 4050 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4051 | ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst); |
| 4052 | ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4053 | if (dst_as_state != nullptr) { |
| 4054 | dst_as_state->built = true; |
| 4055 | dst_as_state->build_info.initialize(pInfo); |
| 4056 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 4057 | } |
| 4058 | if (src_as_state != nullptr) { |
| 4059 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 4060 | } |
| 4061 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 4062 | } |
| 4063 | |
| 4064 | void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer, |
| 4065 | VkAccelerationStructureNV dst, |
| 4066 | VkAccelerationStructureNV src, |
| 4067 | VkCopyAccelerationStructureModeNV mode) { |
| 4068 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4069 | if (cb_state) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4070 | ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src); |
| 4071 | ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4072 | if (dst_as_state != nullptr && src_as_state != nullptr) { |
| 4073 | dst_as_state->built = true; |
| 4074 | dst_as_state->build_info = src_as_state->build_info; |
| 4075 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 4076 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 4077 | } |
| 4078 | } |
| 4079 | } |
| 4080 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 4081 | void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device, |
| 4082 | VkAccelerationStructureKHR accelerationStructure, |
| 4083 | const VkAllocationCallbacks *pAllocator) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4084 | if (!accelerationStructure) return; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4085 | auto *as_state = GetAccelerationStructureStateKHR(accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4086 | if (as_state) { |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 4087 | const VulkanTypedHandle obj_struct(accelerationStructure, kVulkanObjectTypeAccelerationStructureKHR); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4088 | InvalidateCommandBuffers(as_state->cb_bindings, obj_struct); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4089 | ClearMemoryObjectBindings(obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 4090 | as_state->destroyed = true; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4091 | accelerationStructureMap_khr.erase(accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4092 | } |
| 4093 | } |
| 4094 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 4095 | void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device, |
| 4096 | VkAccelerationStructureNV accelerationStructure, |
| 4097 | const VkAllocationCallbacks *pAllocator) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4098 | if (!accelerationStructure) return; |
| 4099 | auto *as_state = GetAccelerationStructureStateNV(accelerationStructure); |
| 4100 | if (as_state) { |
| 4101 | const VulkanTypedHandle obj_struct(accelerationStructure, kVulkanObjectTypeAccelerationStructureNV); |
| 4102 | InvalidateCommandBuffers(as_state->cb_bindings, obj_struct); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4103 | ClearMemoryObjectBindings(obj_struct); |
| 4104 | as_state->destroyed = true; |
| 4105 | accelerationStructureMap.erase(accelerationStructure); |
| 4106 | } |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 4107 | } |
| 4108 | |
Chris Mayer | 9ded5eb | 2019-09-19 16:33:26 +0200 | [diff] [blame] | 4109 | void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 4110 | uint32_t viewportCount, |
| 4111 | const VkViewportWScalingNV *pViewportWScalings) { |
| 4112 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4113 | cb_state->status |= CBSTATUS_VIEWPORT_W_SCALING_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4114 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_W_SCALING_SET; |
Chris Mayer | 9ded5eb | 2019-09-19 16:33:26 +0200 | [diff] [blame] | 4115 | } |
| 4116 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4117 | void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) { |
| 4118 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4119 | cb_state->status |= CBSTATUS_LINE_WIDTH_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4120 | cb_state->static_status &= ~CBSTATUS_LINE_WIDTH_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor, |
| 4124 | uint16_t lineStipplePattern) { |
| 4125 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4126 | cb_state->status |= CBSTATUS_LINE_STIPPLE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4127 | cb_state->static_status &= ~CBSTATUS_LINE_STIPPLE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor, |
| 4131 | float depthBiasClamp, float depthBiasSlopeFactor) { |
| 4132 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4133 | cb_state->status |= CBSTATUS_DEPTH_BIAS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4134 | cb_state->static_status &= ~CBSTATUS_DEPTH_BIAS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4135 | } |
| 4136 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4137 | void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, |
| 4138 | const VkRect2D *pScissors) { |
| 4139 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 4140 | uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor; |
| 4141 | cb_state->scissorMask |= bits; |
| 4142 | cb_state->trashedScissorMask &= ~bits; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4143 | cb_state->status |= CBSTATUS_SCISSOR_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4144 | cb_state->static_status &= ~CBSTATUS_SCISSOR_SET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4145 | } |
| 4146 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4147 | void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) { |
| 4148 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4149 | cb_state->status |= CBSTATUS_BLEND_CONSTANTS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4150 | cb_state->static_status &= ~CBSTATUS_BLEND_CONSTANTS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4151 | } |
| 4152 | |
| 4153 | void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds, |
| 4154 | float maxDepthBounds) { |
| 4155 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4156 | cb_state->status |= CBSTATUS_DEPTH_BOUNDS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4157 | cb_state->static_status &= ~CBSTATUS_DEPTH_BOUNDS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4158 | } |
| 4159 | |
| 4160 | void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 4161 | uint32_t compareMask) { |
| 4162 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4163 | cb_state->status |= CBSTATUS_STENCIL_READ_MASK_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4164 | cb_state->static_status &= ~CBSTATUS_STENCIL_READ_MASK_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4165 | } |
| 4166 | |
| 4167 | void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 4168 | uint32_t writeMask) { |
| 4169 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4170 | cb_state->status |= CBSTATUS_STENCIL_WRITE_MASK_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4171 | cb_state->static_status &= ~CBSTATUS_STENCIL_WRITE_MASK_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 4175 | uint32_t reference) { |
| 4176 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4177 | cb_state->status |= CBSTATUS_STENCIL_REFERENCE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4178 | cb_state->static_status &= ~CBSTATUS_STENCIL_REFERENCE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | // Update pipeline_layout bind points applying the "Pipeline Layout Compatibility" rules. |
| 4182 | // One of pDescriptorSets or push_descriptor_set should be nullptr, indicating whether this |
| 4183 | // is called for CmdBindDescriptorSets or CmdPushDescriptorSet. |
| 4184 | void ValidationStateTracker::UpdateLastBoundDescriptorSets(CMD_BUFFER_STATE *cb_state, VkPipelineBindPoint pipeline_bind_point, |
| 4185 | const PIPELINE_LAYOUT_STATE *pipeline_layout, uint32_t first_set, |
| 4186 | uint32_t set_count, const VkDescriptorSet *pDescriptorSets, |
| 4187 | cvdescriptorset::DescriptorSet *push_descriptor_set, |
| 4188 | uint32_t dynamic_offset_count, const uint32_t *p_dynamic_offsets) { |
| 4189 | assert((pDescriptorSets == nullptr) ^ (push_descriptor_set == nullptr)); |
| 4190 | // Defensive |
| 4191 | assert(pipeline_layout); |
| 4192 | if (!pipeline_layout) return; |
| 4193 | |
| 4194 | uint32_t required_size = first_set + set_count; |
| 4195 | const uint32_t last_binding_index = required_size - 1; |
| 4196 | assert(last_binding_index < pipeline_layout->compat_for_set.size()); |
| 4197 | |
| 4198 | // Some useful shorthand |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 4199 | const auto lv_bind_point = ConvertToLvlBindPoint(pipeline_bind_point); |
| 4200 | auto &last_bound = cb_state->lastBound[lv_bind_point]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4201 | auto &pipe_compat_ids = pipeline_layout->compat_for_set; |
| 4202 | const uint32_t current_size = static_cast<uint32_t>(last_bound.per_set.size()); |
| 4203 | |
| 4204 | // We need this three times in this function, but nowhere else |
| 4205 | auto push_descriptor_cleanup = [&last_bound](const cvdescriptorset::DescriptorSet *ds) -> bool { |
| 4206 | if (ds && ds->IsPushDescriptor()) { |
| 4207 | assert(ds == last_bound.push_descriptor_set.get()); |
| 4208 | last_bound.push_descriptor_set = nullptr; |
| 4209 | return true; |
| 4210 | } |
| 4211 | return false; |
| 4212 | }; |
| 4213 | |
| 4214 | // Clean up the "disturbed" before and after the range to be set |
| 4215 | if (required_size < current_size) { |
| 4216 | if (last_bound.per_set[last_binding_index].compat_id_for_set != pipe_compat_ids[last_binding_index]) { |
| 4217 | // We're disturbing those after last, we'll shrink below, but first need to check for and cleanup the push_descriptor |
| 4218 | for (auto set_idx = required_size; set_idx < current_size; ++set_idx) { |
| 4219 | if (push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set)) break; |
| 4220 | } |
| 4221 | } else { |
| 4222 | // We're not disturbing past last, so leave the upper binding data alone. |
| 4223 | required_size = current_size; |
| 4224 | } |
| 4225 | } |
| 4226 | |
| 4227 | // We resize if we need more set entries or if those past "last" are disturbed |
| 4228 | if (required_size != current_size) { |
| 4229 | last_bound.per_set.resize(required_size); |
| 4230 | } |
| 4231 | |
| 4232 | // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update |
| 4233 | for (uint32_t set_idx = 0; set_idx < first_set; ++set_idx) { |
| 4234 | if (last_bound.per_set[set_idx].compat_id_for_set != pipe_compat_ids[set_idx]) { |
| 4235 | push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set); |
| 4236 | last_bound.per_set[set_idx].bound_descriptor_set = nullptr; |
| 4237 | last_bound.per_set[set_idx].dynamicOffsets.clear(); |
| 4238 | last_bound.per_set[set_idx].compat_id_for_set = pipe_compat_ids[set_idx]; |
| 4239 | } |
| 4240 | } |
| 4241 | |
| 4242 | // Now update the bound sets with the input sets |
| 4243 | const uint32_t *input_dynamic_offsets = p_dynamic_offsets; // "read" pointer for dynamic offset data |
| 4244 | for (uint32_t input_idx = 0; input_idx < set_count; input_idx++) { |
| 4245 | auto set_idx = input_idx + first_set; // set_idx is index within layout, input_idx is index within input descriptor sets |
| 4246 | cvdescriptorset::DescriptorSet *descriptor_set = |
| 4247 | push_descriptor_set ? push_descriptor_set : GetSetNode(pDescriptorSets[input_idx]); |
| 4248 | |
| 4249 | // Record binding (or push) |
| 4250 | if (descriptor_set != last_bound.push_descriptor_set.get()) { |
| 4251 | // Only cleanup the push descriptors if they aren't the currently used set. |
| 4252 | push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set); |
| 4253 | } |
| 4254 | last_bound.per_set[set_idx].bound_descriptor_set = descriptor_set; |
| 4255 | last_bound.per_set[set_idx].compat_id_for_set = pipe_compat_ids[set_idx]; // compat ids are canonical *per* set index |
| 4256 | |
| 4257 | if (descriptor_set) { |
| 4258 | auto set_dynamic_descriptor_count = descriptor_set->GetDynamicDescriptorCount(); |
| 4259 | // TODO: Add logic for tracking push_descriptor offsets (here or in caller) |
| 4260 | if (set_dynamic_descriptor_count && input_dynamic_offsets) { |
| 4261 | const uint32_t *end_offset = input_dynamic_offsets + set_dynamic_descriptor_count; |
| 4262 | last_bound.per_set[set_idx].dynamicOffsets = std::vector<uint32_t>(input_dynamic_offsets, end_offset); |
| 4263 | input_dynamic_offsets = end_offset; |
| 4264 | assert(input_dynamic_offsets <= (p_dynamic_offsets + dynamic_offset_count)); |
| 4265 | } else { |
| 4266 | last_bound.per_set[set_idx].dynamicOffsets.clear(); |
| 4267 | } |
| 4268 | if (!descriptor_set->IsPushDescriptor()) { |
| 4269 | // Can't cache validation of push_descriptors |
| 4270 | cb_state->validated_descriptor_sets.insert(descriptor_set); |
| 4271 | } |
| 4272 | } |
| 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | // Update the bound state for the bind point, including the effects of incompatible pipeline layouts |
| 4277 | void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer, |
| 4278 | VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, |
| 4279 | uint32_t firstSet, uint32_t setCount, |
| 4280 | const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount, |
| 4281 | const uint32_t *pDynamicOffsets) { |
| 4282 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4283 | auto pipeline_layout = GetPipelineLayout(layout); |
| 4284 | |
| 4285 | // Resize binding arrays |
| 4286 | uint32_t last_set_index = firstSet + setCount - 1; |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 4287 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 4288 | if (last_set_index >= cb_state->lastBound[lv_bind_point].per_set.size()) { |
| 4289 | cb_state->lastBound[lv_bind_point].per_set.resize(last_set_index + 1); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | UpdateLastBoundDescriptorSets(cb_state, pipelineBindPoint, pipeline_layout, firstSet, setCount, pDescriptorSets, nullptr, |
| 4293 | dynamicOffsetCount, pDynamicOffsets); |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 4294 | cb_state->lastBound[lv_bind_point].pipeline_layout = layout; |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 4295 | UpdateSamplerDescriptorsUsedByImage(cb_state->lastBound[lv_bind_point]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | void ValidationStateTracker::RecordCmdPushDescriptorSetState(CMD_BUFFER_STATE *cb_state, VkPipelineBindPoint pipelineBindPoint, |
| 4299 | VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount, |
| 4300 | const VkWriteDescriptorSet *pDescriptorWrites) { |
| 4301 | const auto &pipeline_layout = GetPipelineLayout(layout); |
| 4302 | // Short circuit invalid updates |
| 4303 | if (!pipeline_layout || (set >= pipeline_layout->set_layouts.size()) || !pipeline_layout->set_layouts[set] || |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4304 | !pipeline_layout->set_layouts[set]->IsPushDescriptor()) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4305 | return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4306 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4307 | |
| 4308 | // We need a descriptor set to update the bindings with, compatible with the passed layout |
Jeremy Gebben | 50fb183 | 2021-03-19 09:10:13 -0600 | [diff] [blame] | 4309 | const auto& dsl = pipeline_layout->set_layouts[set]; |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 4310 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 4311 | auto &last_bound = cb_state->lastBound[lv_bind_point]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4312 | auto &push_descriptor_set = last_bound.push_descriptor_set; |
| 4313 | // If we are disturbing the current push_desriptor_set clear it |
| 4314 | if (!push_descriptor_set || !CompatForSet(set, last_bound, pipeline_layout->compat_for_set)) { |
John Zulauf | d2c3dae | 2019-12-12 11:02:17 -0700 | [diff] [blame] | 4315 | last_bound.UnbindAndResetPushDescriptorSet(new cvdescriptorset::DescriptorSet(0, nullptr, dsl, 0, this)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | UpdateLastBoundDescriptorSets(cb_state, pipelineBindPoint, pipeline_layout, set, 1, nullptr, push_descriptor_set.get(), 0, |
| 4319 | nullptr); |
| 4320 | last_bound.pipeline_layout = layout; |
| 4321 | |
| 4322 | // Now that we have either the new or extant push_descriptor set ... do the write updates against it |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 4323 | push_descriptor_set->PerformPushDescriptorsUpdate(this, descriptorWriteCount, pDescriptorWrites); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, |
| 4327 | VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, |
| 4328 | uint32_t set, uint32_t descriptorWriteCount, |
| 4329 | const VkWriteDescriptorSet *pDescriptorWrites) { |
| 4330 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4331 | RecordCmdPushDescriptorSetState(cb_state, pipelineBindPoint, layout, set, descriptorWriteCount, pDescriptorWrites); |
| 4332 | } |
| 4333 | |
Tony-LunarG | 6bb1d0c | 2019-09-23 10:39:25 -0600 | [diff] [blame] | 4334 | void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout, |
| 4335 | VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, |
| 4336 | const void *pValues) { |
| 4337 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4338 | if (cb_state != nullptr) { |
| 4339 | ResetCommandBufferPushConstantDataIfIncompatible(cb_state, layout); |
| 4340 | |
| 4341 | auto &push_constant_data = cb_state->push_constant_data; |
| 4342 | assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size())); |
| 4343 | std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size)); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 4344 | cb_state->push_constant_pipeline_layout_set = layout; |
| 4345 | |
| 4346 | auto flags = stageFlags; |
| 4347 | uint32_t bit_shift = 0; |
| 4348 | while (flags) { |
| 4349 | if (flags & 1) { |
| 4350 | VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift); |
| 4351 | const auto it = cb_state->push_constant_data_update.find(flag); |
| 4352 | |
| 4353 | if (it != cb_state->push_constant_data_update.end()) { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 4354 | std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size)); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 4355 | } |
| 4356 | } |
| 4357 | flags = flags >> 1; |
| 4358 | ++bit_shift; |
| 4359 | } |
Tony-LunarG | 6bb1d0c | 2019-09-23 10:39:25 -0600 | [diff] [blame] | 4360 | } |
| 4361 | } |
| 4362 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4363 | void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4364 | VkIndexType indexType) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4365 | auto cb_state = GetCBState(commandBuffer); |
| 4366 | |
| 4367 | cb_state->status |= CBSTATUS_INDEX_BUFFER_BOUND; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4368 | cb_state->static_status &= ~CBSTATUS_INDEX_BUFFER_BOUND; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4369 | cb_state->index_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(buffer); |
| 4370 | cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4371 | cb_state->index_buffer_binding.offset = offset; |
| 4372 | cb_state->index_buffer_binding.index_type = indexType; |
| 4373 | // Add binding for this index buffer to this commandbuffer |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4374 | AddCommandBufferBindingBuffer(cb_state, cb_state->index_buffer_binding.buffer_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding, |
| 4378 | uint32_t bindingCount, const VkBuffer *pBuffers, |
| 4379 | const VkDeviceSize *pOffsets) { |
| 4380 | auto cb_state = GetCBState(commandBuffer); |
| 4381 | |
| 4382 | uint32_t end = firstBinding + bindingCount; |
| 4383 | if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) { |
| 4384 | cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end); |
| 4385 | } |
| 4386 | |
| 4387 | for (uint32_t i = 0; i < bindingCount; ++i) { |
| 4388 | auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4389 | vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4390 | vertex_buffer_binding.offset = pOffsets[i]; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4391 | vertex_buffer_binding.size = VK_WHOLE_SIZE; |
| 4392 | vertex_buffer_binding.stride = 0; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4393 | // Add binding for this vertex buffer to this commandbuffer |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 4394 | if (pBuffers[i]) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4395 | AddCommandBufferBindingBuffer(cb_state, vertex_buffer_binding.buffer_state.get()); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 4396 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4397 | } |
| 4398 | } |
| 4399 | |
| 4400 | void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, |
| 4401 | VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) { |
| 4402 | auto cb_state = GetCBState(commandBuffer); |
| 4403 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 4404 | |
| 4405 | // Update bindings between buffer and cmd buffer |
| 4406 | AddCommandBufferBindingBuffer(cb_state, dst_buffer_state); |
| 4407 | } |
| 4408 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 4409 | bool ValidationStateTracker::SetEventStageMask(VkEvent event, VkPipelineStageFlags2KHR stageMask, |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4410 | EventToStageMap *localEventToStageMap) { |
| 4411 | (*localEventToStageMap)[event] = stageMask; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4412 | return false; |
| 4413 | } |
| 4414 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 4415 | void ValidationStateTracker::RecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2KHR stageMask) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4416 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4417 | auto event_state = GetEventState(event); |
| 4418 | if (event_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4419 | AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(event, kVulkanObjectTypeEvent, event_state), cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4420 | } |
| 4421 | cb_state->events.push_back(event); |
| 4422 | if (!cb_state->waitedEvents.count(event)) { |
| 4423 | cb_state->writeEventsBeforeWait.push_back(event); |
| 4424 | } |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4425 | cb_state->eventUpdates.emplace_back( |
| 4426 | [event, stageMask](const ValidationStateTracker *device_data, bool do_validate, EventToStageMap *localEventToStageMap) { |
| 4427 | return SetEventStageMask(event, stageMask, localEventToStageMap); |
| 4428 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4429 | } |
| 4430 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 4431 | void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4432 | VkPipelineStageFlags stageMask) { |
| 4433 | RecordCmdSetEvent(commandBuffer, event, stageMask); |
| 4434 | } |
| 4435 | |
| 4436 | void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4437 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 4438 | auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo); |
| 4439 | |
| 4440 | RecordCmdSetEvent(commandBuffer, event, stage_masks.src); |
| 4441 | } |
| 4442 | |
| 4443 | void ValidationStateTracker::RecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4444 | VkPipelineStageFlags2KHR stageMask) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4445 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4446 | auto event_state = GetEventState(event); |
| 4447 | if (event_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4448 | AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(event, kVulkanObjectTypeEvent, event_state), cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4449 | } |
| 4450 | cb_state->events.push_back(event); |
| 4451 | if (!cb_state->waitedEvents.count(event)) { |
| 4452 | cb_state->writeEventsBeforeWait.push_back(event); |
| 4453 | } |
| 4454 | |
| 4455 | cb_state->eventUpdates.emplace_back( |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4456 | [event](const ValidationStateTracker *, bool do_validate, EventToStageMap *localEventToStageMap) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 4457 | return SetEventStageMask(event, VkPipelineStageFlags2KHR(0), localEventToStageMap); |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4458 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4459 | } |
| 4460 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 4461 | void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4462 | VkPipelineStageFlags stageMask) { |
| 4463 | RecordCmdResetEvent(commandBuffer, event, stageMask); |
| 4464 | } |
| 4465 | |
| 4466 | void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 4467 | VkPipelineStageFlags2KHR stageMask) { |
| 4468 | RecordCmdResetEvent(commandBuffer, event, stageMask); |
| 4469 | } |
| 4470 | |
| 4471 | void ValidationStateTracker::RecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4472 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4473 | for (uint32_t i = 0; i < eventCount; ++i) { |
| 4474 | auto event_state = GetEventState(pEvents[i]); |
| 4475 | if (event_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4476 | AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(pEvents[i], kVulkanObjectTypeEvent, event_state), |
| 4477 | cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4478 | } |
| 4479 | cb_state->waitedEvents.insert(pEvents[i]); |
| 4480 | cb_state->events.push_back(pEvents[i]); |
| 4481 | } |
| 4482 | } |
| 4483 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 4484 | void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4485 | VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask, |
| 4486 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4487 | uint32_t bufferMemoryBarrierCount, |
| 4488 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4489 | uint32_t imageMemoryBarrierCount, |
| 4490 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 4491 | RecordCmdWaitEvents(commandBuffer, eventCount, pEvents); |
| 4492 | } |
| 4493 | |
| 4494 | void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, |
| 4495 | const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) { |
| 4496 | RecordCmdWaitEvents(commandBuffer, eventCount, pEvents); |
| 4497 | } |
| 4498 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4499 | bool ValidationStateTracker::SetQueryState(QueryObject object, QueryState value, QueryMap *localQueryToStateMap) { |
| 4500 | (*localQueryToStateMap)[object] = value; |
| 4501 | return false; |
| 4502 | } |
| 4503 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4504 | bool ValidationStateTracker::SetQueryStateMulti(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, uint32_t perfPass, |
| 4505 | QueryState value, QueryMap *localQueryToStateMap) { |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4506 | for (uint32_t i = 0; i < queryCount; i++) { |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4507 | QueryObject object = QueryObject(QueryObject(queryPool, firstQuery + i), perfPass); |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4508 | (*localQueryToStateMap)[object] = value; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4509 | } |
| 4510 | return false; |
| 4511 | } |
| 4512 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4513 | QueryState ValidationStateTracker::GetQueryState(const QueryMap *localQueryToStateMap, VkQueryPool queryPool, uint32_t queryIndex, |
| 4514 | uint32_t perfPass) const { |
| 4515 | QueryObject query = QueryObject(QueryObject(queryPool, queryIndex), perfPass); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4516 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4517 | auto iter = localQueryToStateMap->find(query); |
| 4518 | if (iter != localQueryToStateMap->end()) return iter->second; |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4519 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4520 | return QUERYSTATE_UNKNOWN; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | void ValidationStateTracker::RecordCmdBeginQuery(CMD_BUFFER_STATE *cb_state, const QueryObject &query_obj) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4524 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4525 | cb_state->activeQueries.insert(query_obj); |
| 4526 | cb_state->startedQueries.insert(query_obj); |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4527 | cb_state->queryUpdates.emplace_back([query_obj](const ValidationStateTracker *device_data, bool do_validate, |
| 4528 | VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass, |
| 4529 | QueryMap *localQueryToStateMap) { |
| 4530 | SetQueryState(QueryObject(query_obj, perfQueryPass), QUERYSTATE_RUNNING, localQueryToStateMap); |
| 4531 | return false; |
| 4532 | }); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4533 | auto pool_state = GetQueryPoolState(query_obj.pool); |
| 4534 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(query_obj.pool, kVulkanObjectTypeQueryPool, pool_state), |
| 4535 | cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, |
| 4539 | VkFlags flags) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4540 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4541 | QueryObject query = {queryPool, slot}; |
| 4542 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4543 | RecordCmdBeginQuery(cb_state, query); |
| 4544 | } |
| 4545 | |
| 4546 | void ValidationStateTracker::RecordCmdEndQuery(CMD_BUFFER_STATE *cb_state, const QueryObject &query_obj) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4547 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4548 | cb_state->activeQueries.erase(query_obj); |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4549 | cb_state->queryUpdates.emplace_back([query_obj](const ValidationStateTracker *device_data, bool do_validate, |
| 4550 | VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass, |
| 4551 | QueryMap *localQueryToStateMap) { |
| 4552 | return SetQueryState(QueryObject(query_obj, perfQueryPass), QUERYSTATE_ENDED, localQueryToStateMap); |
| 4553 | }); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4554 | auto pool_state = GetQueryPoolState(query_obj.pool); |
| 4555 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(query_obj.pool, kVulkanObjectTypeQueryPool, pool_state), |
| 4556 | cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4557 | } |
| 4558 | |
| 4559 | void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4560 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4561 | QueryObject query_obj = {queryPool, slot}; |
| 4562 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4563 | RecordCmdEndQuery(cb_state, query_obj); |
| 4564 | } |
| 4565 | |
| 4566 | void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4567 | uint32_t firstQuery, uint32_t queryCount) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4568 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4569 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4570 | |
Lionel Landwerlin | b1e5a42 | 2020-02-18 16:49:09 +0200 | [diff] [blame] | 4571 | for (uint32_t slot = firstQuery; slot < (firstQuery + queryCount); slot++) { |
| 4572 | QueryObject query = {queryPool, slot}; |
| 4573 | cb_state->resetQueries.insert(query); |
| 4574 | } |
| 4575 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4576 | cb_state->queryUpdates.emplace_back([queryPool, firstQuery, queryCount](const ValidationStateTracker *device_data, |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4577 | bool do_validate, VkQueryPool &firstPerfQueryPool, |
| 4578 | uint32_t perfQueryPass, |
| 4579 | QueryMap *localQueryToStateMap) { |
| 4580 | return SetQueryStateMulti(queryPool, firstQuery, queryCount, perfQueryPass, QUERYSTATE_RESET, localQueryToStateMap); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4581 | }); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4582 | auto pool_state = GetQueryPoolState(queryPool); |
| 4583 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4584 | cb_state); |
| 4585 | } |
| 4586 | |
| 4587 | void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4588 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 4589 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 4590 | VkQueryResultFlags flags) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4591 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4592 | auto cb_state = GetCBState(commandBuffer); |
| 4593 | auto dst_buff_state = GetBufferState(dstBuffer); |
| 4594 | AddCommandBufferBindingBuffer(cb_state, dst_buff_state); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4595 | auto pool_state = GetQueryPoolState(queryPool); |
| 4596 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4597 | cb_state); |
| 4598 | } |
| 4599 | |
| 4600 | void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4601 | VkQueryPool queryPool, uint32_t slot) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 4602 | PostCallRecordCmdWriteTimestamp2KHR(commandBuffer, pipelineStage, queryPool, slot); |
| 4603 | } |
| 4604 | |
| 4605 | void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer, |
| 4606 | VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool, |
| 4607 | uint32_t slot) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4608 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4609 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4610 | auto pool_state = GetQueryPoolState(queryPool); |
| 4611 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4612 | cb_state); |
| 4613 | QueryObject query = {queryPool, slot}; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4614 | cb_state->queryUpdates.emplace_back([query](const ValidationStateTracker *device_data, bool do_validate, |
| 4615 | VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass, |
| 4616 | QueryMap *localQueryToStateMap) { |
| 4617 | return SetQueryState(QueryObject(query, perfQueryPass), QUERYSTATE_ENDED, localQueryToStateMap); |
| 4618 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4619 | } |
| 4620 | |
Marijn Suijten | 6750fdc | 2020-12-30 22:06:42 +0100 | [diff] [blame] | 4621 | void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR( |
| 4622 | VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures, |
| 4623 | VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) { |
| 4624 | if (disabled[query_validation]) return; |
| 4625 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4626 | auto pool_state = GetQueryPoolState(queryPool); |
| 4627 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state), |
| 4628 | cb_state); |
| 4629 | cb_state->queryUpdates.emplace_back( |
| 4630 | [queryPool, firstQuery, accelerationStructureCount](const ValidationStateTracker *device_data, bool do_validate, |
| 4631 | VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass, |
| 4632 | QueryMap *localQueryToStateMap) { |
| 4633 | return SetQueryStateMulti(queryPool, firstQuery, accelerationStructureCount, perfQueryPass, QUERYSTATE_ENDED, |
| 4634 | localQueryToStateMap); |
| 4635 | }); |
| 4636 | } |
| 4637 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4638 | void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo, |
| 4639 | const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer, |
| 4640 | VkResult result) { |
| 4641 | if (VK_SUCCESS != result) return; |
| 4642 | // Shadow create info and store in map |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 4643 | auto fb_state = std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, GetRenderPassShared(pCreateInfo->renderPass)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4644 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4645 | if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4646 | fb_state->attachments_view_state.resize(pCreateInfo->attachmentCount); |
| 4647 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4648 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4649 | fb_state->attachments_view_state[i] = GetShared<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4650 | } |
| 4651 | } |
| 4652 | frameBufferMap[*pFramebuffer] = std::move(fb_state); |
| 4653 | } |
| 4654 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4655 | void ValidationStateTracker::RecordRenderPassDAG(RenderPassCreateVersion rp_version, const VkRenderPassCreateInfo2 *pCreateInfo, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4656 | RENDER_PASS_STATE *render_pass) { |
| 4657 | auto &subpass_to_node = render_pass->subpassToNode; |
| 4658 | subpass_to_node.resize(pCreateInfo->subpassCount); |
| 4659 | auto &self_dependencies = render_pass->self_dependencies; |
| 4660 | self_dependencies.resize(pCreateInfo->subpassCount); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4661 | auto &subpass_dependencies = render_pass->subpass_dependencies; |
| 4662 | subpass_dependencies.resize(pCreateInfo->subpassCount); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4663 | |
| 4664 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { |
| 4665 | subpass_to_node[i].pass = i; |
| 4666 | self_dependencies[i].clear(); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4667 | subpass_dependencies[i].pass = i; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4668 | } |
| 4669 | for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4670 | const auto &dependency = pCreateInfo->pDependencies[i]; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4671 | const auto src_subpass = dependency.srcSubpass; |
| 4672 | const auto dst_subpass = dependency.dstSubpass; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4673 | if ((dependency.srcSubpass != VK_SUBPASS_EXTERNAL) && (dependency.dstSubpass != VK_SUBPASS_EXTERNAL)) { |
| 4674 | if (dependency.srcSubpass == dependency.dstSubpass) { |
| 4675 | self_dependencies[dependency.srcSubpass].push_back(i); |
| 4676 | } else { |
| 4677 | subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass); |
| 4678 | subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass); |
| 4679 | } |
| 4680 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4681 | if (src_subpass == VK_SUBPASS_EXTERNAL) { |
| 4682 | assert(dst_subpass != VK_SUBPASS_EXTERNAL); // this is invalid per VUID-VkSubpassDependency-srcSubpass-00865 |
| 4683 | subpass_dependencies[dst_subpass].barrier_from_external.emplace_back(&dependency); |
| 4684 | } else if (dst_subpass == VK_SUBPASS_EXTERNAL) { |
| 4685 | subpass_dependencies[src_subpass].barrier_to_external.emplace_back(&dependency); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4686 | } else if (dependency.srcSubpass != dependency.dstSubpass) { |
| 4687 | // ignore self dependencies in prev and next |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4688 | subpass_dependencies[src_subpass].next[&subpass_dependencies[dst_subpass]].emplace_back(&dependency); |
| 4689 | subpass_dependencies[dst_subpass].prev[&subpass_dependencies[src_subpass]].emplace_back(&dependency); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4690 | } |
| 4691 | } |
| 4692 | |
| 4693 | // |
| 4694 | // Determine "asynchrononous" subpassess |
| 4695 | // syncronization is only interested in asyncronous stages *earlier* that the current one... so we'll only look towards those. |
| 4696 | // NOTE: This is O(N^3), which we could shrink to O(N^2logN) using sets instead of arrays, but given that N is likely to be |
| 4697 | // small and the K for |= from the prev is must less than for set, we'll accept the brute force. |
| 4698 | std::vector<std::vector<bool>> pass_depends(pCreateInfo->subpassCount); |
| 4699 | for (uint32_t i = 1; i < pCreateInfo->subpassCount; ++i) { |
| 4700 | auto &depends = pass_depends[i]; |
| 4701 | depends.resize(i); |
| 4702 | auto &subpass_dep = subpass_dependencies[i]; |
| 4703 | for (const auto &prev : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4704 | const auto prev_pass = prev.first->pass; |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4705 | const auto &prev_depends = pass_depends[prev_pass]; |
| 4706 | for (uint32_t j = 0; j < prev_pass; j++) { |
| 4707 | depends[j] = depends[j] | prev_depends[j]; |
| 4708 | } |
| 4709 | depends[prev_pass] = true; |
| 4710 | } |
| 4711 | for (uint32_t pass = 0; pass < subpass_dep.pass; pass++) { |
| 4712 | if (!depends[pass]) { |
| 4713 | subpass_dep.async.push_back(pass); |
| 4714 | } |
| 4715 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4716 | } |
| 4717 | } |
| 4718 | |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4719 | static VkSubpassDependency2 ImplicitDependencyFromExternal(uint32_t subpass) { |
| 4720 | VkSubpassDependency2 from_external = {VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, |
| 4721 | nullptr, |
| 4722 | VK_SUBPASS_EXTERNAL, |
| 4723 | subpass, |
| 4724 | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, |
| 4725 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4726 | 0, |
| 4727 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | |
| 4728 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | |
| 4729 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, |
| 4730 | 0, |
| 4731 | 0}; |
| 4732 | return from_external; |
| 4733 | } |
| 4734 | |
| 4735 | static VkSubpassDependency2 ImplicitDependencyToExternal(uint32_t subpass) { |
| 4736 | VkSubpassDependency2 to_external = {VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, |
| 4737 | nullptr, |
| 4738 | subpass, |
| 4739 | VK_SUBPASS_EXTERNAL, |
| 4740 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4741 | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, |
| 4742 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | |
| 4743 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | |
| 4744 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, |
| 4745 | 0, |
| 4746 | 0, |
| 4747 | 0}; |
| 4748 | return to_external; |
| 4749 | } |
| 4750 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4751 | void ValidationStateTracker::RecordCreateRenderPassState(RenderPassCreateVersion rp_version, |
| 4752 | std::shared_ptr<RENDER_PASS_STATE> &render_pass, |
| 4753 | VkRenderPass *pRenderPass) { |
| 4754 | render_pass->renderPass = *pRenderPass; |
| 4755 | auto create_info = render_pass->createInfo.ptr(); |
| 4756 | |
| 4757 | RecordRenderPassDAG(RENDER_PASS_VERSION_1, create_info, render_pass.get()); |
| 4758 | |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4759 | struct AttachmentTracker { // This is really only of local interest, but a bit big for a lambda |
| 4760 | RENDER_PASS_STATE *const rp; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4761 | std::vector<uint32_t> &first; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4762 | std::vector<bool> &first_is_transition; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4763 | std::vector<uint32_t> &last; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4764 | std::vector<std::vector<RENDER_PASS_STATE::AttachmentTransition>> &subpass_transitions; |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 4765 | layer_data::unordered_map<uint32_t, bool> &first_read; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4766 | const uint32_t attachment_count; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4767 | std::vector<VkImageLayout> attachment_layout; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4768 | std::vector<std::vector<VkImageLayout>> subpass_attachment_layout; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4769 | explicit AttachmentTracker(std::shared_ptr<RENDER_PASS_STATE> &render_pass) |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4770 | : rp(render_pass.get()), |
| 4771 | first(rp->attachment_first_subpass), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4772 | first_is_transition(rp->attachment_first_is_transition), |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4773 | last(rp->attachment_last_subpass), |
| 4774 | subpass_transitions(rp->subpass_transitions), |
| 4775 | first_read(rp->attachment_first_read), |
| 4776 | attachment_count(rp->createInfo.attachmentCount), |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4777 | attachment_layout(), |
| 4778 | subpass_attachment_layout() { |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4779 | first.resize(attachment_count, VK_SUBPASS_EXTERNAL); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4780 | first_is_transition.resize(attachment_count, false); |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4781 | last.resize(attachment_count, VK_SUBPASS_EXTERNAL); |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4782 | subpass_transitions.resize(rp->createInfo.subpassCount + 1); // Add an extra for EndRenderPass |
| 4783 | attachment_layout.reserve(attachment_count); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4784 | subpass_attachment_layout.resize(rp->createInfo.subpassCount); |
| 4785 | for (auto &subpass_layouts : subpass_attachment_layout) { |
| 4786 | subpass_layouts.resize(attachment_count, kInvalidLayout); |
| 4787 | } |
| 4788 | |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4789 | for (uint32_t j = 0; j < attachment_count; j++) { |
| 4790 | attachment_layout.push_back(rp->createInfo.pAttachments[j].initialLayout); |
| 4791 | } |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4792 | } |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4793 | |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4794 | void Update(uint32_t subpass, const VkAttachmentReference2 *attach_ref, uint32_t count, bool is_read) { |
| 4795 | if (nullptr == attach_ref) return; |
| 4796 | for (uint32_t j = 0; j < count; ++j) { |
| 4797 | const auto attachment = attach_ref[j].attachment; |
| 4798 | if (attachment != VK_ATTACHMENT_UNUSED) { |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4799 | const auto layout = attach_ref[j].layout; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4800 | // Take advantage of the fact that insert won't overwrite, so we'll only write the first time. |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 4801 | first_read.emplace(attachment, is_read); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4802 | if (first[attachment] == VK_SUBPASS_EXTERNAL) { |
| 4803 | first[attachment] = subpass; |
| 4804 | const auto initial_layout = rp->createInfo.pAttachments[attachment].initialLayout; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4805 | if (initial_layout != layout) { |
| 4806 | subpass_transitions[subpass].emplace_back(VK_SUBPASS_EXTERNAL, attachment, initial_layout, layout); |
| 4807 | first_is_transition[attachment] = true; |
| 4808 | } |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4809 | } |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4810 | last[attachment] = subpass; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4811 | |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4812 | for (const auto &prev : rp->subpass_dependencies[subpass].prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4813 | const auto prev_pass = prev.first->pass; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4814 | const auto prev_layout = subpass_attachment_layout[prev_pass][attachment]; |
| 4815 | if ((prev_layout != kInvalidLayout) && (prev_layout != layout)) { |
| 4816 | subpass_transitions[subpass].emplace_back(prev_pass, attachment, prev_layout, layout); |
| 4817 | } |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4818 | } |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4819 | attachment_layout[attachment] = layout; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4820 | } |
| 4821 | } |
| 4822 | } |
| 4823 | void FinalTransitions() { |
| 4824 | auto &final_transitions = subpass_transitions[rp->createInfo.subpassCount]; |
| 4825 | |
| 4826 | for (uint32_t attachment = 0; attachment < attachment_count; ++attachment) { |
| 4827 | const auto final_layout = rp->createInfo.pAttachments[attachment].finalLayout; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4828 | // Add final transitions for attachments that were used and change layout. |
| 4829 | if ((last[attachment] != VK_SUBPASS_EXTERNAL) && final_layout != attachment_layout[attachment]) { |
| 4830 | final_transitions.emplace_back(last[attachment], attachment, attachment_layout[attachment], final_layout); |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4831 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4832 | } |
| 4833 | } |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4834 | }; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4835 | AttachmentTracker attachment_tracker(render_pass); |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4836 | |
| 4837 | for (uint32_t subpass_index = 0; subpass_index < create_info->subpassCount; ++subpass_index) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4838 | const VkSubpassDescription2 &subpass = create_info->pSubpasses[subpass_index]; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4839 | attachment_tracker.Update(subpass_index, subpass.pColorAttachments, subpass.colorAttachmentCount, false); |
| 4840 | attachment_tracker.Update(subpass_index, subpass.pResolveAttachments, subpass.colorAttachmentCount, false); |
| 4841 | attachment_tracker.Update(subpass_index, subpass.pDepthStencilAttachment, 1, false); |
| 4842 | attachment_tracker.Update(subpass_index, subpass.pInputAttachments, subpass.inputAttachmentCount, true); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4843 | } |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4844 | attachment_tracker.FinalTransitions(); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4845 | |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4846 | // Add implicit dependencies |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4847 | for (uint32_t attachment = 0; attachment < attachment_tracker.attachment_count; attachment++) { |
| 4848 | const auto first_use = attachment_tracker.first[attachment]; |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4849 | if (first_use != VK_SUBPASS_EXTERNAL) { |
| 4850 | auto &subpass_dep = render_pass->subpass_dependencies[first_use]; |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4851 | if (subpass_dep.barrier_from_external.size() == 0) { |
| 4852 | // Add implicit from barrier if they're aren't any |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4853 | subpass_dep.implicit_barrier_from_external.reset( |
| 4854 | new VkSubpassDependency2(ImplicitDependencyFromExternal(first_use))); |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4855 | subpass_dep.barrier_from_external.emplace_back(subpass_dep.implicit_barrier_from_external.get()); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4856 | } |
| 4857 | } |
| 4858 | |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4859 | const auto last_use = attachment_tracker.last[attachment]; |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4860 | if (last_use != VK_SUBPASS_EXTERNAL) { |
| 4861 | auto &subpass_dep = render_pass->subpass_dependencies[last_use]; |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4862 | if (render_pass->subpass_dependencies[last_use].barrier_to_external.size() == 0) { |
| 4863 | // Add implicit to barrier if they're aren't any |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4864 | subpass_dep.implicit_barrier_to_external.reset(new VkSubpassDependency2(ImplicitDependencyToExternal(last_use))); |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4865 | subpass_dep.barrier_to_external.emplace_back(subpass_dep.implicit_barrier_to_external.get()); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4866 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4867 | } |
| 4868 | } |
| 4869 | |
| 4870 | // Even though render_pass is an rvalue-ref parameter, still must move s.t. move assignment is invoked. |
| 4871 | renderPassMap[*pRenderPass] = std::move(render_pass); |
| 4872 | } |
| 4873 | |
| 4874 | // Style note: |
| 4875 | // Use of rvalue reference exceeds reccommended usage of rvalue refs in google style guide, but intentionally forces caller to move |
| 4876 | // or copy. This is clearer than passing a pointer to shared_ptr and avoids the atomic increment/decrement of shared_ptr copy |
| 4877 | // construction or assignment. |
| 4878 | void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, |
| 4879 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4880 | VkResult result) { |
| 4881 | if (VK_SUCCESS != result) return; |
| 4882 | auto render_pass_state = std::make_shared<RENDER_PASS_STATE>(pCreateInfo); |
| 4883 | RecordCreateRenderPassState(RENDER_PASS_VERSION_1, render_pass_state, pRenderPass); |
| 4884 | } |
| 4885 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4886 | void ValidationStateTracker::RecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo, |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4887 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4888 | VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4889 | if (VK_SUCCESS != result) return; |
| 4890 | auto render_pass_state = std::make_shared<RENDER_PASS_STATE>(pCreateInfo); |
| 4891 | RecordCreateRenderPassState(RENDER_PASS_VERSION_2, render_pass_state, pRenderPass); |
| 4892 | } |
| 4893 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4894 | void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo, |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4895 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4896 | VkResult result) { |
| 4897 | RecordCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass, result); |
| 4898 | } |
| 4899 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4900 | void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo, |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4901 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4902 | VkResult result) { |
| 4903 | RecordCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass, result); |
| 4904 | } |
| 4905 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4906 | void ValidationStateTracker::RecordCmdBeginRenderPassState(VkCommandBuffer commandBuffer, |
| 4907 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4908 | const VkSubpassContents contents) { |
| 4909 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4910 | auto render_pass_state = pRenderPassBegin ? GetShared<RENDER_PASS_STATE>(pRenderPassBegin->renderPass) : nullptr; |
| 4911 | auto framebuffer = pRenderPassBegin ? GetShared<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer) : nullptr; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4912 | |
| 4913 | if (render_pass_state) { |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4914 | cb_state->activeFramebuffer = framebuffer; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4915 | cb_state->activeRenderPass = render_pass_state; |
Tony-LunarG | 61e7c0c | 2020-03-03 16:09:11 -0700 | [diff] [blame] | 4916 | cb_state->activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4917 | cb_state->activeSubpass = 0; |
| 4918 | cb_state->activeSubpassContents = contents; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 4919 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4920 | // Connect this RP to cmdBuffer |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4921 | AddCommandBufferBinding( |
| 4922 | render_pass_state->cb_bindings, |
| 4923 | VulkanTypedHandle(render_pass_state->renderPass, kVulkanObjectTypeRenderPass, render_pass_state.get()), cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4924 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 4925 | auto chained_device_group_struct = LvlFindInChain<VkDeviceGroupRenderPassBeginInfo>(pRenderPassBegin->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4926 | if (chained_device_group_struct) { |
| 4927 | cb_state->active_render_pass_device_mask = chained_device_group_struct->deviceMask; |
| 4928 | } else { |
| 4929 | cb_state->active_render_pass_device_mask = cb_state->initial_device_mask; |
| 4930 | } |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 4931 | |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 4932 | cb_state->active_subpasses = nullptr; |
| 4933 | cb_state->active_attachments = nullptr; |
| 4934 | |
| 4935 | if (framebuffer) { |
| 4936 | cb_state->framebuffers.insert(framebuffer); |
| 4937 | |
| 4938 | // Set cb_state->active_subpasses |
| 4939 | cb_state->active_subpasses = |
| 4940 | std::make_shared<std::vector<SUBPASS_INFO>>(cb_state->activeFramebuffer->createInfo.attachmentCount); |
| 4941 | const auto &subpass = cb_state->activeRenderPass->createInfo.pSubpasses[cb_state->activeSubpass]; |
| 4942 | UpdateSubpassAttachments(subpass, *cb_state->active_subpasses); |
| 4943 | |
| 4944 | // Set cb_state->active_attachments & cb_state->attachments_view_states |
| 4945 | cb_state->active_attachments = |
| 4946 | std::make_shared<std::vector<IMAGE_VIEW_STATE *>>(framebuffer->createInfo.attachmentCount); |
| 4947 | UpdateAttachmentsView(*this, *cb_state, *cb_state->activeFramebuffer, pRenderPassBegin); |
| 4948 | |
| 4949 | // Connect this framebuffer and its children to this cmdBuffer |
| 4950 | AddFramebufferBinding(cb_state, framebuffer.get()); |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 4951 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, |
| 4956 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4957 | VkSubpassContents contents) { |
| 4958 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, contents); |
| 4959 | } |
| 4960 | |
| 4961 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4962 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4963 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4964 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents); |
| 4965 | } |
| 4966 | |
Jeremy Hayes | 9bda85a | 2020-05-21 16:36:17 -0600 | [diff] [blame] | 4967 | void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer, |
| 4968 | uint32_t counterBufferCount, |
| 4969 | const VkBuffer *pCounterBuffers, |
| 4970 | const VkDeviceSize *pCounterBufferOffsets) { |
| 4971 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4972 | |
| 4973 | cb_state->transform_feedback_active = true; |
| 4974 | } |
| 4975 | |
| 4976 | void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer, |
| 4977 | uint32_t counterBufferCount, const VkBuffer *pCounterBuffers, |
| 4978 | const VkDeviceSize *pCounterBufferOffsets) { |
| 4979 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4980 | |
| 4981 | cb_state->transform_feedback_active = false; |
| 4982 | } |
| 4983 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4984 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, |
| 4985 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4986 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4987 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents); |
| 4988 | } |
| 4989 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4990 | void ValidationStateTracker::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 4991 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4992 | cb_state->activeSubpass++; |
| 4993 | cb_state->activeSubpassContents = contents; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 4994 | |
| 4995 | // Update cb_state->active_subpasses |
| 4996 | if (cb_state->activeRenderPass && cb_state->activeFramebuffer) { |
| 4997 | cb_state->active_subpasses = nullptr; |
| 4998 | cb_state->active_subpasses = |
| 4999 | std::make_shared<std::vector<SUBPASS_INFO>>(cb_state->activeFramebuffer->createInfo.attachmentCount); |
| 5000 | |
| 5001 | const auto &subpass = cb_state->activeRenderPass->createInfo.pSubpasses[cb_state->activeSubpass]; |
| 5002 | UpdateSubpassAttachments(subpass, *cb_state->active_subpasses); |
| 5003 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 5007 | RecordCmdNextSubpass(commandBuffer, contents); |
| 5008 | } |
| 5009 | |
| 5010 | void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5011 | const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 5012 | const VkSubpassEndInfo *pSubpassEndInfo) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5013 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents); |
| 5014 | } |
| 5015 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5016 | void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5017 | const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 5018 | const VkSubpassEndInfo *pSubpassEndInfo) { |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5019 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents); |
| 5020 | } |
| 5021 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5022 | void ValidationStateTracker::RecordCmdEndRenderPassState(VkCommandBuffer commandBuffer) { |
| 5023 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5024 | cb_state->activeRenderPass = nullptr; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 5025 | cb_state->active_attachments = nullptr; |
| 5026 | cb_state->active_subpasses = nullptr; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5027 | cb_state->activeSubpass = 0; |
| 5028 | cb_state->activeFramebuffer = VK_NULL_HANDLE; |
| 5029 | } |
| 5030 | |
| 5031 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
| 5032 | RecordCmdEndRenderPassState(commandBuffer); |
| 5033 | } |
| 5034 | |
| 5035 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5036 | const VkSubpassEndInfo *pSubpassEndInfo) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5037 | RecordCmdEndRenderPassState(commandBuffer); |
| 5038 | } |
| 5039 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5040 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5041 | const VkSubpassEndInfo *pSubpassEndInfo) { |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5042 | RecordCmdEndRenderPassState(commandBuffer); |
| 5043 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5044 | void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, |
| 5045 | const VkCommandBuffer *pCommandBuffers) { |
| 5046 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5047 | |
| 5048 | CMD_BUFFER_STATE *sub_cb_state = NULL; |
| 5049 | for (uint32_t i = 0; i < commandBuffersCount; i++) { |
| 5050 | sub_cb_state = GetCBState(pCommandBuffers[i]); |
| 5051 | assert(sub_cb_state); |
| 5052 | if (!(sub_cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) { |
| 5053 | if (cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) { |
| 5054 | // TODO: Because this is a state change, clearing the VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT needs to be moved |
| 5055 | // from the validation step to the recording step |
| 5056 | cb_state->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; |
| 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | // Propagate inital layout and current layout state to the primary cmd buffer |
| 5061 | // NOTE: The update/population of the image_layout_map is done in CoreChecks, but for other classes derived from |
| 5062 | // ValidationStateTracker these maps will be empty, so leaving the propagation in the the state tracker should be a no-op |
| 5063 | // for those other classes. |
| 5064 | for (const auto &sub_layout_map_entry : sub_cb_state->image_layout_map) { |
| 5065 | const auto image = sub_layout_map_entry.first; |
| 5066 | const auto *image_state = GetImageState(image); |
| 5067 | if (!image_state) continue; // Can't set layouts of a dead image |
| 5068 | |
| 5069 | auto *cb_subres_map = GetImageSubresourceLayoutMap(cb_state, *image_state); |
John Zulauf | 17708d0 | 2021-02-22 11:20:58 -0700 | [diff] [blame] | 5070 | const auto *sub_cb_subres_map = &sub_layout_map_entry.second; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5071 | assert(cb_subres_map && sub_cb_subres_map); // Non const get and map traversal should never be null |
| 5072 | cb_subres_map->UpdateFrom(*sub_cb_subres_map); |
| 5073 | } |
| 5074 | |
| 5075 | sub_cb_state->primaryCommandBuffer = cb_state->commandBuffer; |
| 5076 | cb_state->linkedCommandBuffers.insert(sub_cb_state); |
| 5077 | sub_cb_state->linkedCommandBuffers.insert(cb_state); |
| 5078 | for (auto &function : sub_cb_state->queryUpdates) { |
| 5079 | cb_state->queryUpdates.push_back(function); |
| 5080 | } |
| 5081 | for (auto &function : sub_cb_state->queue_submit_functions) { |
| 5082 | cb_state->queue_submit_functions.push_back(function); |
| 5083 | } |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 5084 | |
| 5085 | // State is trashed after executing secondary command buffers. |
| 5086 | // Importantly, this function runs after CoreChecks::PreCallValidateCmdExecuteCommands. |
| 5087 | cb_state->trashedViewportMask = ~uint32_t(0); |
| 5088 | cb_state->trashedScissorMask = ~uint32_t(0); |
| 5089 | cb_state->trashedViewportCount = true; |
| 5090 | cb_state->trashedScissorCount = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5091 | } |
| 5092 | } |
| 5093 | |
| 5094 | void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, |
| 5095 | VkFlags flags, void **ppData, VkResult result) { |
| 5096 | if (VK_SUCCESS != result) return; |
| 5097 | RecordMappedMemory(mem, offset, size, ppData); |
| 5098 | } |
| 5099 | |
| 5100 | void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) { |
| 5101 | auto mem_info = GetDevMemState(mem); |
| 5102 | if (mem_info) { |
| 5103 | mem_info->mapped_range = MemRange(); |
| 5104 | mem_info->p_driver_data = nullptr; |
| 5105 | } |
| 5106 | } |
| 5107 | |
| 5108 | void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) { |
| 5109 | IMAGE_STATE *image_state = GetImageState(bindInfo.image); |
| 5110 | if (image_state) { |
locke-lunarg | ae26eac | 2020-04-16 15:29:05 -0600 | [diff] [blame] | 5111 | // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory. |
| 5112 | // See: VUID-vkGetImageSubresourceLayout-image-01895 |
| 5113 | image_state->fragment_encoder = |
| 5114 | std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state)); |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 5115 | const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5116 | if (swapchain_info) { |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 5117 | auto *swapchain = GetSwapchainState(swapchain_info->swapchain); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5118 | if (swapchain) { |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 5119 | SWAPCHAIN_IMAGE &swap_image = swapchain->images[swapchain_info->imageIndex]; |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 5120 | if (swap_image.bound_images.empty()) { |
| 5121 | // If this is the first "binding" of an image to this swapchain index, get a fake allocation |
| 5122 | image_state->swapchain_fake_address = fake_memory.Alloc(image_state->fragment_encoder->TotalSize()); |
| 5123 | } else { |
| 5124 | image_state->swapchain_fake_address = (*swap_image.bound_images.cbegin())->swapchain_fake_address; |
| 5125 | } |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 5126 | swap_image.bound_images.emplace(image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5127 | image_state->bind_swapchain = swapchain_info->swapchain; |
| 5128 | image_state->bind_swapchain_imageIndex = swapchain_info->imageIndex; |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 5129 | |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 5130 | // All images bound to this swapchain and index are aliases |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 5131 | AddAliasingImage(image_state, &swap_image.bound_images); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5132 | } |
| 5133 | } else { |
| 5134 | // Track bound memory range information |
| 5135 | auto mem_info = GetDevMemState(bindInfo.memory); |
| 5136 | if (mem_info) { |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 5137 | InsertImageMemoryRange(image_state, mem_info, bindInfo.memoryOffset); |
| 5138 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_ALIAS_BIT) { |
| 5139 | AddAliasingImage(image_state, &mem_info->bound_images); |
| 5140 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | // Track objects tied to memory |
| 5144 | SetMemBinding(bindInfo.memory, image_state, bindInfo.memoryOffset, |
| 5145 | VulkanTypedHandle(bindInfo.image, kVulkanObjectTypeImage)); |
| 5146 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5147 | } |
| 5148 | } |
| 5149 | |
| 5150 | void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem, |
| 5151 | VkDeviceSize memoryOffset, VkResult result) { |
| 5152 | if (VK_SUCCESS != result) return; |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 5153 | auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5154 | bind_info.image = image; |
| 5155 | bind_info.memory = mem; |
| 5156 | bind_info.memoryOffset = memoryOffset; |
| 5157 | UpdateBindImageMemoryState(bind_info); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5161 | const VkBindImageMemoryInfo *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5162 | if (VK_SUCCESS != result) return; |
| 5163 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 5164 | UpdateBindImageMemoryState(pBindInfos[i]); |
| 5165 | } |
| 5166 | } |
| 5167 | |
| 5168 | void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5169 | const VkBindImageMemoryInfo *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5170 | if (VK_SUCCESS != result) return; |
| 5171 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 5172 | UpdateBindImageMemoryState(pBindInfos[i]); |
| 5173 | } |
| 5174 | } |
| 5175 | |
| 5176 | void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) { |
| 5177 | auto event_state = GetEventState(event); |
| 5178 | if (event_state) { |
| 5179 | event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT; |
| 5180 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device, |
| 5184 | const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo, |
| 5185 | VkResult result) { |
| 5186 | if (VK_SUCCESS != result) return; |
| 5187 | RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType, |
| 5188 | pImportSemaphoreFdInfo->flags); |
| 5189 | } |
| 5190 | |
| 5191 | void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5192 | VkExternalSemaphoreHandleTypeFlagBits handle_type) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5193 | SEMAPHORE_STATE *semaphore_state = GetSemaphoreState(semaphore); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5194 | if (semaphore_state && handle_type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5195 | // Cannot track semaphore state once it is exported, except for Sync FD handle types which have copy transference |
| 5196 | semaphore_state->scope = kSyncScopeExternalPermanent; |
| 5197 | } |
| 5198 | } |
| 5199 | |
| 5200 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 5201 | void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR( |
| 5202 | VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) { |
| 5203 | if (VK_SUCCESS != result) return; |
| 5204 | RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType, |
| 5205 | pImportSemaphoreWin32HandleInfo->flags); |
| 5206 | } |
| 5207 | |
| 5208 | void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device, |
| 5209 | const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo, |
| 5210 | HANDLE *pHandle, VkResult result) { |
| 5211 | if (VK_SUCCESS != result) return; |
| 5212 | RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType); |
| 5213 | } |
| 5214 | |
| 5215 | void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR( |
| 5216 | VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) { |
| 5217 | if (VK_SUCCESS != result) return; |
| 5218 | RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType, |
| 5219 | pImportFenceWin32HandleInfo->flags); |
| 5220 | } |
| 5221 | |
| 5222 | void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device, |
| 5223 | const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo, |
| 5224 | HANDLE *pHandle, VkResult result) { |
| 5225 | if (VK_SUCCESS != result) return; |
| 5226 | RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType); |
| 5227 | } |
| 5228 | #endif |
| 5229 | |
| 5230 | void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd, |
| 5231 | VkResult result) { |
| 5232 | if (VK_SUCCESS != result) return; |
| 5233 | RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType); |
| 5234 | } |
| 5235 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5236 | void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type, |
| 5237 | VkFenceImportFlags flags) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5238 | FENCE_STATE *fence_node = GetFenceState(fence); |
| 5239 | if (fence_node && fence_node->scope != kSyncScopeExternalPermanent) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5240 | if ((handle_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_FENCE_IMPORT_TEMPORARY_BIT) && |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5241 | fence_node->scope == kSyncScopeInternal) { |
| 5242 | fence_node->scope = kSyncScopeExternalTemporary; |
| 5243 | } else { |
| 5244 | fence_node->scope = kSyncScopeExternalPermanent; |
| 5245 | } |
| 5246 | } |
| 5247 | } |
| 5248 | |
| 5249 | void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo, |
| 5250 | VkResult result) { |
| 5251 | if (VK_SUCCESS != result) return; |
| 5252 | RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags); |
| 5253 | } |
| 5254 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5255 | void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5256 | FENCE_STATE *fence_state = GetFenceState(fence); |
| 5257 | if (fence_state) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5258 | if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5259 | // Export with reference transference becomes external |
| 5260 | fence_state->scope = kSyncScopeExternalPermanent; |
| 5261 | } else if (fence_state->scope == kSyncScopeInternal) { |
| 5262 | // Export with copy transference has a side effect of resetting the fence |
| 5263 | fence_state->state = FENCE_UNSIGNALED; |
| 5264 | } |
| 5265 | } |
| 5266 | } |
| 5267 | |
| 5268 | void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd, |
| 5269 | VkResult result) { |
| 5270 | if (VK_SUCCESS != result) return; |
| 5271 | RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType); |
| 5272 | } |
| 5273 | |
| 5274 | void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo, |
| 5275 | const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) { |
| 5276 | if (VK_SUCCESS != result) return; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 5277 | const auto event = *pEvent; |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 5278 | eventMap.emplace(event, std::make_shared<EVENT_STATE>(event, pCreateInfo->flags)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5279 | } |
| 5280 | |
| 5281 | void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 5282 | VkSwapchainKHR *pSwapchain, SURFACE_STATE *surface_state, |
| 5283 | SWAPCHAIN_NODE *old_swapchain_state) { |
| 5284 | if (VK_SUCCESS == result) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5285 | auto swapchain_state = std::make_shared<SWAPCHAIN_NODE>(pCreateInfo, *pSwapchain); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5286 | if (VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR == pCreateInfo->presentMode || |
| 5287 | VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR == pCreateInfo->presentMode) { |
| 5288 | swapchain_state->shared_presentable = true; |
| 5289 | } |
| 5290 | surface_state->swapchain = swapchain_state.get(); |
| 5291 | swapchainMap[*pSwapchain] = std::move(swapchain_state); |
| 5292 | } else { |
| 5293 | surface_state->swapchain = nullptr; |
| 5294 | } |
| 5295 | // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired |
| 5296 | if (old_swapchain_state) { |
| 5297 | old_swapchain_state->retired = true; |
| 5298 | } |
| 5299 | return; |
| 5300 | } |
| 5301 | |
| 5302 | void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 5303 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain, |
| 5304 | VkResult result) { |
| 5305 | auto surface_state = GetSurfaceState(pCreateInfo->surface); |
| 5306 | auto old_swapchain_state = GetSwapchainState(pCreateInfo->oldSwapchain); |
| 5307 | RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, surface_state, old_swapchain_state); |
| 5308 | } |
| 5309 | |
| 5310 | void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 5311 | const VkAllocationCallbacks *pAllocator) { |
| 5312 | if (!swapchain) return; |
| 5313 | auto swapchain_data = GetSwapchainState(swapchain); |
| 5314 | if (swapchain_data) { |
John Zulauf | faa7a52 | 2021-03-05 12:22:45 -0700 | [diff] [blame] | 5315 | for (auto &swapchain_image : swapchain_data->images) { |
| 5316 | // TODO: missing validation that the bound images are empty (except for image_state above) |
| 5317 | // Clean up the aliases and the bound_images *before* erasing the image_state. |
| 5318 | RemoveAliasingImages(swapchain_image.bound_images); |
| 5319 | swapchain_image.bound_images.clear(); |
| 5320 | |
| 5321 | if (swapchain_image.image_state) { |
John Zulauf | 2d60a45 | 2021-03-04 15:12:03 -0700 | [diff] [blame] | 5322 | ClearMemoryObjectBindings(VulkanTypedHandle(swapchain_image.image_state->image, kVulkanObjectTypeImage)); |
| 5323 | imageMap.erase(swapchain_image.image_state->image); |
John Zulauf | faa7a52 | 2021-03-05 12:22:45 -0700 | [diff] [blame] | 5324 | swapchain_image.image_state = nullptr; |
John Zulauf | 2d60a45 | 2021-03-04 15:12:03 -0700 | [diff] [blame] | 5325 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | auto surface_state = GetSurfaceState(swapchain_data->createInfo.surface); |
| 5329 | if (surface_state) { |
| 5330 | if (surface_state->swapchain == swapchain_data) surface_state->swapchain = nullptr; |
| 5331 | } |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5332 | swapchain_data->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5333 | swapchainMap.erase(swapchain); |
| 5334 | } |
| 5335 | } |
| 5336 | |
sfricke-samsung | 5c1b739 | 2020-12-13 22:17:15 -0800 | [diff] [blame] | 5337 | void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, |
| 5338 | const VkDisplayModeCreateInfoKHR *pCreateInfo, |
| 5339 | const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode, |
| 5340 | VkResult result) { |
| 5341 | if (VK_SUCCESS != result) return; |
| 5342 | if (!pMode) return; |
| 5343 | auto display_mode_state = std::make_shared<DISPLAY_MODE_STATE>(*pMode); |
| 5344 | display_mode_state->physical_device = physicalDevice; |
| 5345 | display_mode_map[*pMode] = std::move(display_mode_state); |
| 5346 | } |
| 5347 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5348 | void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) { |
| 5349 | // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?) |
| 5350 | for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5351 | auto semaphore_state = GetSemaphoreState(pPresentInfo->pWaitSemaphores[i]); |
| 5352 | if (semaphore_state) { |
| 5353 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
| 5354 | semaphore_state->signaled = false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5355 | } |
| 5356 | } |
| 5357 | |
| 5358 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) { |
| 5359 | // Note: this is imperfect, in that we can get confused about what did or didn't succeed-- but if the app does that, it's |
| 5360 | // confused itself just as much. |
| 5361 | auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result; |
| 5362 | if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen. |
| 5363 | // Mark the image as having been released to the WSI |
| 5364 | auto swapchain_data = GetSwapchainState(pPresentInfo->pSwapchains[i]); |
| 5365 | if (swapchain_data && (swapchain_data->images.size() > pPresentInfo->pImageIndices[i])) { |
John Zulauf | faa7a52 | 2021-03-05 12:22:45 -0700 | [diff] [blame] | 5366 | IMAGE_STATE *image_state = swapchain_data->images[pPresentInfo->pImageIndices[i]].image_state; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5367 | if (image_state) { |
| 5368 | image_state->acquired = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 5369 | if (image_state->shared_presentable) { |
| 5370 | image_state->layout_locked = true; |
| 5371 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5372 | } |
| 5373 | } |
| 5374 | } |
| 5375 | // Note: even though presentation is directed to a queue, there is no direct ordering between QP and subsequent work, so QP (and |
| 5376 | // its semaphore waits) /never/ participate in any completion proof. |
| 5377 | } |
| 5378 | |
| 5379 | void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 5380 | const VkSwapchainCreateInfoKHR *pCreateInfos, |
| 5381 | const VkAllocationCallbacks *pAllocator, |
| 5382 | VkSwapchainKHR *pSwapchains, VkResult result) { |
| 5383 | if (pCreateInfos) { |
| 5384 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| 5385 | auto surface_state = GetSurfaceState(pCreateInfos[i].surface); |
| 5386 | auto old_swapchain_state = GetSwapchainState(pCreateInfos[i].oldSwapchain); |
| 5387 | RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], surface_state, old_swapchain_state); |
| 5388 | } |
| 5389 | } |
| 5390 | } |
| 5391 | |
| 5392 | void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 5393 | VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5394 | auto fence_state = GetFenceState(fence); |
| 5395 | if (fence_state && fence_state->scope == kSyncScopeInternal) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5396 | // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary |
| 5397 | // import |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5398 | fence_state->state = FENCE_INFLIGHT; |
| 5399 | fence_state->signaler.first = VK_NULL_HANDLE; // ANI isn't on a queue, so this can't participate in a completion proof. |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5400 | } |
| 5401 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5402 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 5403 | if (semaphore_state && semaphore_state->scope == kSyncScopeInternal) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5404 | // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a |
| 5405 | // temporary import |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5406 | semaphore_state->signaled = true; |
| 5407 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | // Mark the image as acquired. |
| 5411 | auto swapchain_data = GetSwapchainState(swapchain); |
| 5412 | if (swapchain_data && (swapchain_data->images.size() > *pImageIndex)) { |
John Zulauf | faa7a52 | 2021-03-05 12:22:45 -0700 | [diff] [blame] | 5413 | IMAGE_STATE *image_state = swapchain_data->images[*pImageIndex].image_state; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5414 | if (image_state) { |
| 5415 | image_state->acquired = true; |
| 5416 | image_state->shared_presentable = swapchain_data->shared_presentable; |
| 5417 | } |
| 5418 | } |
| 5419 | } |
| 5420 | |
| 5421 | void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 5422 | VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex, |
| 5423 | VkResult result) { |
| 5424 | if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return; |
| 5425 | RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex); |
| 5426 | } |
| 5427 | |
| 5428 | void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo, |
| 5429 | uint32_t *pImageIndex, VkResult result) { |
| 5430 | if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return; |
| 5431 | RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore, |
| 5432 | pAcquireInfo->fence, pImageIndex); |
| 5433 | } |
| 5434 | |
| 5435 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 5436 | VkPhysicalDevice *pPhysicalDevices, VkResult result) { |
| 5437 | if ((NULL != pPhysicalDevices) && ((result == VK_SUCCESS || result == VK_INCOMPLETE))) { |
| 5438 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
| 5439 | auto &phys_device_state = physical_device_map[pPhysicalDevices[i]]; |
| 5440 | phys_device_state.phys_device = pPhysicalDevices[i]; |
| 5441 | // Init actual features for each physical device |
| 5442 | DispatchGetPhysicalDeviceFeatures(pPhysicalDevices[i], &phys_device_state.features2.features); |
| 5443 | } |
| 5444 | } |
| 5445 | } |
| 5446 | |
| 5447 | // Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
| 5448 | static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5449 | VkQueueFamilyProperties2 *pQueueFamilyProperties) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5450 | pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count); |
| 5451 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5452 | if (pQueueFamilyProperties) { // Save queue family properties |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5453 | pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count)); |
| 5454 | for (uint32_t i = 0; i < count; ++i) { |
| 5455 | pd_state->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties; |
| 5456 | } |
| 5457 | } |
| 5458 | } |
| 5459 | |
| 5460 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 5461 | uint32_t *pQueueFamilyPropertyCount, |
| 5462 | VkQueueFamilyProperties *pQueueFamilyProperties) { |
| 5463 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5464 | assert(physical_device_state); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5465 | VkQueueFamilyProperties2 *pqfp = nullptr; |
| 5466 | std::vector<VkQueueFamilyProperties2> qfp; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5467 | qfp.resize(*pQueueFamilyPropertyCount); |
| 5468 | if (pQueueFamilyProperties) { |
| 5469 | for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; ++i) { |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 5470 | qfp[i] = LvlInitStruct<VkQueueFamilyProperties2>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5471 | qfp[i].queueFamilyProperties = pQueueFamilyProperties[i]; |
| 5472 | } |
| 5473 | pqfp = qfp.data(); |
| 5474 | } |
| 5475 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, pqfp); |
| 5476 | } |
| 5477 | |
| 5478 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5479 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5480 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5481 | assert(physical_device_state); |
| 5482 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 5483 | pQueueFamilyProperties); |
| 5484 | } |
| 5485 | |
| 5486 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5487 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5488 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5489 | assert(physical_device_state); |
| 5490 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 5491 | pQueueFamilyProperties); |
| 5492 | } |
| 5493 | void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, |
| 5494 | const VkAllocationCallbacks *pAllocator) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5495 | if (!surface) return; |
| 5496 | auto surface_state = GetSurfaceState(surface); |
| 5497 | surface_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5498 | surface_map.erase(surface); |
| 5499 | } |
| 5500 | |
| 5501 | void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5502 | surface_map[*pSurface] = std::make_shared<SURFACE_STATE>(*pSurface); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5503 | } |
| 5504 | |
| 5505 | void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance, |
| 5506 | const VkDisplaySurfaceCreateInfoKHR *pCreateInfo, |
| 5507 | const VkAllocationCallbacks *pAllocator, |
| 5508 | VkSurfaceKHR *pSurface, VkResult result) { |
| 5509 | if (VK_SUCCESS != result) return; |
| 5510 | RecordVulkanSurface(pSurface); |
| 5511 | } |
| 5512 | |
| 5513 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 5514 | void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance, |
| 5515 | const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, |
| 5516 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5517 | VkResult result) { |
| 5518 | if (VK_SUCCESS != result) return; |
| 5519 | RecordVulkanSurface(pSurface); |
| 5520 | } |
| 5521 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 5522 | |
| 5523 | #ifdef VK_USE_PLATFORM_IOS_MVK |
| 5524 | void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo, |
| 5525 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5526 | VkResult result) { |
| 5527 | if (VK_SUCCESS != result) return; |
| 5528 | RecordVulkanSurface(pSurface); |
| 5529 | } |
| 5530 | #endif // VK_USE_PLATFORM_IOS_MVK |
| 5531 | |
| 5532 | #ifdef VK_USE_PLATFORM_MACOS_MVK |
| 5533 | void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance, |
| 5534 | const VkMacOSSurfaceCreateInfoMVK *pCreateInfo, |
| 5535 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5536 | VkResult result) { |
| 5537 | if (VK_SUCCESS != result) return; |
| 5538 | RecordVulkanSurface(pSurface); |
| 5539 | } |
| 5540 | #endif // VK_USE_PLATFORM_MACOS_MVK |
| 5541 | |
Jeremy Kniager | f33a67c | 2019-12-09 09:44:39 -0700 | [diff] [blame] | 5542 | #ifdef VK_USE_PLATFORM_METAL_EXT |
| 5543 | void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance, |
| 5544 | const VkMetalSurfaceCreateInfoEXT *pCreateInfo, |
| 5545 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5546 | VkResult result) { |
| 5547 | if (VK_SUCCESS != result) return; |
| 5548 | RecordVulkanSurface(pSurface); |
| 5549 | } |
| 5550 | #endif // VK_USE_PLATFORM_METAL_EXT |
| 5551 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5552 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 5553 | void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance, |
| 5554 | const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, |
| 5555 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5556 | VkResult result) { |
| 5557 | if (VK_SUCCESS != result) return; |
| 5558 | RecordVulkanSurface(pSurface); |
| 5559 | } |
| 5560 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 5561 | |
| 5562 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 5563 | void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance, |
| 5564 | const VkWin32SurfaceCreateInfoKHR *pCreateInfo, |
| 5565 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5566 | VkResult result) { |
| 5567 | if (VK_SUCCESS != result) return; |
| 5568 | RecordVulkanSurface(pSurface); |
| 5569 | } |
| 5570 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 5571 | |
| 5572 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 5573 | void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, |
| 5574 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5575 | VkResult result) { |
| 5576 | if (VK_SUCCESS != result) return; |
| 5577 | RecordVulkanSurface(pSurface); |
| 5578 | } |
| 5579 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 5580 | |
| 5581 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 5582 | void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, |
| 5583 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5584 | VkResult result) { |
| 5585 | if (VK_SUCCESS != result) return; |
| 5586 | RecordVulkanSurface(pSurface); |
| 5587 | } |
| 5588 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 5589 | |
Niklas Haas | 8b84af1 | 2020-04-19 22:20:11 +0200 | [diff] [blame] | 5590 | void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance, |
| 5591 | const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo, |
| 5592 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5593 | VkResult result) { |
| 5594 | if (VK_SUCCESS != result) return; |
| 5595 | RecordVulkanSurface(pSurface); |
| 5596 | } |
| 5597 | |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5598 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5599 | VkPhysicalDeviceFeatures *pFeatures) { |
| 5600 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Yilong Li | 358152a | 2020-07-08 02:16:45 -0700 | [diff] [blame] | 5601 | // Reset the features2 safe struct before setting up the features field. |
| 5602 | physical_device_state->features2 = safe_VkPhysicalDeviceFeatures2(); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5603 | physical_device_state->features2.features = *pFeatures; |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5604 | } |
| 5605 | |
| 5606 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5607 | VkPhysicalDeviceFeatures2 *pFeatures) { |
| 5608 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5609 | physical_device_state->features2.initialize(pFeatures); |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5610 | } |
| 5611 | |
| 5612 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2KHR(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5613 | VkPhysicalDeviceFeatures2 *pFeatures) { |
| 5614 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5615 | physical_device_state->features2.initialize(pFeatures); |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5616 | } |
| 5617 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5618 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, |
| 5619 | VkSurfaceKHR surface, |
| 5620 | VkSurfaceCapabilitiesKHR *pSurfaceCapabilities, |
| 5621 | VkResult result) { |
| 5622 | if (VK_SUCCESS != result) return; |
| 5623 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5624 | physical_device_state->surfaceCapabilities = *pSurfaceCapabilities; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5625 | |
| 5626 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 5627 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR( |
| 5631 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, |
| 5632 | VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) { |
| 5633 | if (VK_SUCCESS != result) return; |
| 5634 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5635 | physical_device_state->surfaceCapabilities = pSurfaceCapabilities->surfaceCapabilities; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5636 | |
| 5637 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 5638 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice, |
| 5642 | VkSurfaceKHR surface, |
| 5643 | VkSurfaceCapabilities2EXT *pSurfaceCapabilities, |
| 5644 | VkResult result) { |
| 5645 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5646 | physical_device_state->surfaceCapabilities.minImageCount = pSurfaceCapabilities->minImageCount; |
| 5647 | physical_device_state->surfaceCapabilities.maxImageCount = pSurfaceCapabilities->maxImageCount; |
| 5648 | physical_device_state->surfaceCapabilities.currentExtent = pSurfaceCapabilities->currentExtent; |
| 5649 | physical_device_state->surfaceCapabilities.minImageExtent = pSurfaceCapabilities->minImageExtent; |
| 5650 | physical_device_state->surfaceCapabilities.maxImageExtent = pSurfaceCapabilities->maxImageExtent; |
| 5651 | physical_device_state->surfaceCapabilities.maxImageArrayLayers = pSurfaceCapabilities->maxImageArrayLayers; |
| 5652 | physical_device_state->surfaceCapabilities.supportedTransforms = pSurfaceCapabilities->supportedTransforms; |
| 5653 | physical_device_state->surfaceCapabilities.currentTransform = pSurfaceCapabilities->currentTransform; |
| 5654 | physical_device_state->surfaceCapabilities.supportedCompositeAlpha = pSurfaceCapabilities->supportedCompositeAlpha; |
| 5655 | physical_device_state->surfaceCapabilities.supportedUsageFlags = pSurfaceCapabilities->supportedUsageFlags; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5656 | |
| 5657 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 5658 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, |
| 5662 | uint32_t queueFamilyIndex, VkSurfaceKHR surface, |
| 5663 | VkBool32 *pSupported, VkResult result) { |
| 5664 | if (VK_SUCCESS != result) return; |
| 5665 | auto surface_state = GetSurfaceState(surface); |
| 5666 | surface_state->gpu_queue_support[{physicalDevice, queueFamilyIndex}] = (*pSupported == VK_TRUE); |
| 5667 | } |
| 5668 | |
| 5669 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, |
| 5670 | VkSurfaceKHR surface, |
| 5671 | uint32_t *pPresentModeCount, |
| 5672 | VkPresentModeKHR *pPresentModes, |
| 5673 | VkResult result) { |
| 5674 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5675 | |
| 5676 | // TODO: This isn't quite right -- available modes may differ by surface AND physical device. |
| 5677 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5678 | |
| 5679 | if (*pPresentModeCount) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5680 | if (*pPresentModeCount > physical_device_state->present_modes.size()) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5681 | physical_device_state->present_modes.resize(*pPresentModeCount); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5682 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5683 | } |
| 5684 | if (pPresentModes) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5685 | for (uint32_t i = 0; i < *pPresentModeCount; i++) { |
| 5686 | physical_device_state->present_modes[i] = pPresentModes[i]; |
| 5687 | } |
| 5688 | } |
| 5689 | } |
| 5690 | |
| 5691 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 5692 | uint32_t *pSurfaceFormatCount, |
| 5693 | VkSurfaceFormatKHR *pSurfaceFormats, |
| 5694 | VkResult result) { |
| 5695 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5696 | |
| 5697 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5698 | |
| 5699 | if (*pSurfaceFormatCount) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5700 | if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5701 | physical_device_state->surface_formats.resize(*pSurfaceFormatCount); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5702 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5703 | } |
| 5704 | if (pSurfaceFormats) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5705 | for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) { |
| 5706 | physical_device_state->surface_formats[i] = pSurfaceFormats[i]; |
| 5707 | } |
| 5708 | } |
| 5709 | } |
| 5710 | |
| 5711 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, |
| 5712 | const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, |
| 5713 | uint32_t *pSurfaceFormatCount, |
| 5714 | VkSurfaceFormat2KHR *pSurfaceFormats, |
| 5715 | VkResult result) { |
| 5716 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5717 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5718 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5719 | if (*pSurfaceFormatCount) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5720 | if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) { |
| 5721 | physical_device_state->surface_formats.resize(*pSurfaceFormatCount); |
| 5722 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5723 | } |
| 5724 | if (pSurfaceFormats) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5725 | for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5726 | physical_device_state->surface_formats[i] = pSurfaceFormats[i].surfaceFormat; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5727 | } |
| 5728 | } |
| 5729 | } |
| 5730 | |
| 5731 | void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, |
| 5732 | const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 5733 | BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo); |
| 5734 | } |
| 5735 | |
| 5736 | void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) { |
| 5737 | EndCmdDebugUtilsLabel(report_data, commandBuffer); |
| 5738 | } |
| 5739 | |
| 5740 | void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, |
| 5741 | const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 5742 | InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo); |
| 5743 | |
| 5744 | // Squirrel away an easily accessible copy. |
| 5745 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5746 | cb_state->debug_label = LoggingLabel(pLabelInfo); |
| 5747 | } |
| 5748 | |
| 5749 | void ValidationStateTracker::RecordEnumeratePhysicalDeviceGroupsState( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5750 | uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5751 | if (NULL != pPhysicalDeviceGroupProperties) { |
| 5752 | for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) { |
| 5753 | for (uint32_t j = 0; j < pPhysicalDeviceGroupProperties[i].physicalDeviceCount; j++) { |
| 5754 | VkPhysicalDevice cur_phys_dev = pPhysicalDeviceGroupProperties[i].physicalDevices[j]; |
| 5755 | auto &phys_device_state = physical_device_map[cur_phys_dev]; |
| 5756 | phys_device_state.phys_device = cur_phys_dev; |
| 5757 | // Init actual features for each physical device |
| 5758 | DispatchGetPhysicalDeviceFeatures(cur_phys_dev, &phys_device_state.features2.features); |
| 5759 | } |
| 5760 | } |
| 5761 | } |
| 5762 | } |
| 5763 | |
| 5764 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroups( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5765 | VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5766 | VkResult result) { |
| 5767 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5768 | RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties); |
| 5769 | } |
| 5770 | |
| 5771 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroupsKHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5772 | VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5773 | VkResult result) { |
| 5774 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5775 | RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties); |
| 5776 | } |
| 5777 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5778 | void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice, |
| 5779 | uint32_t queueFamilyIndex, |
| 5780 | uint32_t *pCounterCount, |
| 5781 | VkPerformanceCounterKHR *pCounters) { |
| 5782 | if (NULL == pCounters) return; |
| 5783 | |
| 5784 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5785 | assert(physical_device_state); |
| 5786 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5787 | std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS()); |
| 5788 | queue_family_counters->counters.resize(*pCounterCount); |
| 5789 | for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i]; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5790 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 5791 | physical_device_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters); |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5792 | } |
| 5793 | |
| 5794 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR( |
| 5795 | VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters, |
| 5796 | VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) { |
| 5797 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5798 | RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters); |
| 5799 | } |
| 5800 | |
| 5801 | void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo, |
| 5802 | VkResult result) { |
| 5803 | if (result == VK_SUCCESS) performance_lock_acquired = true; |
| 5804 | } |
| 5805 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5806 | void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) { |
| 5807 | performance_lock_acquired = false; |
| 5808 | for (auto &cmd_buffer : commandBufferMap) { |
| 5809 | cmd_buffer.second->performance_lock_released = true; |
| 5810 | } |
| 5811 | } |
| 5812 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5813 | void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5814 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5815 | const VkAllocationCallbacks *pAllocator) { |
| 5816 | if (!descriptorUpdateTemplate) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5817 | auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 5818 | template_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5819 | desc_template_map.erase(descriptorUpdateTemplate); |
| 5820 | } |
| 5821 | |
| 5822 | void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5823 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5824 | const VkAllocationCallbacks *pAllocator) { |
| 5825 | if (!descriptorUpdateTemplate) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5826 | auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 5827 | template_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5828 | desc_template_map.erase(descriptorUpdateTemplate); |
| 5829 | } |
| 5830 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5831 | void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, |
| 5832 | VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5833 | safe_VkDescriptorUpdateTemplateCreateInfo local_create_info(pCreateInfo); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5834 | auto template_state = std::make_shared<TEMPLATE_STATE>(*pDescriptorUpdateTemplate, &local_create_info); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5835 | desc_template_map[*pDescriptorUpdateTemplate] = std::move(template_state); |
| 5836 | } |
| 5837 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5838 | void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device, |
| 5839 | const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, |
| 5840 | const VkAllocationCallbacks *pAllocator, |
| 5841 | VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, |
| 5842 | VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5843 | if (VK_SUCCESS != result) return; |
| 5844 | RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate); |
| 5845 | } |
| 5846 | |
| 5847 | void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5848 | VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 5849 | VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5850 | if (VK_SUCCESS != result) return; |
| 5851 | RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate); |
| 5852 | } |
| 5853 | |
| 5854 | void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5855 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5856 | const void *pData) { |
| 5857 | auto const template_map_entry = desc_template_map.find(descriptorUpdateTemplate); |
| 5858 | if ((template_map_entry == desc_template_map.end()) || (template_map_entry->second.get() == nullptr)) { |
| 5859 | assert(0); |
| 5860 | } else { |
| 5861 | const TEMPLATE_STATE *template_state = template_map_entry->second.get(); |
| 5862 | // TODO: Record template push descriptor updates |
| 5863 | if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) { |
| 5864 | PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state, pData); |
| 5865 | } |
| 5866 | } |
| 5867 | } |
| 5868 | |
| 5869 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet, |
| 5870 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
| 5871 | const void *pData) { |
| 5872 | RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData); |
| 5873 | } |
| 5874 | |
| 5875 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5876 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5877 | const void *pData) { |
| 5878 | RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData); |
| 5879 | } |
| 5880 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 5881 | void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer, |
| 5882 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
| 5883 | VkPipelineLayout layout, uint32_t set, |
| 5884 | const void *pData) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5885 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5886 | |
| 5887 | const auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 5888 | if (template_state) { |
| 5889 | auto layout_data = GetPipelineLayout(layout); |
| 5890 | auto dsl = GetDslFromPipelineLayout(layout_data, set); |
| 5891 | const auto &template_ci = template_state->create_info; |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 5892 | if (dsl && !dsl->destroyed) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5893 | // Decode the template into a set of write updates |
| 5894 | cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state, pData, |
| 5895 | dsl->GetDescriptorSetLayout()); |
| 5896 | RecordCmdPushDescriptorSetState(cb_state, template_ci.pipelineBindPoint, layout, set, |
| 5897 | static_cast<uint32_t>(decoded_template.desc_writes.size()), |
| 5898 | decoded_template.desc_writes.data()); |
| 5899 | } |
| 5900 | } |
| 5901 | } |
| 5902 | |
| 5903 | void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice, |
| 5904 | uint32_t *pPropertyCount, void *pProperties) { |
| 5905 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5906 | if (*pPropertyCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5907 | physical_device_state->display_plane_property_count = *pPropertyCount; |
| 5908 | } |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5909 | if (*pPropertyCount || pProperties) { |
| 5910 | physical_device_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5911 | } |
| 5912 | } |
| 5913 | |
| 5914 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, |
| 5915 | uint32_t *pPropertyCount, |
| 5916 | VkDisplayPlanePropertiesKHR *pProperties, |
| 5917 | VkResult result) { |
| 5918 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5919 | RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties); |
| 5920 | } |
| 5921 | |
| 5922 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice, |
| 5923 | uint32_t *pPropertyCount, |
| 5924 | VkDisplayPlaneProperties2KHR *pProperties, |
| 5925 | VkResult result) { |
| 5926 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5927 | RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties); |
| 5928 | } |
| 5929 | |
| 5930 | void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 5931 | uint32_t query, VkQueryControlFlags flags, uint32_t index) { |
| 5932 | QueryObject query_obj = {queryPool, query, index}; |
| 5933 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5934 | RecordCmdBeginQuery(cb_state, query_obj); |
| 5935 | } |
| 5936 | |
| 5937 | void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 5938 | uint32_t query, uint32_t index) { |
| 5939 | QueryObject query_obj = {queryPool, query, index}; |
| 5940 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5941 | RecordCmdEndQuery(cb_state, query_obj); |
| 5942 | } |
| 5943 | |
| 5944 | void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info, |
| 5945 | VkSamplerYcbcrConversion ycbcr_conversion) { |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5946 | auto ycbcr_state = std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(); |
| 5947 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5948 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5949 | RecordCreateSamplerYcbcrConversionANDROID(create_info, ycbcr_conversion, ycbcr_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5950 | } |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5951 | |
| 5952 | const VkFormat conversion_format = create_info->format; |
| 5953 | |
| 5954 | if (conversion_format != VK_FORMAT_UNDEFINED) { |
| 5955 | // If format is VK_FORMAT_UNDEFINED, will be set by external AHB features |
| 5956 | ycbcr_state->format_features = GetPotentialFormatFeatures(conversion_format); |
| 5957 | } |
| 5958 | |
| 5959 | ycbcr_state->chromaFilter = create_info->chromaFilter; |
| 5960 | ycbcr_state->format = conversion_format; |
| 5961 | samplerYcbcrConversionMap[ycbcr_conversion] = std::move(ycbcr_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device, |
| 5965 | const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, |
| 5966 | const VkAllocationCallbacks *pAllocator, |
| 5967 | VkSamplerYcbcrConversion *pYcbcrConversion, |
| 5968 | VkResult result) { |
| 5969 | if (VK_SUCCESS != result) return; |
| 5970 | RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion); |
| 5971 | } |
| 5972 | |
| 5973 | void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device, |
| 5974 | const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, |
| 5975 | const VkAllocationCallbacks *pAllocator, |
| 5976 | VkSamplerYcbcrConversion *pYcbcrConversion, |
| 5977 | VkResult result) { |
| 5978 | if (VK_SUCCESS != result) return; |
| 5979 | RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion); |
| 5980 | } |
| 5981 | |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5982 | void ValidationStateTracker::RecordDestroySamplerYcbcrConversionState(VkSamplerYcbcrConversion ycbcr_conversion) { |
| 5983 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
| 5984 | RecordDestroySamplerYcbcrConversionANDROID(ycbcr_conversion); |
| 5985 | } |
| 5986 | |
| 5987 | auto ycbcr_state = GetSamplerYcbcrConversionState(ycbcr_conversion); |
| 5988 | ycbcr_state->destroyed = true; |
| 5989 | samplerYcbcrConversionMap.erase(ycbcr_conversion); |
| 5990 | } |
| 5991 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5992 | void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion, |
| 5993 | const VkAllocationCallbacks *pAllocator) { |
| 5994 | if (!ycbcrConversion) return; |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5995 | RecordDestroySamplerYcbcrConversionState(ycbcrConversion); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5996 | } |
| 5997 | |
| 5998 | void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device, |
| 5999 | VkSamplerYcbcrConversion ycbcrConversion, |
| 6000 | const VkAllocationCallbacks *pAllocator) { |
| 6001 | if (!ycbcrConversion) return; |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 6002 | RecordDestroySamplerYcbcrConversionState(ycbcrConversion); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6003 | } |
| 6004 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 6005 | void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 6006 | uint32_t queryCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6007 | // Do nothing if the feature is not enabled. |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 6008 | if (!enabled_features.core12.hostQueryReset) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6009 | |
| 6010 | // Do nothing if the query pool has been destroyed. |
| 6011 | auto query_pool_state = GetQueryPoolState(queryPool); |
| 6012 | if (!query_pool_state) return; |
| 6013 | |
| 6014 | // Reset the state of existing entries. |
| 6015 | QueryObject query_obj{queryPool, 0}; |
| 6016 | const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery); |
| 6017 | for (uint32_t i = 0; i < max_query_count; ++i) { |
| 6018 | query_obj.query = firstQuery + i; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 6019 | queryToStateMap[query_obj] = QUERYSTATE_RESET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 6020 | if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 6021 | for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) { |
| 6022 | query_obj.perf_pass = pass_index; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 6023 | queryToStateMap[query_obj] = QUERYSTATE_RESET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 6024 | } |
| 6025 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6026 | } |
| 6027 | } |
| 6028 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 6029 | void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 6030 | uint32_t queryCount) { |
| 6031 | RecordResetQueryPool(device, queryPool, firstQuery, queryCount); |
| 6032 | } |
| 6033 | |
| 6034 | void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 6035 | uint32_t queryCount) { |
| 6036 | RecordResetQueryPool(device, queryPool, firstQuery, queryCount); |
| 6037 | } |
| 6038 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6039 | void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet, |
| 6040 | const TEMPLATE_STATE *template_state, const void *pData) { |
| 6041 | // Translate the templated update into a normal update for validation... |
| 6042 | cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData); |
| 6043 | cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()), |
| 6044 | decoded_update.desc_writes.data(), 0, NULL); |
| 6045 | } |
| 6046 | |
| 6047 | // Update the common AllocateDescriptorSetsData |
| 6048 | void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 6049 | cvdescriptorset::AllocateDescriptorSetsData *ds_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6050 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 6051 | auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6052 | if (layout) { |
| 6053 | ds_data->layout_nodes[i] = layout; |
| 6054 | // Count total descriptors required per type |
| 6055 | for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) { |
| 6056 | const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 6057 | uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType); |
| 6058 | ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6059 | } |
| 6060 | } |
| 6061 | // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call |
| 6062 | } |
| 6063 | } |
| 6064 | |
| 6065 | // Decrement allocated sets from the pool and insert new sets into set_map |
| 6066 | void ValidationStateTracker::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 6067 | const VkDescriptorSet *descriptor_sets, |
| 6068 | const cvdescriptorset::AllocateDescriptorSetsData *ds_data) { |
| 6069 | auto pool_state = descriptorPoolMap[p_alloc_info->descriptorPool].get(); |
| 6070 | // Account for sets and individual descriptors allocated from pool |
| 6071 | pool_state->availableSets -= p_alloc_info->descriptorSetCount; |
| 6072 | for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) { |
| 6073 | pool_state->availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first); |
| 6074 | } |
| 6075 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 6076 | const auto *variable_count_info = LvlFindInChain<VkDescriptorSetVariableDescriptorCountAllocateInfo>(p_alloc_info->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6077 | bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == p_alloc_info->descriptorSetCount; |
| 6078 | |
| 6079 | // Create tracking object for each descriptor set; insert into global map and the pool's set. |
| 6080 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
| 6081 | uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0; |
| 6082 | |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 6083 | auto new_ds = std::make_shared<cvdescriptorset::DescriptorSet>(descriptor_sets[i], pool_state, ds_data->layout_nodes[i], |
John Zulauf | d2c3dae | 2019-12-12 11:02:17 -0700 | [diff] [blame] | 6084 | variable_count, this); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6085 | pool_state->sets.insert(new_ds.get()); |
| 6086 | new_ds->in_use.store(0); |
| 6087 | setMap[descriptor_sets[i]] = std::move(new_ds); |
| 6088 | } |
| 6089 | } |
| 6090 | |
| 6091 | // Generic function to handle state update for all CmdDraw* and CmdDispatch* type functions |
Jeremy Kniager | 05631e7 | 2020-06-08 14:21:35 -0600 | [diff] [blame] | 6092 | void ValidationStateTracker::UpdateStateCmdDrawDispatchType(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6093 | VkPipelineBindPoint bind_point, const char *function) { |
| 6094 | UpdateDrawState(cb_state, cmd_type, bind_point, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6095 | cb_state->hasDispatchCmd = true; |
| 6096 | } |
| 6097 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6098 | // Generic function to handle state update for all CmdDraw* type functions |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6099 | void ValidationStateTracker::UpdateStateCmdDrawType(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, VkPipelineBindPoint bind_point, |
| 6100 | const char *function) { |
| 6101 | UpdateStateCmdDrawDispatchType(cb_state, cmd_type, bind_point, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6102 | cb_state->hasDrawCmd = true; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 6103 | |
| 6104 | // Update the consumed viewport/scissor count. |
| 6105 | uint32_t& used = cb_state->usedViewportScissorCount; |
| 6106 | used = std::max(used, cb_state->pipelineStaticViewportCount); |
| 6107 | used = std::max(used, cb_state->pipelineStaticScissorCount); |
| 6108 | cb_state->usedDynamicViewportCount |= !!(cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET); // !! silences MSVC warn |
| 6109 | cb_state->usedDynamicScissorCount |= !!(cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6110 | } |
| 6111 | |
| 6112 | void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 6113 | uint32_t firstVertex, uint32_t firstInstance) { |
| 6114 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6115 | UpdateStateCmdDrawType(cb_state, CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, |
| 6119 | uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, |
| 6120 | uint32_t firstInstance) { |
| 6121 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6122 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6123 | } |
| 6124 | |
| 6125 | void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 6126 | uint32_t count, uint32_t stride) { |
| 6127 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6128 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6129 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6130 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 6131 | } |
| 6132 | |
| 6133 | void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6134 | VkDeviceSize offset, uint32_t count, uint32_t stride) { |
| 6135 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6136 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6137 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6138 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 6139 | } |
| 6140 | |
| 6141 | void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) { |
| 6142 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6143 | UpdateStateCmdDrawDispatchType(cb_state, CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6144 | } |
| 6145 | |
| 6146 | void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6147 | VkDeviceSize offset) { |
| 6148 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6149 | UpdateStateCmdDrawDispatchType(cb_state, CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6150 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 6151 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 6152 | } |
| 6153 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 6154 | void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 6155 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6156 | uint32_t stride, const char *function) { |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 6157 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6158 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 6159 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6160 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 6161 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 6162 | AddCommandBufferBindingBuffer(cb_state, count_buffer_state); |
| 6163 | } |
| 6164 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6165 | void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6166 | VkDeviceSize offset, VkBuffer countBuffer, |
| 6167 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 6168 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6169 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 6170 | "vkCmdDrawIndirectCountKHR()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 6171 | } |
| 6172 | |
| 6173 | void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 6174 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 6175 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6176 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 6177 | "vkCmdDrawIndirectCount()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 6181 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6182 | uint32_t maxDrawCount, uint32_t stride, const char *function) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6183 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6184 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 6185 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6186 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXEDINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6187 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 6188 | AddCommandBufferBindingBuffer(cb_state, count_buffer_state); |
| 6189 | } |
| 6190 | |
| 6191 | void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6192 | VkDeviceSize offset, VkBuffer countBuffer, |
| 6193 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 6194 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6195 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 6196 | "vkCmdDrawIndexedIndirectCountKHR()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6200 | VkDeviceSize offset, VkBuffer countBuffer, |
| 6201 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 6202 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6203 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 6204 | "vkCmdDrawIndexedIndirectCount()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, |
| 6208 | uint32_t firstTask) { |
| 6209 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6210 | UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawMeshTasksNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6211 | } |
| 6212 | |
| 6213 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6214 | VkDeviceSize offset, uint32_t drawCount, uint32_t stride) { |
| 6215 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6216 | UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6217 | "vkCmdDrawMeshTasksIndirectNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6218 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 6219 | if (buffer_state) { |
| 6220 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 6221 | } |
| 6222 | } |
| 6223 | |
| 6224 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6225 | VkDeviceSize offset, VkBuffer countBuffer, |
| 6226 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 6227 | uint32_t stride) { |
| 6228 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6229 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 6230 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6231 | UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6232 | "vkCmdDrawMeshTasksIndirectCountNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6233 | if (buffer_state) { |
| 6234 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 6235 | } |
| 6236 | if (count_buffer_state) { |
| 6237 | AddCommandBufferBindingBuffer(cb_state, count_buffer_state); |
| 6238 | } |
| 6239 | } |
| 6240 | |
| 6241 | void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo, |
| 6242 | const VkAllocationCallbacks *pAllocator, |
| 6243 | VkShaderModule *pShaderModule, VkResult result, |
| 6244 | void *csm_state_data) { |
| 6245 | if (VK_SUCCESS != result) return; |
| 6246 | create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data); |
| 6247 | |
Tony-LunarG | 8a51b7d | 2020-07-01 15:57:23 -0600 | [diff] [blame] | 6248 | spv_target_env spirv_environment = PickSpirvEnv(api_version, (device_extensions.vk_khr_spirv_1_4 != kNotEnabled)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6249 | bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 6250 | auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment, |
| 6251 | csm_state->unique_shader_id) |
| 6252 | : std::make_shared<SHADER_MODULE_STATE>(); |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 6253 | new_shader_module->SetPushConstantUsedInShader(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6254 | shaderModuleMap[*pShaderModule] = std::move(new_shader_module); |
| 6255 | } |
| 6256 | |
| 6257 | void ValidationStateTracker::RecordPipelineShaderStage(VkPipelineShaderStageCreateInfo const *pStage, PIPELINE_STATE *pipeline, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 6258 | PIPELINE_STATE::StageState *stage_state) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6259 | // Validation shouldn't rely on anything in stage state being valid if the spirv isn't |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6260 | stage_state->entry_point_name = pStage->pName; |
| 6261 | stage_state->shader_state = GetShared<SHADER_MODULE_STATE>(pStage->module); |
| 6262 | auto module = stage_state->shader_state.get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6263 | if (!module->has_valid_spirv) return; |
| 6264 | |
| 6265 | // Validation shouldn't rely on anything in stage state being valid if the entrypoint isn't present |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 6266 | auto entrypoint = module->FindEntrypoint(pStage->pName, pStage->stage); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6267 | if (entrypoint == module->end()) return; |
| 6268 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 6269 | stage_state->stage_flag = pStage->stage; |
| 6270 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6271 | // Mark accessible ids |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 6272 | stage_state->accessible_ids = module->MarkAccessibleIds(entrypoint); |
| 6273 | module->ProcessExecutionModes(entrypoint, pipeline); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6274 | |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 6275 | stage_state->descriptor_uses = module->CollectInterfaceByDescriptorSlot( |
| 6276 | stage_state->accessible_ids, &stage_state->has_writable_descriptor, &stage_state->has_atomic_descriptor); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6277 | // Capture descriptor uses for the pipeline |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 6278 | for (const auto &use : stage_state->descriptor_uses) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6279 | // While validating shaders capture which slots are used by the pipeline |
John Zulauf | 649edd5 | 2019-10-02 14:39:41 -0600 | [diff] [blame] | 6280 | const uint32_t slot = use.first.first; |
locke-lunarg | 351c9d8 | 2020-10-23 14:43:21 -0600 | [diff] [blame] | 6281 | pipeline->active_slots[slot][use.first.second].is_writable |= use.second.is_writable; |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 6282 | auto &reqs = pipeline->active_slots[slot][use.first.second].reqs; |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 6283 | reqs = descriptor_req(reqs | module->DescriptorTypeToReqs(use.second.type_id)); |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 6284 | if (use.second.is_atomic_operation) reqs = descriptor_req(reqs | DESCRIPTOR_REQ_VIEW_ATOMIC_OPERATION); |
locke-lunarg | 12d2099 | 2020-09-21 12:46:49 -0600 | [diff] [blame] | 6285 | if (use.second.is_sampler_implicitLod_dref_proj) reqs = descriptor_req(reqs | DESCRIPTOR_REQ_SAMPLER_IMPLICITLOD_DREF_PROJ); |
locke-lunarg | ae2a43c | 2020-09-22 17:21:57 -0600 | [diff] [blame] | 6286 | if (use.second.is_sampler_bias_offset) reqs = descriptor_req(reqs | DESCRIPTOR_REQ_SAMPLER_BIAS_OFFSET); |
locke-lunarg | 12d2099 | 2020-09-21 12:46:49 -0600 | [diff] [blame] | 6287 | |
John Zulauf | 649edd5 | 2019-10-02 14:39:41 -0600 | [diff] [blame] | 6288 | pipeline->max_active_slot = std::max(pipeline->max_active_slot, slot); |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 6289 | if (use.second.samplers_used_by_image.size()) { |
locke-lunarg | 654a905 | 2020-10-13 16:28:42 -0600 | [diff] [blame] | 6290 | auto &samplers_used_by_image = pipeline->active_slots[slot][use.first.second].samplers_used_by_image; |
| 6291 | if (use.second.samplers_used_by_image.size() > samplers_used_by_image.size()) { |
| 6292 | samplers_used_by_image.resize(use.second.samplers_used_by_image.size()); |
| 6293 | } |
locke-lunarg | 654a905 | 2020-10-13 16:28:42 -0600 | [diff] [blame] | 6294 | uint32_t image_index = 0; |
| 6295 | for (const auto &samplers : use.second.samplers_used_by_image) { |
| 6296 | for (const auto &sampler : samplers) { |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 6297 | samplers_used_by_image[image_index].emplace(sampler, nullptr); |
locke-lunarg | 654a905 | 2020-10-13 16:28:42 -0600 | [diff] [blame] | 6298 | } |
| 6299 | ++image_index; |
| 6300 | } |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 6301 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6302 | } |
locke-lunarg | 7848683 | 2020-09-09 19:39:42 -0600 | [diff] [blame] | 6303 | |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 6304 | if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 6305 | pipeline->fragmentShader_writable_output_location_list = module->CollectWritableOutputLocationinFS(*pStage); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 6306 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6307 | } |
| 6308 | |
sfricke-samsung | 70ad9ce | 2021-04-04 00:53:54 -0700 | [diff] [blame] | 6309 | // Discussed in details in https://github.com/KhronosGroup/Vulkan-Docs/issues/1081 |
| 6310 | // Internal discussion and CTS were written to prove that this is not called after an incompatible vkCmdBindPipeline |
| 6311 | // "Binding a pipeline with a layout that is not compatible with the push constant layout does not disturb the push constant values" |
| 6312 | // |
| 6313 | // vkCmdBindDescriptorSet has nothing to do with push constants and don't need to call this after neither |
| 6314 | // |
| 6315 | // Part of this assumes apps at draw/dispath/traceRays/etc time will have it properly compatabile or else other VU will be triggered |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6316 | void ValidationStateTracker::ResetCommandBufferPushConstantDataIfIncompatible(CMD_BUFFER_STATE *cb_state, VkPipelineLayout layout) { |
| 6317 | if (cb_state == nullptr) { |
| 6318 | return; |
| 6319 | } |
| 6320 | |
| 6321 | const PIPELINE_LAYOUT_STATE *pipeline_layout_state = GetPipelineLayout(layout); |
| 6322 | if (pipeline_layout_state == nullptr) { |
| 6323 | return; |
| 6324 | } |
| 6325 | |
| 6326 | if (cb_state->push_constant_data_ranges != pipeline_layout_state->push_constant_ranges) { |
| 6327 | cb_state->push_constant_data_ranges = pipeline_layout_state->push_constant_ranges; |
| 6328 | cb_state->push_constant_data.clear(); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6329 | cb_state->push_constant_data_update.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6330 | uint32_t size_needed = 0; |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 6331 | for (const auto &push_constant_range : *cb_state->push_constant_data_ranges) { |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6332 | auto size = push_constant_range.offset + push_constant_range.size; |
| 6333 | size_needed = std::max(size_needed, size); |
| 6334 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 6335 | auto stage_flags = push_constant_range.stageFlags; |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6336 | uint32_t bit_shift = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 6337 | while (stage_flags) { |
| 6338 | if (stage_flags & 1) { |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6339 | VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift); |
| 6340 | const auto it = cb_state->push_constant_data_update.find(flag); |
| 6341 | |
| 6342 | if (it != cb_state->push_constant_data_update.end()) { |
| 6343 | if (it->second.size() < push_constant_range.offset) { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 6344 | it->second.resize(push_constant_range.offset, PC_Byte_Not_Set); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6345 | } |
| 6346 | if (it->second.size() < size) { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 6347 | it->second.resize(size, PC_Byte_Not_Updated); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6348 | } |
| 6349 | } else { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 6350 | std::vector<uint8_t> bytes; |
| 6351 | bytes.resize(push_constant_range.offset, PC_Byte_Not_Set); |
| 6352 | bytes.resize(size, PC_Byte_Not_Updated); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6353 | cb_state->push_constant_data_update[flag] = bytes; |
| 6354 | } |
| 6355 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 6356 | stage_flags = stage_flags >> 1; |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6357 | ++bit_shift; |
| 6358 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6359 | } |
| 6360 | cb_state->push_constant_data.resize(size_needed, 0); |
| 6361 | } |
| 6362 | } |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6363 | |
| 6364 | void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 6365 | uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages, |
| 6366 | VkResult result) { |
| 6367 | if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return; |
| 6368 | auto swapchain_state = GetSwapchainState(swapchain); |
| 6369 | |
| 6370 | if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount); |
| 6371 | |
| 6372 | if (pSwapchainImages) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6373 | for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) { |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 6374 | SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i]; |
John Zulauf | faa7a52 | 2021-03-05 12:22:45 -0700 | [diff] [blame] | 6375 | if (swapchain_image.image_state) continue; // Already retrieved this. |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6376 | |
| 6377 | // Add imageMap entries for each swapchain image |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 6378 | auto image_ci = LvlInitStruct<VkImageCreateInfo>(); |
| 6379 | image_ci.pNext = LvlFindInChain<VkImageFormatListCreateInfo>(swapchain_state->createInfo.pNext); |
Mark Lobodzinski | d3ec86f | 2020-03-18 11:23:04 -0600 | [diff] [blame] | 6380 | image_ci.flags = 0; // to be updated below |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6381 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 6382 | image_ci.format = swapchain_state->createInfo.imageFormat; |
| 6383 | image_ci.extent.width = swapchain_state->createInfo.imageExtent.width; |
| 6384 | image_ci.extent.height = swapchain_state->createInfo.imageExtent.height; |
| 6385 | image_ci.extent.depth = 1; |
| 6386 | image_ci.mipLevels = 1; |
| 6387 | image_ci.arrayLayers = swapchain_state->createInfo.imageArrayLayers; |
| 6388 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 6389 | image_ci.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 6390 | image_ci.usage = swapchain_state->createInfo.imageUsage; |
| 6391 | image_ci.sharingMode = swapchain_state->createInfo.imageSharingMode; |
| 6392 | image_ci.queueFamilyIndexCount = swapchain_state->createInfo.queueFamilyIndexCount; |
| 6393 | image_ci.pQueueFamilyIndices = swapchain_state->createInfo.pQueueFamilyIndices; |
| 6394 | image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 6395 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 6396 | if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6397 | image_ci.flags |= VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 6398 | } |
| 6399 | if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6400 | image_ci.flags |= VK_IMAGE_CREATE_PROTECTED_BIT; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 6401 | } |
| 6402 | if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 6403 | image_ci.flags |= (VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 6404 | } |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6405 | |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 6406 | imageMap[pSwapchainImages[i]] = std::make_shared<IMAGE_STATE>(device, pSwapchainImages[i], &image_ci); |
John Zulauf | faa7a52 | 2021-03-05 12:22:45 -0700 | [diff] [blame] | 6407 | auto *image_state = imageMap[pSwapchainImages[i]].get(); |
| 6408 | assert(image_state); |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6409 | image_state->valid = false; |
| 6410 | image_state->create_from_swapchain = swapchain; |
| 6411 | image_state->bind_swapchain = swapchain; |
| 6412 | image_state->bind_swapchain_imageIndex = i; |
Tony-LunarG | e64e4fe | 2020-02-17 16:21:55 -0700 | [diff] [blame] | 6413 | image_state->is_swapchain_image = true; |
sfricke-samsung | c8a5085 | 2021-03-31 13:56:50 -0700 | [diff] [blame] | 6414 | image_state->unprotected = ((image_ci.flags & VK_IMAGE_CREATE_PROTECTED_BIT) == 0); |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 6415 | |
| 6416 | // Since swapchains can't be linear, we can create an encoder here, and SyncValNeeds a fake_base_address |
| 6417 | image_state->fragment_encoder = std::unique_ptr<const subresource_adapter::ImageRangeEncoder>( |
| 6418 | new subresource_adapter::ImageRangeEncoder(*image_state)); |
| 6419 | |
| 6420 | if (swapchain_image.bound_images.empty()) { |
| 6421 | // First time "bind" allocates |
| 6422 | image_state->swapchain_fake_address = fake_memory.Alloc(image_state->fragment_encoder->TotalSize()); |
| 6423 | } else { |
| 6424 | // All others reuse |
| 6425 | image_state->swapchain_fake_address = (*swapchain_image.bound_images.cbegin())->swapchain_fake_address; |
| 6426 | // Since there are others, need to update the aliasing information |
John Zulauf | faa7a52 | 2021-03-05 12:22:45 -0700 | [diff] [blame] | 6427 | AddAliasingImage(image_state, &swapchain_image.bound_images); |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | swapchain_image.image_state = image_state; // Don't move, it's already a reference to the imageMap |
John Zulauf | faa7a52 | 2021-03-05 12:22:45 -0700 | [diff] [blame] | 6431 | swapchain_image.bound_images.emplace(image_state); |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 6432 | |
| 6433 | AddImageStateProps(*image_state, device, physical_device); |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6434 | } |
| 6435 | } |
| 6436 | |
| 6437 | if (*pSwapchainImageCount) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6438 | swapchain_state->get_swapchain_image_count = *pSwapchainImageCount; |
| 6439 | } |
| 6440 | } |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 6441 | |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 6442 | void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer, |
| 6443 | const VkCopyAccelerationStructureInfoKHR *pInfo) { |
| 6444 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6445 | if (cb_state) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 6446 | ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfo->src); |
| 6447 | ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfo->dst); |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 6448 | if (dst_as_state != nullptr && src_as_state != nullptr) { |
| 6449 | dst_as_state->built = true; |
| 6450 | dst_as_state->build_info_khr = src_as_state->build_info_khr; |
| 6451 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 6452 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 6453 | } |
| 6454 | } |
| 6455 | } |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 6456 | |
| 6457 | void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) { |
| 6458 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6459 | cb_state->status |= CBSTATUS_CULL_MODE_SET; |
| 6460 | cb_state->static_status &= ~CBSTATUS_CULL_MODE_SET; |
| 6461 | } |
| 6462 | |
| 6463 | void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) { |
| 6464 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6465 | cb_state->status |= CBSTATUS_FRONT_FACE_SET; |
| 6466 | cb_state->static_status &= ~CBSTATUS_FRONT_FACE_SET; |
| 6467 | } |
| 6468 | |
| 6469 | void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer, |
| 6470 | VkPrimitiveTopology primitiveTopology) { |
| 6471 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6472 | cb_state->primitiveTopology = primitiveTopology; |
| 6473 | cb_state->status |= CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 6474 | cb_state->static_status &= ~CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 6475 | } |
| 6476 | |
| 6477 | void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount, |
| 6478 | const VkViewport *pViewports) { |
| 6479 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 6480 | uint32_t bits = (1u << viewportCount) - 1u; |
| 6481 | cb_state->viewportWithCountMask |= bits; |
| 6482 | cb_state->trashedViewportMask &= ~bits; |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 6483 | cb_state->viewportWithCountCount = viewportCount; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 6484 | cb_state->trashedViewportCount = false; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 6485 | cb_state->status |= CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
| 6486 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 6487 | |
| 6488 | cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size())); |
| 6489 | for (size_t i = 0; i < viewportCount; ++i) { |
| 6490 | cb_state->dynamicViewports[i] = pViewports[i]; |
| 6491 | } |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 6492 | } |
| 6493 | |
| 6494 | void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount, |
| 6495 | const VkRect2D *pScissors) { |
| 6496 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 6497 | uint32_t bits = (1u << scissorCount) - 1u; |
| 6498 | cb_state->scissorWithCountMask |= bits; |
| 6499 | cb_state->trashedScissorMask &= ~bits; |
| 6500 | cb_state->scissorWithCountCount = scissorCount; |
| 6501 | cb_state->trashedScissorCount = false; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 6502 | cb_state->status |= CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 6503 | cb_state->static_status &= ~CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 6504 | } |
| 6505 | |
| 6506 | void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding, |
| 6507 | uint32_t bindingCount, const VkBuffer *pBuffers, |
| 6508 | const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes, |
| 6509 | const VkDeviceSize *pStrides) { |
| 6510 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6511 | if (pStrides) { |
| 6512 | cb_state->status |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 6513 | cb_state->static_status &= ~CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 6514 | } |
| 6515 | |
| 6516 | uint32_t end = firstBinding + bindingCount; |
| 6517 | if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) { |
| 6518 | cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end); |
| 6519 | } |
| 6520 | |
| 6521 | for (uint32_t i = 0; i < bindingCount; ++i) { |
| 6522 | auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 6523 | vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]); |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 6524 | vertex_buffer_binding.offset = pOffsets[i]; |
| 6525 | vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE; |
| 6526 | vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0; |
| 6527 | // Add binding for this vertex buffer to this commandbuffer |
| 6528 | if (pBuffers[i]) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 6529 | AddCommandBufferBindingBuffer(cb_state, vertex_buffer_binding.buffer_state.get()); |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 6530 | } |
| 6531 | } |
| 6532 | } |
| 6533 | |
| 6534 | void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) { |
| 6535 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6536 | cb_state->status |= CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 6537 | cb_state->static_status &= ~CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 6538 | } |
| 6539 | |
| 6540 | void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) { |
| 6541 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6542 | cb_state->status |= CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 6543 | cb_state->static_status &= ~CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 6544 | } |
| 6545 | |
| 6546 | void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) { |
| 6547 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6548 | cb_state->status |= CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 6549 | cb_state->static_status &= ~CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 6550 | } |
| 6551 | |
| 6552 | void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer, |
| 6553 | VkBool32 depthBoundsTestEnable) { |
| 6554 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6555 | cb_state->status |= CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 6556 | cb_state->static_status &= ~CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 6557 | } |
| 6558 | void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) { |
| 6559 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6560 | cb_state->status |= CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 6561 | cb_state->static_status &= ~CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 6562 | } |
| 6563 | |
| 6564 | void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 6565 | VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp, |
| 6566 | VkCompareOp compareOp) { |
| 6567 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6568 | cb_state->status |= CBSTATUS_STENCIL_OP_SET; |
| 6569 | cb_state->static_status &= ~CBSTATUS_STENCIL_OP_SET; |
| 6570 | } |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 6571 | |
| 6572 | void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle, |
| 6573 | uint32_t discardRectangleCount, |
| 6574 | const VkRect2D *pDiscardRectangles) { |
| 6575 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6576 | cb_state->status |= CBSTATUS_DISCARD_RECTANGLE_SET; |
| 6577 | cb_state->static_status &= ~CBSTATUS_DISCARD_RECTANGLE_SET; |
| 6578 | } |
| 6579 | |
| 6580 | void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer, |
| 6581 | const VkSampleLocationsInfoEXT *pSampleLocationsInfo) { |
| 6582 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6583 | cb_state->status |= CBSTATUS_SAMPLE_LOCATIONS_SET; |
| 6584 | cb_state->static_status &= ~CBSTATUS_SAMPLE_LOCATIONS_SET; |
| 6585 | } |
| 6586 | |
| 6587 | void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer, |
| 6588 | VkCoarseSampleOrderTypeNV sampleOrderType, |
| 6589 | uint32_t customSampleOrderCount, |
| 6590 | const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) { |
| 6591 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6592 | cb_state->status |= CBSTATUS_COARSE_SAMPLE_ORDER_SET; |
| 6593 | cb_state->static_status &= ~CBSTATUS_COARSE_SAMPLE_ORDER_SET; |
| 6594 | } |
Vikram Kushwaha | a57b0c3 | 2021-04-19 12:21:46 -0700 | [diff] [blame] | 6595 | |
| 6596 | void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) { |
| 6597 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6598 | cb_state->status |= CBSTATUS_PATCH_CONTROL_POINTS_SET; |
| 6599 | cb_state->static_status &= ~CBSTATUS_PATCH_CONTROL_POINTS_SET; |
| 6600 | } |
| 6601 | |
| 6602 | void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) { |
| 6603 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6604 | cb_state->status |= CBSTATUS_LOGIC_OP_SET; |
| 6605 | cb_state->static_status &= ~CBSTATUS_LOGIC_OP_SET; |
| 6606 | } |
| 6607 | |
| 6608 | void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer, |
| 6609 | VkBool32 rasterizerDiscardEnable) { |
| 6610 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6611 | cb_state->status |= CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET; |
| 6612 | cb_state->static_status &= ~CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET; |
| 6613 | } |
| 6614 | |
| 6615 | void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) { |
| 6616 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6617 | cb_state->status |= CBSTATUS_DEPTH_BIAS_ENABLE_SET; |
| 6618 | cb_state->static_status &= ~CBSTATUS_DEPTH_BIAS_ENABLE_SET; |
| 6619 | } |
| 6620 | |
| 6621 | void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer, |
| 6622 | VkBool32 primitiveRestartEnable) { |
| 6623 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6624 | cb_state->status |= CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET; |
| 6625 | cb_state->static_status &= ~CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 6626 | } |