Tony-LunarG | 7371999 | 2020-01-15 10:20:28 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2020 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2020 Valve Corporation |
| 3 | * Copyright (c) 2015-2020 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2020 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 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 25 | #include <cmath> |
| 26 | #include <set> |
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" |
| 38 | |
John Zulauf | 890b50b | 2020-06-17 15:18:19 -0600 | [diff] [blame] | 39 | const char *CommandTypeString(CMD_TYPE type) { |
| 40 | // Autogenerated as part of the vk_validation_error_message.h codegen |
Mark Lobodzinski | 677dc0b | 2020-11-12 15:28:09 -0700 | [diff] [blame] | 41 | return kGeneratedCommandNameList[type]; |
John Zulauf | 890b50b | 2020-06-17 15:18:19 -0600 | [diff] [blame] | 42 | } |
| 43 | |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 44 | VkDynamicState ConvertToDynamicState(CBStatusFlagBits flag) { |
| 45 | switch (flag) { |
| 46 | case CBSTATUS_LINE_WIDTH_SET: |
| 47 | return VK_DYNAMIC_STATE_LINE_WIDTH; |
| 48 | case CBSTATUS_DEPTH_BIAS_SET: |
| 49 | return VK_DYNAMIC_STATE_DEPTH_BIAS; |
| 50 | case CBSTATUS_BLEND_CONSTANTS_SET: |
| 51 | return VK_DYNAMIC_STATE_BLEND_CONSTANTS; |
| 52 | case CBSTATUS_DEPTH_BOUNDS_SET: |
| 53 | return VK_DYNAMIC_STATE_DEPTH_BOUNDS; |
| 54 | case CBSTATUS_STENCIL_READ_MASK_SET: |
| 55 | return VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK; |
| 56 | case CBSTATUS_STENCIL_WRITE_MASK_SET: |
| 57 | return VK_DYNAMIC_STATE_STENCIL_WRITE_MASK; |
| 58 | case CBSTATUS_STENCIL_REFERENCE_SET: |
| 59 | return VK_DYNAMIC_STATE_STENCIL_REFERENCE; |
| 60 | case CBSTATUS_VIEWPORT_SET: |
| 61 | return VK_DYNAMIC_STATE_VIEWPORT; |
| 62 | case CBSTATUS_SCISSOR_SET: |
| 63 | return VK_DYNAMIC_STATE_SCISSOR; |
| 64 | case CBSTATUS_EXCLUSIVE_SCISSOR_SET: |
| 65 | return VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV; |
| 66 | case CBSTATUS_SHADING_RATE_PALETTE_SET: |
| 67 | return VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV; |
| 68 | case CBSTATUS_LINE_STIPPLE_SET: |
| 69 | return VK_DYNAMIC_STATE_LINE_STIPPLE_EXT; |
| 70 | case CBSTATUS_VIEWPORT_W_SCALING_SET: |
| 71 | return VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV; |
| 72 | case CBSTATUS_CULL_MODE_SET: |
| 73 | return VK_DYNAMIC_STATE_CULL_MODE_EXT; |
| 74 | case CBSTATUS_FRONT_FACE_SET: |
| 75 | return VK_DYNAMIC_STATE_FRONT_FACE_EXT; |
| 76 | case CBSTATUS_PRIMITIVE_TOPOLOGY_SET: |
| 77 | return VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT; |
| 78 | case CBSTATUS_VIEWPORT_WITH_COUNT_SET: |
| 79 | return VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT; |
| 80 | case CBSTATUS_SCISSOR_WITH_COUNT_SET: |
| 81 | return VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT; |
| 82 | case CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET: |
| 83 | return VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT; |
| 84 | case CBSTATUS_DEPTH_TEST_ENABLE_SET: |
| 85 | return VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT; |
| 86 | case CBSTATUS_DEPTH_WRITE_ENABLE_SET: |
| 87 | return VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT; |
| 88 | case CBSTATUS_DEPTH_COMPARE_OP_SET: |
| 89 | return VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT; |
| 90 | case CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET: |
| 91 | return VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT; |
| 92 | case CBSTATUS_STENCIL_TEST_ENABLE_SET: |
| 93 | return VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT; |
| 94 | case CBSTATUS_STENCIL_OP_SET: |
| 95 | return VK_DYNAMIC_STATE_STENCIL_OP_EXT; |
| 96 | case CBSTATUS_DISCARD_RECTANGLE_SET: |
| 97 | return VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT; |
| 98 | case CBSTATUS_SAMPLE_LOCATIONS_SET: |
| 99 | return VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT; |
| 100 | case CBSTATUS_COARSE_SAMPLE_ORDER_SET: |
| 101 | return VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV; |
| 102 | default: |
| 103 | // CBSTATUS_INDEX_BUFFER_BOUND is not in VkDynamicState |
| 104 | return VK_DYNAMIC_STATE_MAX_ENUM; |
| 105 | } |
| 106 | return VK_DYNAMIC_STATE_MAX_ENUM; |
| 107 | } |
| 108 | |
| 109 | CBStatusFlagBits ConvertToCBStatusFlagBits(VkDynamicState state) { |
| 110 | switch (state) { |
| 111 | case VK_DYNAMIC_STATE_VIEWPORT: |
| 112 | return CBSTATUS_VIEWPORT_SET; |
| 113 | case VK_DYNAMIC_STATE_SCISSOR: |
| 114 | return CBSTATUS_SCISSOR_SET; |
| 115 | case VK_DYNAMIC_STATE_LINE_WIDTH: |
| 116 | return CBSTATUS_LINE_WIDTH_SET; |
| 117 | case VK_DYNAMIC_STATE_DEPTH_BIAS: |
| 118 | return CBSTATUS_DEPTH_BIAS_SET; |
| 119 | case VK_DYNAMIC_STATE_BLEND_CONSTANTS: |
| 120 | return CBSTATUS_BLEND_CONSTANTS_SET; |
| 121 | case VK_DYNAMIC_STATE_DEPTH_BOUNDS: |
| 122 | return CBSTATUS_DEPTH_BOUNDS_SET; |
| 123 | case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK: |
| 124 | return CBSTATUS_STENCIL_READ_MASK_SET; |
| 125 | case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK: |
| 126 | return CBSTATUS_STENCIL_WRITE_MASK_SET; |
| 127 | case VK_DYNAMIC_STATE_STENCIL_REFERENCE: |
| 128 | return CBSTATUS_STENCIL_REFERENCE_SET; |
| 129 | case VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV: |
| 130 | return CBSTATUS_VIEWPORT_W_SCALING_SET; |
| 131 | case VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT: |
| 132 | return CBSTATUS_DISCARD_RECTANGLE_SET; |
| 133 | case VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT: |
| 134 | return CBSTATUS_SAMPLE_LOCATIONS_SET; |
| 135 | case VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV: |
| 136 | return CBSTATUS_SHADING_RATE_PALETTE_SET; |
| 137 | case VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV: |
| 138 | return CBSTATUS_COARSE_SAMPLE_ORDER_SET; |
| 139 | case VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV: |
| 140 | return CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
| 141 | case VK_DYNAMIC_STATE_LINE_STIPPLE_EXT: |
| 142 | return CBSTATUS_LINE_STIPPLE_SET; |
| 143 | case VK_DYNAMIC_STATE_CULL_MODE_EXT: |
| 144 | return CBSTATUS_CULL_MODE_SET; |
| 145 | case VK_DYNAMIC_STATE_FRONT_FACE_EXT: |
| 146 | return CBSTATUS_FRONT_FACE_SET; |
| 147 | case VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT: |
| 148 | return CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 149 | case VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT: |
| 150 | return CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
| 151 | case VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT: |
| 152 | return CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 153 | case VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT: |
| 154 | return CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 155 | case VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT: |
| 156 | return CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 157 | case VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT: |
| 158 | return CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 159 | case VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT: |
| 160 | return CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 161 | case VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT: |
| 162 | return CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 163 | case VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT: |
| 164 | return CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 165 | case VK_DYNAMIC_STATE_STENCIL_OP_EXT: |
| 166 | return CBSTATUS_STENCIL_OP_SET; |
| 167 | default: |
| 168 | return CBSTATUS_NONE; |
| 169 | } |
| 170 | return CBSTATUS_NONE; |
| 171 | } |
| 172 | |
Mark Lobodzinski | b4ab6ac | 2020-04-02 13:12:06 -0600 | [diff] [blame] | 173 | void ValidationStateTracker::InitDeviceValidationObject(bool add_obj, ValidationObject *inst_obj, ValidationObject *dev_obj) { |
| 174 | if (add_obj) { |
| 175 | instance_state = reinterpret_cast<ValidationStateTracker *>(GetValidationObject(inst_obj->object_dispatch, container_type)); |
| 176 | // Call base class |
| 177 | ValidationObject::InitDeviceValidationObject(add_obj, inst_obj, dev_obj); |
| 178 | } |
| 179 | } |
| 180 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 181 | uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) { |
| 182 | // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS |
| 183 | uint32_t mip_level_count = range->levelCount; |
| 184 | if (range->levelCount == VK_REMAINING_MIP_LEVELS) { |
| 185 | mip_level_count = mip_levels - range->baseMipLevel; |
| 186 | } |
| 187 | return mip_level_count; |
| 188 | } |
| 189 | |
| 190 | uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) { |
| 191 | // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS |
| 192 | uint32_t array_layer_count = range->layerCount; |
| 193 | if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 194 | array_layer_count = layers - range->baseArrayLayer; |
| 195 | } |
| 196 | return array_layer_count; |
| 197 | } |
| 198 | |
| 199 | VkImageSubresourceRange NormalizeSubresourceRange(const VkImageCreateInfo &image_create_info, |
| 200 | const VkImageSubresourceRange &range) { |
| 201 | VkImageSubresourceRange norm = range; |
| 202 | norm.levelCount = ResolveRemainingLevels(&range, image_create_info.mipLevels); |
| 203 | |
| 204 | // Special case for 3D images with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR flag bit, where <extent.depth> and |
| 205 | // <arrayLayers> can potentially alias. |
| 206 | uint32_t layer_limit = (0 != (image_create_info.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) |
| 207 | ? image_create_info.extent.depth |
| 208 | : image_create_info.arrayLayers; |
| 209 | norm.layerCount = ResolveRemainingLayers(&range, layer_limit); |
| 210 | |
| 211 | // For multiplanar formats, IMAGE_ASPECT_COLOR is equivalent to adding the aspect of the individual planes |
| 212 | VkImageAspectFlags &aspect_mask = norm.aspectMask; |
| 213 | if (FormatIsMultiplane(image_create_info.format)) { |
| 214 | if (aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 215 | aspect_mask &= ~VK_IMAGE_ASPECT_COLOR_BIT; |
| 216 | aspect_mask |= (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT); |
| 217 | if (FormatPlaneCount(image_create_info.format) > 2) { |
| 218 | aspect_mask |= VK_IMAGE_ASPECT_PLANE_2_BIT; |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | return norm; |
| 223 | } |
| 224 | |
| 225 | VkImageSubresourceRange NormalizeSubresourceRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &range) { |
| 226 | const VkImageCreateInfo &image_create_info = image_state.createInfo; |
| 227 | return NormalizeSubresourceRange(image_create_info, range); |
| 228 | } |
| 229 | |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 230 | // NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS" |
| 231 | // attachments won't persist past the API entry point exit. |
| 232 | std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin, |
| 233 | const FRAMEBUFFER_STATE &fb_state) { |
| 234 | const VkImageView *attachments = fb_state.createInfo.pAttachments; |
| 235 | uint32_t count = fb_state.createInfo.attachmentCount; |
| 236 | if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
| 237 | const auto *framebuffer_attachments = lvl_find_in_chain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext); |
| 238 | if (framebuffer_attachments) { |
| 239 | attachments = framebuffer_attachments->pAttachments; |
| 240 | count = framebuffer_attachments->attachmentCount; |
| 241 | } |
| 242 | } |
| 243 | return std::make_pair(count, attachments); |
| 244 | } |
| 245 | |
| 246 | std::vector<const IMAGE_VIEW_STATE *> ValidationStateTracker::GetAttachmentViews(const VkRenderPassBeginInfo &rp_begin, |
| 247 | const FRAMEBUFFER_STATE &fb_state) const { |
| 248 | std::vector<const IMAGE_VIEW_STATE *> views; |
| 249 | |
| 250 | const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state); |
| 251 | const auto attachment_count = count_attachment.first; |
| 252 | const auto *attachments = count_attachment.second; |
| 253 | views.resize(attachment_count, nullptr); |
| 254 | for (uint32_t i = 0; i < attachment_count; i++) { |
| 255 | if (attachments[i] != VK_NULL_HANDLE) { |
| 256 | views[i] = Get<IMAGE_VIEW_STATE>(attachments[i]); |
| 257 | } |
| 258 | } |
| 259 | return views; |
| 260 | } |
| 261 | |
| 262 | std::vector<const IMAGE_VIEW_STATE *> ValidationStateTracker::GetCurrentAttachmentViews(const CMD_BUFFER_STATE &cb_state) const { |
| 263 | // Only valid *after* RecordBeginRenderPass and *before* RecordEndRenderpass as it relies on cb_state for the renderpass info. |
| 264 | std::vector<const IMAGE_VIEW_STATE *> views; |
| 265 | |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 266 | const auto *rp_state = cb_state.activeRenderPass.get(); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 267 | if (!rp_state) return views; |
| 268 | const auto &rp_begin = *cb_state.activeRenderPassBeginInfo.ptr(); |
| 269 | const auto *fb_state = Get<FRAMEBUFFER_STATE>(rp_begin.framebuffer); |
| 270 | if (!fb_state) return views; |
| 271 | |
| 272 | return GetAttachmentViews(rp_begin, *fb_state); |
| 273 | } |
| 274 | |
locke-lunarg | 3e127c7 | 2020-06-09 17:45:28 -0600 | [diff] [blame] | 275 | PIPELINE_STATE *GetCurrentPipelineFromCommandBuffer(const CMD_BUFFER_STATE &cmd, VkPipelineBindPoint pipelineBindPoint) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 276 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 277 | return cmd.lastBound[lv_bind_point].pipeline_state; |
locke-lunarg | 3e127c7 | 2020-06-09 17:45:28 -0600 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(const CMD_BUFFER_STATE &cmd, VkPipelineBindPoint pipelineBindPoint, |
| 281 | const PIPELINE_STATE **rtn_pipe, |
| 282 | const std::vector<LAST_BOUND_STATE::PER_SET> **rtn_sets) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 283 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 284 | const auto &last_bound_it = cmd.lastBound[lv_bind_point]; |
| 285 | if (!last_bound_it.IsUsing()) { |
locke-lunarg | 3e127c7 | 2020-06-09 17:45:28 -0600 | [diff] [blame] | 286 | return; |
| 287 | } |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 288 | *rtn_pipe = last_bound_it.pipeline_state; |
| 289 | *rtn_sets = &(last_bound_it.per_set); |
locke-lunarg | 3e127c7 | 2020-06-09 17:45:28 -0600 | [diff] [blame] | 290 | } |
| 291 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 292 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 293 | // Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR |
| 294 | // This could also move into a seperate core_validation_android.cpp file... ? |
| 295 | |
| 296 | void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) { |
| 297 | const VkExternalMemoryImageCreateInfo *emici = lvl_find_in_chain<VkExternalMemoryImageCreateInfo>(create_info->pNext); |
| 298 | 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] | 299 | is_node->external_ahb = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 300 | } |
| 301 | const VkExternalFormatANDROID *ext_fmt_android = lvl_find_in_chain<VkExternalFormatANDROID>(create_info->pNext); |
| 302 | if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) { |
| 303 | is_node->has_ahb_format = true; |
| 304 | is_node->ahb_format = ext_fmt_android->externalFormat; |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 305 | // VUID 01894 will catch if not found in map |
| 306 | auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat); |
| 307 | if (it != ahb_ext_formats_map.end()) { |
| 308 | is_node->format_features = it->second; |
| 309 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 313 | void ValidationStateTracker::RecordCreateBufferANDROID(const VkBufferCreateInfo *create_info, BUFFER_STATE *bs_node) { |
| 314 | const VkExternalMemoryBufferCreateInfo *embci = lvl_find_in_chain<VkExternalMemoryBufferCreateInfo>(create_info->pNext); |
| 315 | if (embci && (embci->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) { |
| 316 | bs_node->external_ahb = true; |
| 317 | } |
| 318 | } |
| 319 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 320 | void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info, |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 321 | VkSamplerYcbcrConversion ycbcr_conversion, |
| 322 | SAMPLER_YCBCR_CONVERSION_STATE *ycbcr_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 323 | const VkExternalFormatANDROID *ext_format_android = lvl_find_in_chain<VkExternalFormatANDROID>(create_info->pNext); |
| 324 | if (ext_format_android && (0 != ext_format_android->externalFormat)) { |
| 325 | ycbcr_conversion_ahb_fmt_map.emplace(ycbcr_conversion, ext_format_android->externalFormat); |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 326 | // VUID 01894 will catch if not found in map |
| 327 | auto it = ahb_ext_formats_map.find(ext_format_android->externalFormat); |
| 328 | if (it != ahb_ext_formats_map.end()) { |
| 329 | ycbcr_state->format_features = it->second; |
| 330 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 331 | } |
| 332 | }; |
| 333 | |
| 334 | void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion) { |
| 335 | ycbcr_conversion_ahb_fmt_map.erase(ycbcr_conversion); |
| 336 | }; |
| 337 | |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 338 | void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID( |
| 339 | VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) { |
| 340 | if (VK_SUCCESS != result) return; |
| 341 | auto ahb_format_props = lvl_find_in_chain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext); |
| 342 | if (ahb_format_props) { |
| 343 | ahb_ext_formats_map.insert({ahb_format_props->externalFormat, ahb_format_props->formatFeatures}); |
| 344 | } |
| 345 | } |
| 346 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 347 | #else |
| 348 | |
| 349 | void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) {} |
| 350 | |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 351 | void ValidationStateTracker::RecordCreateBufferANDROID(const VkBufferCreateInfo *create_info, BUFFER_STATE *bs_node) {} |
| 352 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 353 | void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info, |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 354 | VkSamplerYcbcrConversion ycbcr_conversion, |
| 355 | SAMPLER_YCBCR_CONVERSION_STATE *ycbcr_state){}; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 356 | |
| 357 | void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion){}; |
| 358 | |
| 359 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 360 | |
Mark Lobodzinski | d3ec86f | 2020-03-18 11:23:04 -0600 | [diff] [blame] | 361 | std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> GetDslFromPipelineLayout(PIPELINE_LAYOUT_STATE const *layout_data, |
| 362 | uint32_t set) { |
| 363 | std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> dsl = nullptr; |
| 364 | if (layout_data && (set < layout_data->set_layouts.size())) { |
| 365 | dsl = layout_data->set_layouts[set]; |
| 366 | } |
| 367 | return dsl; |
| 368 | } |
| 369 | |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 370 | void AddImageStateProps(IMAGE_STATE &image_state, const VkDevice device, const VkPhysicalDevice physical_device) { |
| 371 | // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features) |
| 372 | // if format is AHB external format then the features are already set |
| 373 | if (image_state.has_ahb_format == false) { |
| 374 | const VkImageTiling image_tiling = image_state.createInfo.tiling; |
| 375 | const VkFormat image_format = image_state.createInfo.format; |
| 376 | if (image_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { |
| 377 | VkImageDrmFormatModifierPropertiesEXT drm_format_properties = { |
| 378 | VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, nullptr}; |
| 379 | DispatchGetImageDrmFormatModifierPropertiesEXT(device, image_state.image, &drm_format_properties); |
| 380 | |
| 381 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr}; |
| 382 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 383 | nullptr}; |
| 384 | format_properties_2.pNext = (void *)&drm_properties_list; |
| 385 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties_2); |
Lionel Landwerlin | 09351a7 | 2020-06-22 18:15:59 +0300 | [diff] [blame] | 386 | std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties; |
| 387 | drm_properties.resize(drm_properties_list.drmFormatModifierCount); |
| 388 | drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0]; |
| 389 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties_2); |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 390 | |
| 391 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 392 | if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == |
| 393 | drm_format_properties.drmFormatModifier) { |
| 394 | image_state.format_features = |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 395 | drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 396 | break; |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | } else { |
| 400 | VkFormatProperties format_properties; |
| 401 | DispatchGetPhysicalDeviceFormatProperties(physical_device, image_format, &format_properties); |
| 402 | image_state.format_features = (image_tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures |
| 403 | : format_properties.optimalTilingFeatures; |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 408 | void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, |
| 409 | const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) { |
| 410 | if (VK_SUCCESS != result) return; |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 411 | auto is_node = std::make_shared<IMAGE_STATE>(device, *pImage, pCreateInfo); |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 412 | is_node->disjoint = ((pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT) != 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 413 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
| 414 | RecordCreateImageANDROID(pCreateInfo, is_node.get()); |
| 415 | } |
| 416 | const auto swapchain_info = lvl_find_in_chain<VkImageSwapchainCreateInfoKHR>(pCreateInfo->pNext); |
| 417 | if (swapchain_info) { |
| 418 | is_node->create_from_swapchain = swapchain_info->swapchain; |
| 419 | } |
| 420 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 421 | // Record the memory requirements in case they won't be queried |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 422 | // External AHB memory can't be queried until after memory is bound |
Spencer Fricke | 224c985 | 2020-04-06 07:47:29 -0700 | [diff] [blame] | 423 | if (is_node->external_ahb == false) { |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 424 | if (is_node->disjoint == false) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 425 | DispatchGetImageMemoryRequirements(device, *pImage, &is_node->requirements); |
| 426 | } else { |
| 427 | uint32_t plane_count = FormatPlaneCount(pCreateInfo->format); |
| 428 | VkImagePlaneMemoryRequirementsInfo image_plane_req = {VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO, nullptr}; |
| 429 | VkMemoryRequirements2 mem_reqs2 = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, nullptr}; |
| 430 | VkImageMemoryRequirementsInfo2 mem_req_info2 = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2}; |
| 431 | mem_req_info2.pNext = &image_plane_req; |
| 432 | mem_req_info2.image = *pImage; |
| 433 | |
| 434 | assert(plane_count != 0); // assumes each format has at least first plane |
| 435 | image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_0_BIT; |
| 436 | DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2); |
| 437 | is_node->plane0_requirements = mem_reqs2.memoryRequirements; |
| 438 | |
| 439 | if (plane_count >= 2) { |
| 440 | image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_1_BIT; |
| 441 | DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2); |
| 442 | is_node->plane1_requirements = mem_reqs2.memoryRequirements; |
| 443 | } |
| 444 | if (plane_count >= 3) { |
| 445 | image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_2_BIT; |
| 446 | DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2); |
| 447 | is_node->plane2_requirements = mem_reqs2.memoryRequirements; |
| 448 | } |
| 449 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 450 | } |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 451 | |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 452 | AddImageStateProps(*is_node, device, physical_device); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 453 | |
sfricke-samsung | edce77a | 2020-07-03 22:35:13 -0700 | [diff] [blame] | 454 | is_node->unprotected = ((pCreateInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT) == 0); |
| 455 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 456 | imageMap.insert(std::make_pair(*pImage, std::move(is_node))); |
| 457 | } |
| 458 | |
| 459 | void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) { |
| 460 | if (!image) return; |
| 461 | IMAGE_STATE *image_state = GetImageState(image); |
| 462 | const VulkanTypedHandle obj_struct(image, kVulkanObjectTypeImage); |
| 463 | InvalidateCommandBuffers(image_state->cb_bindings, obj_struct); |
| 464 | // Clean up memory mapping, bindings and range references for image |
| 465 | for (auto mem_binding : image_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 466 | RemoveImageMemoryRange(image, mem_binding); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 467 | } |
| 468 | if (image_state->bind_swapchain) { |
| 469 | auto swapchain = GetSwapchainState(image_state->bind_swapchain); |
| 470 | if (swapchain) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 471 | swapchain->images[image_state->bind_swapchain_imageIndex].bound_images.erase(image_state->image); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | RemoveAliasingImage(image_state); |
| 475 | ClearMemoryObjectBindings(obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 476 | image_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 477 | // Remove image from imageMap |
| 478 | imageMap.erase(image); |
| 479 | } |
| 480 | |
| 481 | void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, |
| 482 | VkImageLayout imageLayout, const VkClearColorValue *pColor, |
| 483 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 484 | auto cb_node = GetCBState(commandBuffer); |
| 485 | auto image_state = GetImageState(image); |
| 486 | if (cb_node && image_state) { |
| 487 | AddCommandBufferBindingImage(cb_node, image_state); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 492 | VkImageLayout imageLayout, |
| 493 | const VkClearDepthStencilValue *pDepthStencil, |
| 494 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 495 | auto cb_node = GetCBState(commandBuffer); |
| 496 | auto image_state = GetImageState(image); |
| 497 | if (cb_node && image_state) { |
| 498 | AddCommandBufferBindingImage(cb_node, image_state); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 503 | VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 504 | uint32_t regionCount, const VkImageCopy *pRegions) { |
| 505 | auto cb_node = GetCBState(commandBuffer); |
| 506 | auto src_image_state = GetImageState(srcImage); |
| 507 | auto dst_image_state = GetImageState(dstImage); |
| 508 | |
| 509 | // Update bindings between images and cmd buffer |
| 510 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 511 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 512 | } |
| 513 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 514 | void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 515 | const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 516 | auto cb_node = GetCBState(commandBuffer); |
| 517 | auto src_image_state = GetImageState(pCopyImageInfo->srcImage); |
| 518 | auto dst_image_state = GetImageState(pCopyImageInfo->dstImage); |
| 519 | |
| 520 | // Update bindings between images and cmd buffer |
| 521 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 522 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 523 | } |
| 524 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 525 | void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 526 | VkImageLayout srcImageLayout, VkImage dstImage, |
| 527 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 528 | const VkImageResolve *pRegions) { |
| 529 | auto cb_node = GetCBState(commandBuffer); |
| 530 | auto src_image_state = GetImageState(srcImage); |
| 531 | auto dst_image_state = GetImageState(dstImage); |
| 532 | |
| 533 | // Update bindings between images and cmd buffer |
| 534 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 535 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 536 | } |
| 537 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 538 | void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 539 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 540 | auto cb_node = GetCBState(commandBuffer); |
| 541 | auto src_image_state = GetImageState(pResolveImageInfo->srcImage); |
| 542 | auto dst_image_state = GetImageState(pResolveImageInfo->dstImage); |
| 543 | |
| 544 | // Update bindings between images and cmd buffer |
| 545 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 546 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 547 | } |
| 548 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 549 | void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 550 | VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 551 | uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) { |
| 552 | auto cb_node = GetCBState(commandBuffer); |
| 553 | auto src_image_state = GetImageState(srcImage); |
| 554 | auto dst_image_state = GetImageState(dstImage); |
| 555 | |
| 556 | // Update bindings between images and cmd buffer |
| 557 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 558 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 559 | } |
| 560 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 561 | void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 562 | const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 563 | auto cb_node = GetCBState(commandBuffer); |
| 564 | auto src_image_state = GetImageState(pBlitImageInfo->srcImage); |
| 565 | auto dst_image_state = GetImageState(pBlitImageInfo->dstImage); |
| 566 | |
| 567 | // Update bindings between images and cmd buffer |
| 568 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 569 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 570 | } |
| 571 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 572 | void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, |
| 573 | const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer, |
| 574 | VkResult result) { |
| 575 | if (result != VK_SUCCESS) return; |
| 576 | // 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] | 577 | auto buffer_state = std::make_shared<BUFFER_STATE>(*pBuffer, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 578 | |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 579 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
| 580 | RecordCreateBufferANDROID(pCreateInfo, buffer_state.get()); |
| 581 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 582 | // Get a set of requirements in the case the app does not |
sfricke-samsung | ad90e72 | 2020-07-08 20:54:24 -0700 | [diff] [blame] | 583 | DispatchGetBufferMemoryRequirements(device, *pBuffer, &buffer_state->requirements); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 584 | |
sfricke-samsung | edce77a | 2020-07-03 22:35:13 -0700 | [diff] [blame] | 585 | buffer_state->unprotected = ((pCreateInfo->flags & VK_BUFFER_CREATE_PROTECTED_BIT) == 0); |
| 586 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 587 | bufferMap.insert(std::make_pair(*pBuffer, std::move(buffer_state))); |
| 588 | } |
| 589 | |
| 590 | void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo, |
| 591 | const VkAllocationCallbacks *pAllocator, VkBufferView *pView, |
| 592 | VkResult result) { |
| 593 | if (result != VK_SUCCESS) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 594 | auto buffer_state = GetBufferShared(pCreateInfo->buffer); |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 595 | auto buffer_view_state = std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo); |
| 596 | |
| 597 | VkFormatProperties format_properties; |
| 598 | DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties); |
| 599 | buffer_view_state->format_features = format_properties.bufferFeatures; |
| 600 | |
| 601 | bufferViewMap.insert(std::make_pair(*pView, std::move(buffer_view_state))); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, |
| 605 | const VkAllocationCallbacks *pAllocator, VkImageView *pView, |
| 606 | VkResult result) { |
| 607 | if (result != VK_SUCCESS) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 608 | auto image_state = GetImageShared(pCreateInfo->image); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 609 | auto image_view_state = std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo); |
| 610 | |
| 611 | // Add feature support according to Image View Format Features (vkspec.html#resources-image-view-format-features) |
| 612 | const VkImageTiling image_tiling = image_state->createInfo.tiling; |
| 613 | const VkFormat image_view_format = pCreateInfo->format; |
| 614 | if (image_state->has_ahb_format == true) { |
| 615 | // The ImageView uses same Image's format feature since they share same AHB |
| 616 | image_view_state->format_features = image_state->format_features; |
| 617 | } else if (image_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { |
| 618 | // Parameter validation should catch if this is used without VK_EXT_image_drm_format_modifier |
| 619 | assert(device_extensions.vk_ext_image_drm_format_modifier); |
| 620 | VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, |
| 621 | nullptr}; |
| 622 | DispatchGetImageDrmFormatModifierPropertiesEXT(device, image_state->image, &drm_format_properties); |
| 623 | |
| 624 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr}; |
| 625 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 626 | nullptr}; |
| 627 | format_properties_2.pNext = (void *)&drm_properties_list; |
| 628 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_view_format, &format_properties_2); |
| 629 | |
| 630 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 631 | if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) { |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 632 | image_view_state->format_features |= |
| 633 | drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 634 | break; |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | } else { |
| 638 | VkFormatProperties format_properties; |
| 639 | DispatchGetPhysicalDeviceFormatProperties(physical_device, image_view_format, &format_properties); |
| 640 | image_view_state->format_features = (image_tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures |
| 641 | : format_properties.optimalTilingFeatures; |
| 642 | } |
| 643 | |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 644 | // filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw. |
| 645 | image_view_state->filter_cubic_props = lvl_init_struct<VkFilterCubicImageViewImageFormatPropertiesEXT>(); |
| 646 | if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) { |
| 647 | auto imageview_format_info = lvl_init_struct<VkPhysicalDeviceImageViewImageFormatInfoEXT>(); |
| 648 | imageview_format_info.imageViewType = pCreateInfo->viewType; |
| 649 | auto image_format_info = lvl_init_struct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info); |
| 650 | image_format_info.type = image_state->createInfo.imageType; |
| 651 | image_format_info.format = image_state->createInfo.format; |
| 652 | image_format_info.tiling = image_state->createInfo.tiling; |
| 653 | image_format_info.usage = image_state->createInfo.usage; |
| 654 | image_format_info.flags = image_state->createInfo.flags; |
| 655 | |
| 656 | auto image_format_properties = lvl_init_struct<VkImageFormatProperties2>(&image_view_state->filter_cubic_props); |
| 657 | |
| 658 | DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties); |
| 659 | } |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 660 | imageViewMap.insert(std::make_pair(*pView, std::move(image_view_state))); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 664 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
| 665 | auto cb_node = GetCBState(commandBuffer); |
| 666 | auto src_buffer_state = GetBufferState(srcBuffer); |
| 667 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 668 | |
| 669 | // Update bindings between buffers and cmd buffer |
| 670 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 671 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 672 | } |
| 673 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 674 | void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 675 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 676 | auto cb_node = GetCBState(commandBuffer); |
| 677 | auto src_buffer_state = GetBufferState(pCopyBufferInfos->srcBuffer); |
| 678 | auto dst_buffer_state = GetBufferState(pCopyBufferInfos->dstBuffer); |
| 679 | |
| 680 | // Update bindings between buffers and cmd buffer |
| 681 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 682 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 683 | } |
| 684 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 685 | void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView, |
| 686 | const VkAllocationCallbacks *pAllocator) { |
| 687 | IMAGE_VIEW_STATE *image_view_state = GetImageViewState(imageView); |
| 688 | if (!image_view_state) return; |
| 689 | const VulkanTypedHandle obj_struct(imageView, kVulkanObjectTypeImageView); |
| 690 | |
| 691 | // Any bound cmd buffers are now invalid |
| 692 | InvalidateCommandBuffers(image_view_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 693 | image_view_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 694 | imageViewMap.erase(imageView); |
| 695 | } |
| 696 | |
| 697 | void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) { |
| 698 | if (!buffer) return; |
| 699 | auto buffer_state = GetBufferState(buffer); |
| 700 | const VulkanTypedHandle obj_struct(buffer, kVulkanObjectTypeBuffer); |
| 701 | |
| 702 | InvalidateCommandBuffers(buffer_state->cb_bindings, obj_struct); |
| 703 | for (auto mem_binding : buffer_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 704 | RemoveBufferMemoryRange(buffer, mem_binding); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 705 | } |
| 706 | ClearMemoryObjectBindings(obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 707 | buffer_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 708 | bufferMap.erase(buffer_state->buffer); |
| 709 | } |
| 710 | |
| 711 | void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView, |
| 712 | const VkAllocationCallbacks *pAllocator) { |
| 713 | if (!bufferView) return; |
| 714 | auto buffer_view_state = GetBufferViewState(bufferView); |
| 715 | const VulkanTypedHandle obj_struct(bufferView, kVulkanObjectTypeBufferView); |
| 716 | |
| 717 | // Any bound cmd buffers are now invalid |
| 718 | InvalidateCommandBuffers(buffer_view_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 719 | buffer_view_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 720 | bufferViewMap.erase(bufferView); |
| 721 | } |
| 722 | |
| 723 | void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 724 | VkDeviceSize size, uint32_t data) { |
| 725 | auto cb_node = GetCBState(commandBuffer); |
| 726 | auto buffer_state = GetBufferState(dstBuffer); |
| 727 | // Update bindings between buffer and cmd buffer |
| 728 | AddCommandBufferBindingBuffer(cb_node, buffer_state); |
| 729 | } |
| 730 | |
| 731 | void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 732 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, |
| 733 | uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 734 | auto cb_node = GetCBState(commandBuffer); |
| 735 | auto src_image_state = GetImageState(srcImage); |
| 736 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 737 | |
| 738 | // Update bindings between buffer/image and cmd buffer |
| 739 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 740 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 741 | } |
| 742 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 743 | void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 744 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 745 | auto cb_node = GetCBState(commandBuffer); |
| 746 | auto src_image_state = GetImageState(pCopyImageToBufferInfo->srcImage); |
| 747 | auto dst_buffer_state = GetBufferState(pCopyImageToBufferInfo->dstBuffer); |
| 748 | |
| 749 | // Update bindings between buffer/image and cmd buffer |
| 750 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 751 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 752 | } |
| 753 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 754 | void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 755 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 756 | const VkBufferImageCopy *pRegions) { |
| 757 | auto cb_node = GetCBState(commandBuffer); |
| 758 | auto src_buffer_state = GetBufferState(srcBuffer); |
| 759 | auto dst_image_state = GetImageState(dstImage); |
| 760 | |
| 761 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 762 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 763 | } |
| 764 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 765 | void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 766 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 767 | auto cb_node = GetCBState(commandBuffer); |
| 768 | auto src_buffer_state = GetBufferState(pCopyBufferToImageInfo->srcBuffer); |
| 769 | auto dst_image_state = GetImageState(pCopyBufferToImageInfo->dstImage); |
| 770 | |
| 771 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 772 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 773 | } |
| 774 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 775 | // Get the image viewstate for a given framebuffer attachment |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 776 | IMAGE_VIEW_STATE *ValidationStateTracker::GetActiveAttachmentImageViewState(const CMD_BUFFER_STATE *cb, uint32_t index, |
| 777 | const CMD_BUFFER_STATE *primary_cb) { |
| 778 | if (primary_cb) { |
| 779 | assert(primary_cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < primary_cb->active_attachments->size())); |
| 780 | return primary_cb->active_attachments->at(index); |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 781 | } |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 782 | assert(cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < cb->active_attachments->size())); |
| 783 | return cb->active_attachments->at(index); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | // Get the image viewstate for a given framebuffer attachment |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 787 | const IMAGE_VIEW_STATE *ValidationStateTracker::GetActiveAttachmentImageViewState(const CMD_BUFFER_STATE *cb, uint32_t index, |
| 788 | const CMD_BUFFER_STATE *primary_cb) const { |
| 789 | if (primary_cb) { |
| 790 | assert(primary_cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < primary_cb->active_attachments->size())); |
| 791 | return primary_cb->active_attachments->at(index); |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 792 | } |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 793 | assert(cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < cb->active_attachments->size())); |
| 794 | return cb->active_attachments->at(index); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | void ValidationStateTracker::AddAliasingImage(IMAGE_STATE *image_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 798 | std::unordered_set<VkImage> *bound_images = nullptr; |
| 799 | |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 800 | if (image_state->bind_swapchain) { |
| 801 | auto swapchain_state = GetSwapchainState(image_state->bind_swapchain); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 802 | if (swapchain_state) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 803 | bound_images = &swapchain_state->images[image_state->bind_swapchain_imageIndex].bound_images; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 804 | } |
| 805 | } else { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 806 | if (image_state->binding.mem_state) { |
| 807 | bound_images = &image_state->binding.mem_state->bound_images; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
| 811 | if (bound_images) { |
| 812 | for (const auto &handle : *bound_images) { |
| 813 | if (handle != image_state->image) { |
| 814 | auto is = GetImageState(handle); |
| 815 | if (is && is->IsCompatibleAliasing(image_state)) { |
| 816 | auto inserted = is->aliasing_images.emplace(image_state->image); |
| 817 | if (inserted.second) { |
| 818 | image_state->aliasing_images.emplace(handle); |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | void ValidationStateTracker::RemoveAliasingImage(IMAGE_STATE *image_state) { |
| 827 | for (const auto &image : image_state->aliasing_images) { |
| 828 | auto is = GetImageState(image); |
| 829 | if (is) { |
| 830 | is->aliasing_images.erase(image_state->image); |
| 831 | } |
| 832 | } |
| 833 | image_state->aliasing_images.clear(); |
| 834 | } |
| 835 | |
| 836 | void ValidationStateTracker::RemoveAliasingImages(const std::unordered_set<VkImage> &bound_images) { |
| 837 | // This is one way clear. Because the bound_images include cross references, the one way clear loop could clear the whole |
| 838 | // reference. It doesn't need two ways clear. |
| 839 | for (const auto &handle : bound_images) { |
| 840 | auto is = GetImageState(handle); |
| 841 | if (is) { |
| 842 | is->aliasing_images.clear(); |
| 843 | } |
| 844 | } |
| 845 | } |
| 846 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 847 | const EVENT_STATE *ValidationStateTracker::GetEventState(VkEvent event) const { |
| 848 | auto it = eventMap.find(event); |
| 849 | if (it == eventMap.end()) { |
| 850 | return nullptr; |
| 851 | } |
| 852 | return &it->second; |
| 853 | } |
| 854 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 855 | EVENT_STATE *ValidationStateTracker::GetEventState(VkEvent event) { |
| 856 | auto it = eventMap.find(event); |
| 857 | if (it == eventMap.end()) { |
| 858 | return nullptr; |
| 859 | } |
| 860 | return &it->second; |
| 861 | } |
| 862 | |
| 863 | const QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) const { |
| 864 | auto it = queueMap.find(queue); |
| 865 | if (it == queueMap.cend()) { |
| 866 | return nullptr; |
| 867 | } |
| 868 | return &it->second; |
| 869 | } |
| 870 | |
| 871 | QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) { |
| 872 | auto it = queueMap.find(queue); |
| 873 | if (it == queueMap.end()) { |
| 874 | return nullptr; |
| 875 | } |
| 876 | return &it->second; |
| 877 | } |
| 878 | |
| 879 | const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) const { |
| 880 | auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map); |
| 881 | auto it = phys_dev_map->find(phys); |
| 882 | if (it == phys_dev_map->end()) { |
| 883 | return nullptr; |
| 884 | } |
| 885 | return &it->second; |
| 886 | } |
| 887 | |
| 888 | PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) { |
| 889 | auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map); |
| 890 | auto it = phys_dev_map->find(phys); |
| 891 | if (it == phys_dev_map->end()) { |
| 892 | return nullptr; |
| 893 | } |
| 894 | return &it->second; |
| 895 | } |
| 896 | |
| 897 | PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() { return physical_device_state; } |
| 898 | const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() const { return physical_device_state; } |
| 899 | |
| 900 | // Return ptr to memory binding for given handle of specified type |
| 901 | template <typename State, typename Result> |
| 902 | static Result GetObjectMemBindingImpl(State state, const VulkanTypedHandle &typed_handle) { |
| 903 | switch (typed_handle.type) { |
| 904 | case kVulkanObjectTypeImage: |
| 905 | return state->GetImageState(typed_handle.Cast<VkImage>()); |
| 906 | case kVulkanObjectTypeBuffer: |
| 907 | return state->GetBufferState(typed_handle.Cast<VkBuffer>()); |
| 908 | case kVulkanObjectTypeAccelerationStructureNV: |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 909 | return state->GetAccelerationStructureStateNV(typed_handle.Cast<VkAccelerationStructureNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 910 | default: |
| 911 | break; |
| 912 | } |
| 913 | return nullptr; |
| 914 | } |
| 915 | |
| 916 | const BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) const { |
| 917 | return GetObjectMemBindingImpl<const ValidationStateTracker *, const BINDABLE *>(this, typed_handle); |
| 918 | } |
| 919 | |
| 920 | BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) { |
| 921 | return GetObjectMemBindingImpl<ValidationStateTracker *, BINDABLE *>(this, typed_handle); |
| 922 | } |
| 923 | |
| 924 | void ValidationStateTracker::AddMemObjInfo(void *object, const VkDeviceMemory mem, const VkMemoryAllocateInfo *pAllocateInfo) { |
| 925 | assert(object != NULL); |
| 926 | |
John Zulauf | 7995271 | 2020-04-07 11:25:54 -0600 | [diff] [blame] | 927 | auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize); |
| 928 | 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] | 929 | auto mem_info = memObjMap[mem].get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 930 | |
| 931 | auto dedicated = lvl_find_in_chain<VkMemoryDedicatedAllocateInfoKHR>(pAllocateInfo->pNext); |
| 932 | if (dedicated) { |
| 933 | mem_info->is_dedicated = true; |
| 934 | mem_info->dedicated_buffer = dedicated->buffer; |
| 935 | mem_info->dedicated_image = dedicated->image; |
| 936 | } |
| 937 | auto export_info = lvl_find_in_chain<VkExportMemoryAllocateInfo>(pAllocateInfo->pNext); |
| 938 | if (export_info) { |
| 939 | mem_info->is_export = true; |
| 940 | mem_info->export_handle_type_flags = export_info->handleTypes; |
| 941 | } |
sfricke-samsung | 2306827 | 2020-06-21 14:49:51 -0700 | [diff] [blame] | 942 | |
Mark Lobodzinski | 7bda6ed | 2020-07-24 09:57:38 -0600 | [diff] [blame] | 943 | auto alloc_flags = lvl_find_in_chain<VkMemoryAllocateFlagsInfo>(pAllocateInfo->pNext); |
| 944 | if (alloc_flags) { |
| 945 | auto dev_mask = alloc_flags->deviceMask; |
| 946 | if ((dev_mask != 0) && (dev_mask & (dev_mask - 1))) { |
| 947 | mem_info->multi_instance = true; |
| 948 | } |
| 949 | } |
| 950 | 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] | 951 | mem_info->multi_instance |= (((phys_dev_mem_props.memoryHeaps[heap_index].flags & VK_MEMORY_HEAP_MULTI_INSTANCE_BIT) != 0) && |
| 952 | physical_device_count > 1); |
Mark Lobodzinski | 7bda6ed | 2020-07-24 09:57:38 -0600 | [diff] [blame] | 953 | |
sfricke-samsung | 2306827 | 2020-06-21 14:49:51 -0700 | [diff] [blame] | 954 | // Assumes validation already for only a single import operation in the pNext |
| 955 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 956 | auto win32_import = lvl_find_in_chain<VkImportMemoryWin32HandleInfoKHR>(pAllocateInfo->pNext); |
| 957 | if (win32_import) { |
| 958 | mem_info->is_import = true; |
| 959 | mem_info->import_handle_type_flags = win32_import->handleType; |
| 960 | } |
| 961 | #endif |
| 962 | auto fd_import = lvl_find_in_chain<VkImportMemoryFdInfoKHR>(pAllocateInfo->pNext); |
| 963 | if (fd_import) { |
| 964 | mem_info->is_import = true; |
| 965 | mem_info->import_handle_type_flags = fd_import->handleType; |
| 966 | } |
| 967 | auto host_pointer_import = lvl_find_in_chain<VkImportMemoryHostPointerInfoEXT>(pAllocateInfo->pNext); |
| 968 | if (host_pointer_import) { |
| 969 | mem_info->is_import = true; |
| 970 | mem_info->import_handle_type_flags = host_pointer_import->handleType; |
| 971 | } |
| 972 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 973 | // AHB Import doesn't have handle in the pNext struct |
| 974 | // It should be assumed that all imported AHB can only have the same, single handleType |
| 975 | auto ahb_import = lvl_find_in_chain<VkImportAndroidHardwareBufferInfoANDROID>(pAllocateInfo->pNext); |
| 976 | if ((ahb_import) && (ahb_import->buffer != nullptr)) { |
| 977 | mem_info->is_import_ahb = true; |
| 978 | mem_info->is_import = true; |
| 979 | mem_info->import_handle_type_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID; |
| 980 | } |
sfricke-samsung | 98acb88 | 2020-11-03 19:16:10 -0800 | [diff] [blame] | 981 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
sfricke-samsung | edce77a | 2020-07-03 22:35:13 -0700 | [diff] [blame] | 982 | |
| 983 | const VkMemoryType memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex]; |
| 984 | mem_info->unprotected = ((memory_type.propertyFlags & VK_MEMORY_PROPERTY_PROTECTED_BIT) == 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | // Create binding link between given sampler and command buffer node |
| 988 | void ValidationStateTracker::AddCommandBufferBindingSampler(CMD_BUFFER_STATE *cb_node, SAMPLER_STATE *sampler_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 989 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 990 | return; |
| 991 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 992 | AddCommandBufferBinding(sampler_state->cb_bindings, |
| 993 | VulkanTypedHandle(sampler_state->sampler, kVulkanObjectTypeSampler, sampler_state), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | // Create binding link between given image node and command buffer node |
| 997 | void ValidationStateTracker::AddCommandBufferBindingImage(CMD_BUFFER_STATE *cb_node, IMAGE_STATE *image_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 998 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 999 | return; |
| 1000 | } |
| 1001 | // Skip validation if this image was created through WSI |
| 1002 | if (image_state->create_from_swapchain == VK_NULL_HANDLE) { |
| 1003 | // First update cb binding for image |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1004 | if (AddCommandBufferBinding(image_state->cb_bindings, |
| 1005 | VulkanTypedHandle(image_state->image, kVulkanObjectTypeImage, image_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1006 | // Now update CB binding in MemObj mini CB list |
| 1007 | for (auto mem_binding : image_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1008 | // Now update CBInfo's Mem reference list |
| 1009 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 1010 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | // Create binding link between given image view node and its image with command buffer node |
| 1017 | 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] | 1018 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1019 | return; |
| 1020 | } |
| 1021 | // First add bindings for imageView |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1022 | if (AddCommandBufferBinding(view_state->cb_bindings, |
| 1023 | VulkanTypedHandle(view_state->image_view, kVulkanObjectTypeImageView, view_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1024 | // Only need to continue if this is a new item |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1025 | auto image_state = view_state->image_state.get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1026 | // Add bindings for image within imageView |
| 1027 | if (image_state) { |
| 1028 | AddCommandBufferBindingImage(cb_node, image_state); |
| 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | // Create binding link between given buffer node and command buffer node |
| 1034 | void ValidationStateTracker::AddCommandBufferBindingBuffer(CMD_BUFFER_STATE *cb_node, BUFFER_STATE *buffer_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1035 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1036 | return; |
| 1037 | } |
| 1038 | // First update cb binding for buffer |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1039 | if (AddCommandBufferBinding(buffer_state->cb_bindings, |
| 1040 | VulkanTypedHandle(buffer_state->buffer, kVulkanObjectTypeBuffer, buffer_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1041 | // Now update CB binding in MemObj mini CB list |
| 1042 | for (auto mem_binding : buffer_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1043 | // Now update CBInfo's Mem reference list |
| 1044 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 1045 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | // Create binding link between given buffer view node and its buffer with command buffer node |
| 1051 | 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] | 1052 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1053 | return; |
| 1054 | } |
| 1055 | // First add bindings for bufferView |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1056 | if (AddCommandBufferBinding(view_state->cb_bindings, |
| 1057 | VulkanTypedHandle(view_state->buffer_view, kVulkanObjectTypeBufferView, view_state), cb_node)) { |
| 1058 | auto buffer_state = view_state->buffer_state.get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1059 | // Add bindings for buffer within bufferView |
| 1060 | if (buffer_state) { |
| 1061 | AddCommandBufferBindingBuffer(cb_node, buffer_state); |
| 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | // Create binding link between given acceleration structure and command buffer node |
| 1067 | void ValidationStateTracker::AddCommandBufferBindingAccelerationStructure(CMD_BUFFER_STATE *cb_node, |
| 1068 | ACCELERATION_STRUCTURE_STATE *as_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1069 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1070 | return; |
| 1071 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1072 | if (AddCommandBufferBinding( |
| 1073 | as_state->cb_bindings, |
| 1074 | VulkanTypedHandle(as_state->acceleration_structure, kVulkanObjectTypeAccelerationStructureNV, as_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1075 | // Now update CB binding in MemObj mini CB list |
| 1076 | for (auto mem_binding : as_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1077 | // Now update CBInfo's Mem reference list |
| 1078 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 1079 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1084 | // Create binding link between given acceleration structure and command buffer node |
| 1085 | void ValidationStateTracker::AddCommandBufferBindingAccelerationStructure(CMD_BUFFER_STATE *cb_node, |
| 1086 | ACCELERATION_STRUCTURE_STATE_KHR *as_state) { |
| 1087 | if (disabled[command_buffer_state]) { |
| 1088 | return; |
| 1089 | } |
| 1090 | if (AddCommandBufferBinding( |
| 1091 | as_state->cb_bindings, |
| 1092 | VulkanTypedHandle(as_state->acceleration_structure, kVulkanObjectTypeAccelerationStructureKHR, as_state), cb_node)) { |
| 1093 | // Now update CB binding in MemObj mini CB list |
| 1094 | for (auto mem_binding : as_state->GetBoundMemory()) { |
| 1095 | // Now update CBInfo's Mem reference list |
| 1096 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 1097 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1102 | // Clear a single object binding from given memory object |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 1103 | void ValidationStateTracker::ClearMemoryObjectBinding(const VulkanTypedHandle &typed_handle, DEVICE_MEMORY_STATE *mem_info) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1104 | // This obj is bound to a memory object. Remove the reference to this object in that memory object's list |
| 1105 | if (mem_info) { |
| 1106 | mem_info->obj_bindings.erase(typed_handle); |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | // ClearMemoryObjectBindings clears the binding of objects to memory |
| 1111 | // For the given object it pulls the memory bindings and makes sure that the bindings |
| 1112 | // no longer refer to the object being cleared. This occurs when objects are destroyed. |
| 1113 | void ValidationStateTracker::ClearMemoryObjectBindings(const VulkanTypedHandle &typed_handle) { |
| 1114 | BINDABLE *mem_binding = GetObjectMemBinding(typed_handle); |
| 1115 | if (mem_binding) { |
| 1116 | if (!mem_binding->sparse) { |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 1117 | ClearMemoryObjectBinding(typed_handle, mem_binding->binding.mem_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1118 | } else { // Sparse, clear all bindings |
| 1119 | for (auto &sparse_mem_binding : mem_binding->sparse_bindings) { |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 1120 | ClearMemoryObjectBinding(typed_handle, sparse_mem_binding.mem_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | // SetMemBinding is used to establish immutable, non-sparse binding between a single image/buffer object and memory object. |
| 1127 | // Corresponding valid usage checks are in ValidateSetMemBinding(). |
| 1128 | void ValidationStateTracker::SetMemBinding(VkDeviceMemory mem, BINDABLE *mem_binding, VkDeviceSize memory_offset, |
| 1129 | const VulkanTypedHandle &typed_handle) { |
| 1130 | assert(mem_binding); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1131 | |
| 1132 | if (mem != VK_NULL_HANDLE) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1133 | mem_binding->binding.mem_state = GetShared<DEVICE_MEMORY_STATE>(mem); |
| 1134 | if (mem_binding->binding.mem_state) { |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 1135 | mem_binding->binding.offset = memory_offset; |
| 1136 | mem_binding->binding.size = mem_binding->requirements.size; |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1137 | mem_binding->binding.mem_state->obj_bindings.insert(typed_handle); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1138 | // For image objects, make sure default memory state is correctly set |
| 1139 | // TODO : What's the best/correct way to handle this? |
| 1140 | if (kVulkanObjectTypeImage == typed_handle.type) { |
| 1141 | auto const image_state = reinterpret_cast<const IMAGE_STATE *>(mem_binding); |
| 1142 | if (image_state) { |
| 1143 | VkImageCreateInfo ici = image_state->createInfo; |
| 1144 | if (ici.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) { |
| 1145 | // TODO:: More memory state transition stuff. |
| 1146 | } |
| 1147 | } |
| 1148 | } |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1149 | mem_binding->UpdateBoundMemorySet(); // force recreation of cached set |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | // For NULL mem case, clear any previous binding Else... |
| 1155 | // Make sure given object is in its object map |
| 1156 | // IF a previous binding existed, update binding |
| 1157 | // Add reference from objectInfo to memoryInfo |
| 1158 | // Add reference off of object's binding info |
| 1159 | // Return VK_TRUE if addition is successful, VK_FALSE otherwise |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1160 | bool ValidationStateTracker::SetSparseMemBinding(const VkDeviceMemory mem, const VkDeviceSize mem_offset, |
| 1161 | const VkDeviceSize mem_size, const VulkanTypedHandle &typed_handle) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1162 | bool skip = VK_FALSE; |
| 1163 | // Handle NULL case separately, just clear previous binding & decrement reference |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1164 | if (mem == VK_NULL_HANDLE) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1165 | // TODO : This should cause the range of the resource to be unbound according to spec |
| 1166 | } else { |
| 1167 | BINDABLE *mem_binding = GetObjectMemBinding(typed_handle); |
| 1168 | assert(mem_binding); |
| 1169 | if (mem_binding) { // Invalid handles are reported by object tracker, but Get returns NULL for them, so avoid SEGV here |
| 1170 | assert(mem_binding->sparse); |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1171 | MEM_BINDING binding = {GetShared<DEVICE_MEMORY_STATE>(mem), mem_offset, mem_size}; |
| 1172 | if (binding.mem_state) { |
| 1173 | binding.mem_state->obj_bindings.insert(typed_handle); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1174 | // Need to set mem binding for this object |
| 1175 | mem_binding->sparse_bindings.insert(binding); |
| 1176 | mem_binding->UpdateBoundMemorySet(); |
| 1177 | } |
| 1178 | } |
| 1179 | } |
| 1180 | return skip; |
| 1181 | } |
| 1182 | |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1183 | void ValidationStateTracker::UpdateDrawState(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, const VkPipelineBindPoint bind_point, |
| 1184 | const char *function) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1185 | const auto lv_bind_point = ConvertToLvlBindPoint(bind_point); |
| 1186 | auto &state = cb_state->lastBound[lv_bind_point]; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1187 | PIPELINE_STATE *pipe = state.pipeline_state; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1188 | if (VK_NULL_HANDLE != state.pipeline_layout) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1189 | for (const auto &set_binding_pair : pipe->active_slots) { |
| 1190 | uint32_t set_index = set_binding_pair.first; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1191 | // Pull the set node |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1192 | cvdescriptorset::DescriptorSet *descriptor_set = state.per_set[set_index].bound_descriptor_set; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1193 | |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1194 | // 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] | 1195 | |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1196 | // TODO: If recreating the reduced_map here shows up in profilinging, need to find a way of sharing with the |
| 1197 | // Validate pass. Though in the case of "many" descriptors, typically the descriptor count >> binding count |
| 1198 | cvdescriptorset::PrefilterBindRequestMap reduced_map(*descriptor_set, set_binding_pair.second); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1199 | const auto &binding_req_map = reduced_map.FilteredMap(*cb_state, *pipe); |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1200 | |
| 1201 | if (reduced_map.IsManyDescriptors()) { |
| 1202 | // 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^] | 1203 | descriptor_set->UpdateValidationCache(*cb_state, *pipe, binding_req_map); |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | // We can skip updating the state if "nothing" has changed since the last validation. |
| 1207 | // See CoreChecks::ValidateCmdBufDrawState for more details. |
| 1208 | bool descriptor_set_changed = |
| 1209 | !reduced_map.IsManyDescriptors() || |
| 1210 | // Update if descriptor set (or contents) has changed |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1211 | state.per_set[set_index].validated_set != descriptor_set || |
| 1212 | state.per_set[set_index].validated_set_change_count != descriptor_set->GetChangeCount() || |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1213 | (!disabled[image_layout_validation] && |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1214 | 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] | 1215 | bool need_update = descriptor_set_changed || |
| 1216 | // Update if previous bindingReqMap doesn't include new bindingReqMap |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1217 | !std::includes(state.per_set[set_index].validated_set_binding_req_map.begin(), |
| 1218 | 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] | 1219 | binding_req_map.end()); |
| 1220 | |
| 1221 | if (need_update) { |
| 1222 | // Bind this set and its active descriptor resources to the command buffer |
| 1223 | if (!descriptor_set_changed && reduced_map.IsManyDescriptors()) { |
| 1224 | // Only record the bindings that haven't already been recorded |
| 1225 | BindingReqMap delta_reqs; |
| 1226 | std::set_difference(binding_req_map.begin(), binding_req_map.end(), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1227 | state.per_set[set_index].validated_set_binding_req_map.begin(), |
| 1228 | state.per_set[set_index].validated_set_binding_req_map.end(), |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1229 | std::inserter(delta_reqs, delta_reqs.begin())); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1230 | descriptor_set->UpdateDrawState(this, cb_state, cmd_type, pipe, delta_reqs, function); |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1231 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1232 | 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] | 1233 | } |
| 1234 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1235 | state.per_set[set_index].validated_set = descriptor_set; |
| 1236 | state.per_set[set_index].validated_set_change_count = descriptor_set->GetChangeCount(); |
| 1237 | 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] | 1238 | if (reduced_map.IsManyDescriptors()) { |
| 1239 | // Check whether old == new before assigning, the equality check is much cheaper than |
| 1240 | // freeing and reallocating the map. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1241 | if (state.per_set[set_index].validated_set_binding_req_map != set_binding_pair.second) { |
| 1242 | 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] | 1243 | } |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1244 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1245 | state.per_set[set_index].validated_set_binding_req_map = BindingReqMap(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | } |
| 1249 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1250 | if (!pipe->vertex_binding_descriptions_.empty()) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1251 | cb_state->vertex_buffer_used = true; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | // Remove set from setMap and delete the set |
| 1256 | void ValidationStateTracker::FreeDescriptorSet(cvdescriptorset::DescriptorSet *descriptor_set) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 1257 | descriptor_set->destroyed = true; |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1258 | const VulkanTypedHandle obj_struct(descriptor_set->GetSet(), kVulkanObjectTypeDescriptorSet); |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1259 | // Any bound cmd buffers are now invalid |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1260 | InvalidateCommandBuffers(descriptor_set->cb_bindings, obj_struct); |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1261 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1262 | setMap.erase(descriptor_set->GetSet()); |
| 1263 | } |
| 1264 | |
| 1265 | // Free all DS Pools including their Sets & related sub-structs |
| 1266 | // NOTE : Calls to this function should be wrapped in mutex |
| 1267 | void ValidationStateTracker::DeleteDescriptorSetPools() { |
| 1268 | for (auto ii = descriptorPoolMap.begin(); ii != descriptorPoolMap.end();) { |
| 1269 | // Remove this pools' sets from setMap and delete them |
| 1270 | for (auto ds : ii->second->sets) { |
| 1271 | FreeDescriptorSet(ds); |
| 1272 | } |
| 1273 | ii->second->sets.clear(); |
| 1274 | ii = descriptorPoolMap.erase(ii); |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | // For given object struct return a ptr of BASE_NODE type for its wrapping struct |
| 1279 | BASE_NODE *ValidationStateTracker::GetStateStructPtrFromObject(const VulkanTypedHandle &object_struct) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1280 | if (object_struct.node) { |
| 1281 | #ifdef _DEBUG |
| 1282 | // assert that lookup would find the same object |
| 1283 | VulkanTypedHandle other = object_struct; |
| 1284 | other.node = nullptr; |
| 1285 | assert(object_struct.node == GetStateStructPtrFromObject(other)); |
| 1286 | #endif |
| 1287 | return object_struct.node; |
| 1288 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1289 | BASE_NODE *base_ptr = nullptr; |
| 1290 | switch (object_struct.type) { |
| 1291 | case kVulkanObjectTypeDescriptorSet: { |
| 1292 | base_ptr = GetSetNode(object_struct.Cast<VkDescriptorSet>()); |
| 1293 | break; |
| 1294 | } |
| 1295 | case kVulkanObjectTypeSampler: { |
| 1296 | base_ptr = GetSamplerState(object_struct.Cast<VkSampler>()); |
| 1297 | break; |
| 1298 | } |
| 1299 | case kVulkanObjectTypeQueryPool: { |
| 1300 | base_ptr = GetQueryPoolState(object_struct.Cast<VkQueryPool>()); |
| 1301 | break; |
| 1302 | } |
| 1303 | case kVulkanObjectTypePipeline: { |
| 1304 | base_ptr = GetPipelineState(object_struct.Cast<VkPipeline>()); |
| 1305 | break; |
| 1306 | } |
| 1307 | case kVulkanObjectTypeBuffer: { |
| 1308 | base_ptr = GetBufferState(object_struct.Cast<VkBuffer>()); |
| 1309 | break; |
| 1310 | } |
| 1311 | case kVulkanObjectTypeBufferView: { |
| 1312 | base_ptr = GetBufferViewState(object_struct.Cast<VkBufferView>()); |
| 1313 | break; |
| 1314 | } |
| 1315 | case kVulkanObjectTypeImage: { |
| 1316 | base_ptr = GetImageState(object_struct.Cast<VkImage>()); |
| 1317 | break; |
| 1318 | } |
| 1319 | case kVulkanObjectTypeImageView: { |
| 1320 | base_ptr = GetImageViewState(object_struct.Cast<VkImageView>()); |
| 1321 | break; |
| 1322 | } |
| 1323 | case kVulkanObjectTypeEvent: { |
| 1324 | base_ptr = GetEventState(object_struct.Cast<VkEvent>()); |
| 1325 | break; |
| 1326 | } |
| 1327 | case kVulkanObjectTypeDescriptorPool: { |
| 1328 | base_ptr = GetDescriptorPoolState(object_struct.Cast<VkDescriptorPool>()); |
| 1329 | break; |
| 1330 | } |
| 1331 | case kVulkanObjectTypeCommandPool: { |
| 1332 | base_ptr = GetCommandPoolState(object_struct.Cast<VkCommandPool>()); |
| 1333 | break; |
| 1334 | } |
| 1335 | case kVulkanObjectTypeFramebuffer: { |
| 1336 | base_ptr = GetFramebufferState(object_struct.Cast<VkFramebuffer>()); |
| 1337 | break; |
| 1338 | } |
| 1339 | case kVulkanObjectTypeRenderPass: { |
| 1340 | base_ptr = GetRenderPassState(object_struct.Cast<VkRenderPass>()); |
| 1341 | break; |
| 1342 | } |
| 1343 | case kVulkanObjectTypeDeviceMemory: { |
| 1344 | base_ptr = GetDevMemState(object_struct.Cast<VkDeviceMemory>()); |
| 1345 | break; |
| 1346 | } |
| 1347 | case kVulkanObjectTypeAccelerationStructureNV: { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1348 | base_ptr = GetAccelerationStructureStateNV(object_struct.Cast<VkAccelerationStructureNV>()); |
| 1349 | break; |
| 1350 | } |
| 1351 | case kVulkanObjectTypeAccelerationStructureKHR: { |
| 1352 | base_ptr = GetAccelerationStructureStateKHR(object_struct.Cast<VkAccelerationStructureKHR>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1353 | break; |
| 1354 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1355 | case kVulkanObjectTypeUnknown: |
| 1356 | // This can happen if an element of the object_bindings vector has been |
| 1357 | // zeroed out, after an object is destroyed. |
| 1358 | break; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1359 | default: |
| 1360 | // TODO : Any other objects to be handled here? |
| 1361 | assert(0); |
| 1362 | break; |
| 1363 | } |
| 1364 | return base_ptr; |
| 1365 | } |
| 1366 | |
sfricke-samsung | bf1a2ed | 2020-06-14 23:31:00 -0700 | [diff] [blame] | 1367 | // Gets union of all features defined by Potential Format Features |
| 1368 | // 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] | 1369 | VkFormatFeatureFlags ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const { |
| 1370 | VkFormatFeatureFlags format_features = 0; |
| 1371 | |
| 1372 | if (format != VK_FORMAT_UNDEFINED) { |
| 1373 | VkFormatProperties format_properties; |
| 1374 | DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties); |
| 1375 | format_features |= format_properties.linearTilingFeatures; |
| 1376 | format_features |= format_properties.optimalTilingFeatures; |
| 1377 | if (device_extensions.vk_ext_image_drm_format_modifier) { |
| 1378 | // VK_KHR_get_physical_device_properties2 is required in this case |
| 1379 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; |
| 1380 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 1381 | nullptr}; |
| 1382 | format_properties_2.pNext = (void *)&drm_properties_list; |
| 1383 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2); |
| 1384 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
| 1385 | format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | return format_features; |
| 1391 | } |
| 1392 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1393 | // Tie the VulkanTypedHandle to the cmd buffer which includes: |
| 1394 | // Add object_binding to cmd buffer |
| 1395 | // Add cb_binding to object |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1396 | bool ValidationStateTracker::AddCommandBufferBinding(small_unordered_map<CMD_BUFFER_STATE *, int, 8> &cb_bindings, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1397 | const VulkanTypedHandle &obj, CMD_BUFFER_STATE *cb_node) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1398 | if (disabled[command_buffer_state]) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1399 | return false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1400 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1401 | // Insert the cb_binding with a default 'index' of -1. Then push the obj into the object_bindings |
| 1402 | // vector, and update cb_bindings[cb_node] with the index of that element of the vector. |
| 1403 | auto inserted = cb_bindings.insert({cb_node, -1}); |
| 1404 | if (inserted.second) { |
| 1405 | cb_node->object_bindings.push_back(obj); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1406 | inserted.first->second = static_cast<int>(cb_node->object_bindings.size()) - 1; |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1407 | return true; |
| 1408 | } |
| 1409 | return false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | // For a given object, if cb_node is in that objects cb_bindings, remove cb_node |
| 1413 | void ValidationStateTracker::RemoveCommandBufferBinding(VulkanTypedHandle const &object, CMD_BUFFER_STATE *cb_node) { |
| 1414 | BASE_NODE *base_obj = GetStateStructPtrFromObject(object); |
| 1415 | if (base_obj) base_obj->cb_bindings.erase(cb_node); |
| 1416 | } |
| 1417 | |
| 1418 | // Reset the command buffer state |
| 1419 | // Maintain the createInfo and set state to CB_NEW, but clear all other state |
| 1420 | void ValidationStateTracker::ResetCommandBufferState(const VkCommandBuffer cb) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1421 | CMD_BUFFER_STATE *cb_state = GetCBState(cb); |
| 1422 | if (cb_state) { |
| 1423 | cb_state->in_use.store(0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1424 | // Reset CB state (note that createInfo is not cleared) |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1425 | cb_state->commandBuffer = cb; |
| 1426 | memset(&cb_state->beginInfo, 0, sizeof(VkCommandBufferBeginInfo)); |
| 1427 | memset(&cb_state->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo)); |
| 1428 | cb_state->hasDrawCmd = false; |
| 1429 | cb_state->hasTraceRaysCmd = false; |
| 1430 | cb_state->hasBuildAccelerationStructureCmd = false; |
| 1431 | cb_state->hasDispatchCmd = false; |
| 1432 | cb_state->state = CB_NEW; |
| 1433 | cb_state->commandCount = 0; |
| 1434 | cb_state->submitCount = 0; |
| 1435 | cb_state->image_layout_change_count = 1; // Start at 1. 0 is insert value for validation cache versions, s.t. new == dirty |
| 1436 | cb_state->status = 0; |
| 1437 | cb_state->static_status = 0; |
| 1438 | cb_state->viewportMask = 0; |
| 1439 | cb_state->viewportWithCountMask = 0; |
| 1440 | cb_state->viewportWithCountCount = 0; |
| 1441 | cb_state->scissorMask = 0; |
| 1442 | cb_state->scissorWithCountMask = 0; |
| 1443 | cb_state->primitiveTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1444 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1445 | for (auto &item : cb_state->lastBound) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1446 | item.reset(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1447 | } |
| 1448 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1449 | cb_state->activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo(); |
| 1450 | cb_state->activeRenderPass = nullptr; |
| 1451 | cb_state->active_attachments = nullptr; |
| 1452 | cb_state->active_subpasses = nullptr; |
| 1453 | cb_state->attachments_view_states.clear(); |
| 1454 | cb_state->activeSubpassContents = VK_SUBPASS_CONTENTS_INLINE; |
| 1455 | cb_state->activeSubpass = 0; |
| 1456 | cb_state->broken_bindings.clear(); |
| 1457 | cb_state->waitedEvents.clear(); |
| 1458 | cb_state->events.clear(); |
| 1459 | cb_state->writeEventsBeforeWait.clear(); |
| 1460 | cb_state->activeQueries.clear(); |
| 1461 | cb_state->startedQueries.clear(); |
| 1462 | cb_state->image_layout_map.clear(); |
| 1463 | cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.clear(); |
| 1464 | cb_state->vertex_buffer_used = false; |
| 1465 | cb_state->primaryCommandBuffer = VK_NULL_HANDLE; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1466 | // If secondary, invalidate any primary command buffer that may call us. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1467 | if (cb_state->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
| 1468 | InvalidateLinkedCommandBuffers(cb_state->linkedCommandBuffers, VulkanTypedHandle(cb, kVulkanObjectTypeCommandBuffer)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | // Remove reverse command buffer links. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1472 | for (auto sub_cb : cb_state->linkedCommandBuffers) { |
| 1473 | sub_cb->linkedCommandBuffers.erase(cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1474 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1475 | cb_state->linkedCommandBuffers.clear(); |
| 1476 | cb_state->queue_submit_functions.clear(); |
| 1477 | cb_state->cmd_execute_commands_functions.clear(); |
| 1478 | cb_state->eventUpdates.clear(); |
| 1479 | cb_state->queryUpdates.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1480 | |
| 1481 | // Remove object bindings |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1482 | for (const auto &obj : cb_state->object_bindings) { |
| 1483 | RemoveCommandBufferBinding(obj, cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1484 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1485 | cb_state->object_bindings.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1486 | // Remove this cmdBuffer's reference from each FrameBuffer's CB ref list |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1487 | for (auto framebuffer : cb_state->framebuffers) { |
| 1488 | framebuffer->cb_bindings.erase(cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1489 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1490 | cb_state->framebuffers.clear(); |
| 1491 | cb_state->activeFramebuffer = VK_NULL_HANDLE; |
| 1492 | cb_state->index_buffer_binding.reset(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1493 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1494 | cb_state->qfo_transfer_image_barriers.Reset(); |
| 1495 | cb_state->qfo_transfer_buffer_barriers.Reset(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1496 | |
| 1497 | // Clean up the label data |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1498 | ResetCmdDebugUtilsLabel(report_data, cb_state->commandBuffer); |
| 1499 | cb_state->debug_label.Reset(); |
| 1500 | cb_state->validate_descriptorsets_in_queuesubmit.clear(); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1501 | |
| 1502 | // Best practices info |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1503 | cb_state->small_indexed_draw_call_count = 0; |
Jeremy Hayes | 9bda85a | 2020-05-21 16:36:17 -0600 | [diff] [blame] | 1504 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 1505 | cb_state->transform_feedback_active = false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1506 | } |
| 1507 | if (command_buffer_reset_callback) { |
| 1508 | (*command_buffer_reset_callback)(cb); |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 1513 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, |
| 1514 | VkResult result) { |
| 1515 | if (VK_SUCCESS != result) return; |
| 1516 | |
| 1517 | const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures; |
| 1518 | if (nullptr == enabled_features_found) { |
| 1519 | const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext); |
| 1520 | if (features2) { |
| 1521 | enabled_features_found = &(features2->features); |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 1526 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type); |
| 1527 | ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data); |
| 1528 | |
| 1529 | if (nullptr == enabled_features_found) { |
| 1530 | state_tracker->enabled_features.core = {}; |
| 1531 | } else { |
| 1532 | state_tracker->enabled_features.core = *enabled_features_found; |
| 1533 | } |
| 1534 | |
| 1535 | // Make sure that queue_family_properties are obtained for this device's physical_device, even if the app has not |
| 1536 | // previously set them through an explicit API call. |
| 1537 | uint32_t count; |
| 1538 | auto pd_state = GetPhysicalDeviceState(gpu); |
| 1539 | DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr); |
| 1540 | pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count)); |
| 1541 | DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, &pd_state->queue_family_properties[0]); |
| 1542 | // Save local link to this device's physical device state |
| 1543 | state_tracker->physical_device_state = pd_state; |
| 1544 | |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1545 | const auto *vulkan_12_features = lvl_find_in_chain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext); |
| 1546 | if (vulkan_12_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1547 | state_tracker->enabled_features.core12 = *vulkan_12_features; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1548 | } else { |
sfricke-samsung | 27c7072 | 2020-05-02 08:42:39 -0700 | [diff] [blame] | 1549 | // Set Extension Feature Aliases to false as there is no struct to check |
| 1550 | state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE; |
| 1551 | state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE; |
| 1552 | state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE; |
| 1553 | state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE; |
| 1554 | state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE; |
| 1555 | state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE; |
| 1556 | |
| 1557 | // 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] | 1558 | |
| 1559 | const auto *eight_bit_storage_features = lvl_find_in_chain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext); |
| 1560 | if (eight_bit_storage_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1561 | state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess; |
| 1562 | state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess = |
| 1563 | eight_bit_storage_features->uniformAndStorageBuffer8BitAccess; |
| 1564 | state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | const auto *float16_int8_features = lvl_find_in_chain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext); |
| 1568 | if (float16_int8_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1569 | state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16; |
| 1570 | state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | const auto *descriptor_indexing_features = |
| 1574 | lvl_find_in_chain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext); |
| 1575 | if (descriptor_indexing_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1576 | state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing = |
| 1577 | descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing; |
| 1578 | state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing = |
| 1579 | descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing; |
| 1580 | state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing = |
| 1581 | descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing; |
| 1582 | state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing = |
| 1583 | descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing; |
| 1584 | state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing = |
| 1585 | descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing; |
| 1586 | state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing = |
| 1587 | descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing; |
| 1588 | state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing = |
| 1589 | descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing; |
| 1590 | state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing = |
| 1591 | descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing; |
| 1592 | state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing = |
| 1593 | descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing; |
| 1594 | state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing = |
| 1595 | descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing; |
| 1596 | state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind = |
| 1597 | descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind; |
| 1598 | state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind = |
| 1599 | descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind; |
| 1600 | state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind = |
| 1601 | descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind; |
| 1602 | state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind = |
| 1603 | descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind; |
| 1604 | state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind = |
| 1605 | descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind; |
| 1606 | state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind = |
| 1607 | descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind; |
| 1608 | state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending = |
| 1609 | descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending; |
| 1610 | state_tracker->enabled_features.core12.descriptorBindingPartiallyBound = |
| 1611 | descriptor_indexing_features->descriptorBindingPartiallyBound; |
| 1612 | state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount = |
| 1613 | descriptor_indexing_features->descriptorBindingVariableDescriptorCount; |
| 1614 | state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1617 | const auto *scalar_block_layout_features = lvl_find_in_chain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1618 | if (scalar_block_layout_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1619 | state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | const auto *imageless_framebuffer_features = |
| 1623 | lvl_find_in_chain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext); |
| 1624 | if (imageless_framebuffer_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1625 | state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | const auto *uniform_buffer_standard_layout_features = |
| 1629 | lvl_find_in_chain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext); |
| 1630 | if (uniform_buffer_standard_layout_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1631 | state_tracker->enabled_features.core12.uniformBufferStandardLayout = |
| 1632 | uniform_buffer_standard_layout_features->uniformBufferStandardLayout; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | const auto *subgroup_extended_types_features = |
| 1636 | lvl_find_in_chain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext); |
| 1637 | if (subgroup_extended_types_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1638 | state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes = |
| 1639 | subgroup_extended_types_features->shaderSubgroupExtendedTypes; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | const auto *separate_depth_stencil_layouts_features = |
| 1643 | lvl_find_in_chain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext); |
| 1644 | if (separate_depth_stencil_layouts_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1645 | state_tracker->enabled_features.core12.separateDepthStencilLayouts = |
| 1646 | separate_depth_stencil_layouts_features->separateDepthStencilLayouts; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | const auto *host_query_reset_features = lvl_find_in_chain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext); |
| 1650 | if (host_query_reset_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1651 | state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1654 | const auto *timeline_semaphore_features = lvl_find_in_chain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1655 | if (timeline_semaphore_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1656 | state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | const auto *buffer_device_address = lvl_find_in_chain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext); |
| 1660 | if (buffer_device_address) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1661 | state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress; |
| 1662 | state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay = |
| 1663 | buffer_device_address->bufferDeviceAddressCaptureReplay; |
| 1664 | state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice = |
| 1665 | buffer_device_address->bufferDeviceAddressMultiDevice; |
| 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | const auto *vulkan_11_features = lvl_find_in_chain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext); |
| 1670 | if (vulkan_11_features) { |
| 1671 | state_tracker->enabled_features.core11 = *vulkan_11_features; |
| 1672 | } else { |
| 1673 | // These structs are only allowed in pNext chain if there is no kPhysicalDeviceVulkan11Features |
| 1674 | |
| 1675 | const auto *sixteen_bit_storage_features = lvl_find_in_chain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext); |
| 1676 | if (sixteen_bit_storage_features) { |
| 1677 | state_tracker->enabled_features.core11.storageBuffer16BitAccess = |
| 1678 | sixteen_bit_storage_features->storageBuffer16BitAccess; |
| 1679 | state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess = |
| 1680 | sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess; |
| 1681 | state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16; |
| 1682 | state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16; |
| 1683 | } |
| 1684 | |
| 1685 | const auto *multiview_features = lvl_find_in_chain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext); |
| 1686 | if (multiview_features) { |
| 1687 | state_tracker->enabled_features.core11.multiview = multiview_features->multiview; |
| 1688 | state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader; |
| 1689 | state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader; |
| 1690 | } |
| 1691 | |
| 1692 | const auto *variable_pointers_features = lvl_find_in_chain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext); |
| 1693 | if (variable_pointers_features) { |
| 1694 | state_tracker->enabled_features.core11.variablePointersStorageBuffer = |
| 1695 | variable_pointers_features->variablePointersStorageBuffer; |
| 1696 | state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers; |
| 1697 | } |
| 1698 | |
| 1699 | const auto *protected_memory_features = lvl_find_in_chain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext); |
| 1700 | if (protected_memory_features) { |
| 1701 | state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory; |
| 1702 | } |
| 1703 | |
| 1704 | const auto *ycbcr_conversion_features = |
| 1705 | lvl_find_in_chain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext); |
| 1706 | if (ycbcr_conversion_features) { |
| 1707 | state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion; |
| 1708 | } |
| 1709 | |
| 1710 | const auto *shader_draw_parameters_features = |
| 1711 | lvl_find_in_chain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext); |
| 1712 | if (shader_draw_parameters_features) { |
| 1713 | state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1714 | } |
| 1715 | } |
| 1716 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1717 | const auto *device_group_ci = lvl_find_in_chain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext); |
Tony-LunarG | ca4891a | 2020-08-10 15:46:46 -0600 | [diff] [blame] | 1718 | if (device_group_ci) { |
| 1719 | state_tracker->physical_device_count = device_group_ci->physicalDeviceCount; |
| 1720 | state_tracker->device_group_create_info = *device_group_ci; |
| 1721 | } else { |
| 1722 | state_tracker->physical_device_count = 1; |
| 1723 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1724 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1725 | const auto *exclusive_scissor_features = lvl_find_in_chain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext); |
| 1726 | if (exclusive_scissor_features) { |
| 1727 | state_tracker->enabled_features.exclusive_scissor = *exclusive_scissor_features; |
| 1728 | } |
| 1729 | |
| 1730 | const auto *shading_rate_image_features = lvl_find_in_chain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext); |
| 1731 | if (shading_rate_image_features) { |
| 1732 | state_tracker->enabled_features.shading_rate_image = *shading_rate_image_features; |
| 1733 | } |
| 1734 | |
| 1735 | const auto *mesh_shader_features = lvl_find_in_chain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext); |
| 1736 | if (mesh_shader_features) { |
| 1737 | state_tracker->enabled_features.mesh_shader = *mesh_shader_features; |
| 1738 | } |
| 1739 | |
| 1740 | const auto *inline_uniform_block_features = |
| 1741 | lvl_find_in_chain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext); |
| 1742 | if (inline_uniform_block_features) { |
| 1743 | state_tracker->enabled_features.inline_uniform_block = *inline_uniform_block_features; |
| 1744 | } |
| 1745 | |
| 1746 | const auto *transform_feedback_features = lvl_find_in_chain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext); |
| 1747 | if (transform_feedback_features) { |
| 1748 | state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features; |
| 1749 | } |
| 1750 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1751 | const auto *vtx_attrib_div_features = lvl_find_in_chain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext); |
| 1752 | if (vtx_attrib_div_features) { |
| 1753 | state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features; |
| 1754 | } |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1755 | |
Jeff Bolz | 4563f2a | 2019-12-10 13:30:30 -0600 | [diff] [blame] | 1756 | const auto *buffer_device_address_ext = lvl_find_in_chain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext); |
| 1757 | if (buffer_device_address_ext) { |
Jeff Bolz | 33fc672 | 2020-03-31 12:58:16 -0500 | [diff] [blame] | 1758 | state_tracker->enabled_features.buffer_device_address_ext = *buffer_device_address_ext; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | const auto *cooperative_matrix_features = lvl_find_in_chain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext); |
| 1762 | if (cooperative_matrix_features) { |
| 1763 | state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features; |
| 1764 | } |
| 1765 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1766 | const auto *compute_shader_derivatives_features = |
| 1767 | lvl_find_in_chain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext); |
| 1768 | if (compute_shader_derivatives_features) { |
| 1769 | state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features; |
| 1770 | } |
| 1771 | |
| 1772 | const auto *fragment_shader_barycentric_features = |
| 1773 | lvl_find_in_chain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext); |
| 1774 | if (fragment_shader_barycentric_features) { |
| 1775 | state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features; |
| 1776 | } |
| 1777 | |
| 1778 | const auto *shader_image_footprint_features = |
| 1779 | lvl_find_in_chain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext); |
| 1780 | if (shader_image_footprint_features) { |
| 1781 | state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features; |
| 1782 | } |
| 1783 | |
| 1784 | const auto *fragment_shader_interlock_features = |
| 1785 | lvl_find_in_chain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext); |
| 1786 | if (fragment_shader_interlock_features) { |
| 1787 | state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features; |
| 1788 | } |
| 1789 | |
| 1790 | const auto *demote_to_helper_invocation_features = |
| 1791 | lvl_find_in_chain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext); |
| 1792 | if (demote_to_helper_invocation_features) { |
| 1793 | state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features; |
| 1794 | } |
| 1795 | |
| 1796 | const auto *texel_buffer_alignment_features = |
| 1797 | lvl_find_in_chain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext); |
| 1798 | if (texel_buffer_alignment_features) { |
| 1799 | state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features; |
| 1800 | } |
| 1801 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1802 | const auto *pipeline_exe_props_features = |
| 1803 | lvl_find_in_chain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext); |
| 1804 | if (pipeline_exe_props_features) { |
| 1805 | state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features; |
| 1806 | } |
| 1807 | |
Jeff Bolz | 82f854d | 2019-09-17 14:56:47 -0500 | [diff] [blame] | 1808 | const auto *dedicated_allocation_image_aliasing_features = |
| 1809 | lvl_find_in_chain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext); |
| 1810 | if (dedicated_allocation_image_aliasing_features) { |
| 1811 | state_tracker->enabled_features.dedicated_allocation_image_aliasing_features = |
| 1812 | *dedicated_allocation_image_aliasing_features; |
| 1813 | } |
| 1814 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 1815 | const auto *performance_query_features = lvl_find_in_chain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext); |
| 1816 | if (performance_query_features) { |
| 1817 | state_tracker->enabled_features.performance_query_features = *performance_query_features; |
| 1818 | } |
| 1819 | |
Tobias Hector | 782bcde | 2019-11-28 16:19:42 +0000 | [diff] [blame] | 1820 | const auto *device_coherent_memory_features = lvl_find_in_chain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext); |
| 1821 | if (device_coherent_memory_features) { |
| 1822 | state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features; |
| 1823 | } |
| 1824 | |
sfricke-samsung | cead080 | 2020-01-30 22:20:10 -0800 | [diff] [blame] | 1825 | const auto *ycbcr_image_array_features = lvl_find_in_chain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext); |
| 1826 | if (ycbcr_image_array_features) { |
| 1827 | state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features; |
| 1828 | } |
| 1829 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1830 | const auto *ray_query_features = lvl_find_in_chain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext); |
| 1831 | if (ray_query_features) { |
| 1832 | state_tracker->enabled_features.ray_query_features = *ray_query_features; |
| 1833 | } |
| 1834 | |
| 1835 | const auto *ray_tracing_pipeline_features = |
| 1836 | lvl_find_in_chain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext); |
| 1837 | if (ray_tracing_pipeline_features) { |
| 1838 | state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features; |
| 1839 | } |
| 1840 | |
| 1841 | const auto *ray_tracing_acceleration_structure_features = |
| 1842 | lvl_find_in_chain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext); |
| 1843 | if (ray_tracing_acceleration_structure_features) { |
| 1844 | 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] | 1845 | } |
| 1846 | |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 1847 | const auto *robustness2_features = lvl_find_in_chain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext); |
| 1848 | if (robustness2_features) { |
| 1849 | state_tracker->enabled_features.robustness2_features = *robustness2_features; |
| 1850 | } |
| 1851 | |
janharaldfredriksen-arm | 3b79377 | 2020-05-12 18:55:53 +0200 | [diff] [blame] | 1852 | const auto *fragment_density_map_features = |
| 1853 | lvl_find_in_chain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext); |
| 1854 | if (fragment_density_map_features) { |
| 1855 | state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features; |
| 1856 | } |
| 1857 | |
janharaldfredriksen-arm | 36e1757 | 2020-07-07 13:59:28 +0200 | [diff] [blame] | 1858 | const auto *fragment_density_map_features2 = |
| 1859 | lvl_find_in_chain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext); |
| 1860 | if (fragment_density_map_features2) { |
| 1861 | state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2; |
| 1862 | } |
| 1863 | |
sfricke-samsung | 0c4a06f | 2020-06-27 01:24:32 -0700 | [diff] [blame] | 1864 | const auto *astc_decode_features = lvl_find_in_chain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext); |
| 1865 | if (astc_decode_features) { |
| 1866 | state_tracker->enabled_features.astc_decode_features = *astc_decode_features; |
| 1867 | } |
| 1868 | |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 1869 | const auto *custom_border_color_features = lvl_find_in_chain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext); |
| 1870 | if (custom_border_color_features) { |
| 1871 | state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features; |
| 1872 | } |
| 1873 | |
sfricke-samsung | fd661d6 | 2020-05-16 00:57:27 -0700 | [diff] [blame] | 1874 | const auto *pipeline_creation_cache_control_features = |
| 1875 | lvl_find_in_chain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext); |
| 1876 | if (pipeline_creation_cache_control_features) { |
| 1877 | state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features; |
| 1878 | } |
| 1879 | |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 1880 | const auto *fragment_shading_rate_features = |
| 1881 | lvl_find_in_chain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext); |
| 1882 | if (fragment_shading_rate_features) { |
| 1883 | state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features; |
| 1884 | } |
| 1885 | |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 1886 | const auto *extended_dynamic_state_features = |
| 1887 | lvl_find_in_chain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext); |
| 1888 | if (extended_dynamic_state_features) { |
| 1889 | state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features; |
| 1890 | } |
| 1891 | |
locke-lunarg | 3fa463a | 2020-10-23 16:39:04 -0600 | [diff] [blame] | 1892 | const auto *multiview_features = lvl_find_in_chain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext); |
| 1893 | if (multiview_features) { |
| 1894 | state_tracker->enabled_features.multiview_features = *multiview_features; |
| 1895 | } |
| 1896 | |
Nathaniel Cesario | b3f2d70 | 2020-11-09 09:20:49 -0700 | [diff] [blame] | 1897 | const auto *portability_features = lvl_find_in_chain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext); |
| 1898 | if (portability_features) { |
| 1899 | state_tracker->enabled_features.portability_subset_features = *portability_features; |
| 1900 | } |
| 1901 | |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1902 | const auto *shader_integer_functions2_features = |
| 1903 | lvl_find_in_chain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext); |
| 1904 | if (shader_integer_functions2_features) { |
| 1905 | state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features; |
| 1906 | } |
| 1907 | |
| 1908 | const auto *shader_sm_builtins_feature = lvl_find_in_chain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext); |
| 1909 | if (shader_sm_builtins_feature) { |
| 1910 | state_tracker->enabled_features.shader_sm_builtins_feature = *shader_sm_builtins_feature; |
| 1911 | } |
| 1912 | |
| 1913 | const auto *shader_atomic_float_feature = lvl_find_in_chain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext); |
| 1914 | if (shader_atomic_float_feature) { |
| 1915 | state_tracker->enabled_features.shader_atomic_float_feature = *shader_atomic_float_feature; |
| 1916 | } |
| 1917 | |
| 1918 | const auto *shader_image_atomic_int64_feature = |
| 1919 | lvl_find_in_chain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext); |
| 1920 | if (shader_image_atomic_int64_feature) { |
| 1921 | state_tracker->enabled_features.shader_image_atomic_int64_feature = *shader_image_atomic_int64_feature; |
| 1922 | } |
| 1923 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1924 | // Store physical device properties and physical device mem limits into CoreChecks structs |
| 1925 | DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props); |
| 1926 | DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1927 | GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2, |
| 1928 | &state_tracker->phys_dev_props_core11); |
| 1929 | GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2, |
| 1930 | &state_tracker->phys_dev_props_core12); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1931 | |
| 1932 | const auto &dev_ext = state_tracker->device_extensions; |
| 1933 | auto *phys_dev_props = &state_tracker->phys_dev_ext_props; |
| 1934 | |
| 1935 | if (dev_ext.vk_khr_push_descriptor) { |
| 1936 | // Get the needed push_descriptor limits |
| 1937 | VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor_prop; |
| 1938 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &push_descriptor_prop); |
| 1939 | phys_dev_props->max_push_descriptors = push_descriptor_prop.maxPushDescriptors; |
| 1940 | } |
| 1941 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1942 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_ext_descriptor_indexing) { |
| 1943 | VkPhysicalDeviceDescriptorIndexingPropertiesEXT descriptor_indexing_prop; |
| 1944 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop); |
| 1945 | state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools = |
| 1946 | descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools; |
| 1947 | state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative = |
| 1948 | descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative; |
| 1949 | state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative = |
| 1950 | descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative; |
| 1951 | state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative = |
| 1952 | descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative; |
| 1953 | state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative = |
| 1954 | descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative; |
| 1955 | state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative = |
| 1956 | descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative; |
| 1957 | state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind = |
| 1958 | descriptor_indexing_prop.robustBufferAccessUpdateAfterBind; |
| 1959 | state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod; |
| 1960 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers = |
| 1961 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers; |
| 1962 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers = |
| 1963 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers; |
| 1964 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers = |
| 1965 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers; |
| 1966 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages = |
| 1967 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages; |
| 1968 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages = |
| 1969 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages; |
| 1970 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments = |
| 1971 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments; |
| 1972 | state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources = |
| 1973 | descriptor_indexing_prop.maxPerStageUpdateAfterBindResources; |
| 1974 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers = |
| 1975 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers; |
| 1976 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers = |
| 1977 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers; |
| 1978 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic = |
| 1979 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic; |
| 1980 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers = |
| 1981 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers; |
| 1982 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic = |
| 1983 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic; |
| 1984 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages = |
| 1985 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages; |
| 1986 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages = |
| 1987 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages; |
| 1988 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments = |
| 1989 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments; |
| 1990 | } |
| 1991 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1992 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props); |
| 1993 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props); |
| 1994 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props); |
| 1995 | 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] | 1996 | |
| 1997 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_depth_stencil_resolve) { |
| 1998 | VkPhysicalDeviceDepthStencilResolvePropertiesKHR depth_stencil_resolve_props; |
| 1999 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props); |
| 2000 | state_tracker->phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes; |
| 2001 | state_tracker->phys_dev_props_core12.supportedStencilResolveModes = |
| 2002 | depth_stencil_resolve_props.supportedStencilResolveModes; |
| 2003 | state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone; |
| 2004 | state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve; |
| 2005 | } |
| 2006 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2007 | 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] | 2008 | 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] | 2009 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR); |
| 2010 | 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] | 2011 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props); |
| 2012 | 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] | 2013 | 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] | 2014 | 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] | 2015 | 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] | 2016 | 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] | 2017 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props); |
Nathaniel Cesario | 3291c91 | 2020-11-17 16:54:41 -0700 | [diff] [blame] | 2018 | 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] | 2019 | |
| 2020 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_timeline_semaphore) { |
| 2021 | VkPhysicalDeviceTimelineSemaphorePropertiesKHR timeline_semaphore_props; |
| 2022 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props); |
| 2023 | state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference = |
| 2024 | timeline_semaphore_props.maxTimelineSemaphoreValueDifference; |
| 2025 | } |
| 2026 | |
| 2027 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_shader_float_controls) { |
| 2028 | VkPhysicalDeviceFloatControlsPropertiesKHR float_controls_props; |
| 2029 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props); |
| 2030 | state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence; |
| 2031 | state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence; |
| 2032 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 = |
| 2033 | float_controls_props.shaderSignedZeroInfNanPreserveFloat16; |
| 2034 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 = |
| 2035 | float_controls_props.shaderSignedZeroInfNanPreserveFloat32; |
| 2036 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 = |
| 2037 | float_controls_props.shaderSignedZeroInfNanPreserveFloat64; |
| 2038 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16; |
| 2039 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32; |
| 2040 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64; |
| 2041 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16; |
| 2042 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32; |
| 2043 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64; |
| 2044 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16; |
| 2045 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32; |
| 2046 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64; |
| 2047 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16; |
| 2048 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32; |
| 2049 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64; |
| 2050 | } |
Mark Lobodzinski | e4a2b7f | 2019-12-20 12:51:30 -0700 | [diff] [blame] | 2051 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2052 | if (state_tracker->device_extensions.vk_nv_cooperative_matrix) { |
| 2053 | // Get the needed cooperative_matrix properties |
| 2054 | auto cooperative_matrix_props = lvl_init_struct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>(); |
| 2055 | auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2KHR>(&cooperative_matrix_props); |
| 2056 | instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2); |
| 2057 | state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props; |
| 2058 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2059 | uint32_t num_cooperative_matrix_properties = 0; |
| 2060 | instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL); |
| 2061 | state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2062 | lvl_init_struct<VkCooperativeMatrixPropertiesNV>()); |
| 2063 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2064 | instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2065 | state_tracker->cooperative_matrix_properties.data()); |
| 2066 | } |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2067 | 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] | 2068 | // Get the needed subgroup limits |
| 2069 | auto subgroup_prop = lvl_init_struct<VkPhysicalDeviceSubgroupProperties>(); |
| 2070 | auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2KHR>(&subgroup_prop); |
| 2071 | instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2); |
| 2072 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 2073 | state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize; |
| 2074 | state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages; |
| 2075 | state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations; |
| 2076 | state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2077 | } |
| 2078 | |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2079 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props); |
| 2080 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2081 | // Store queue family data |
| 2082 | if (pCreateInfo->pQueueCreateInfos != nullptr) { |
| 2083 | for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) { |
sfricke-samsung | 590ae1e | 2020-04-25 01:18:05 -0700 | [diff] [blame] | 2084 | const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2085 | state_tracker->queue_family_index_map.insert( |
sfricke-samsung | 590ae1e | 2020-04-25 01:18:05 -0700 | [diff] [blame] | 2086 | std::make_pair(queue_create_info.queueFamilyIndex, queue_create_info.queueCount)); |
| 2087 | state_tracker->queue_family_create_flags_map.insert( |
| 2088 | std::make_pair(queue_create_info.queueFamilyIndex, queue_create_info.flags)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2089 | } |
| 2090 | } |
| 2091 | } |
| 2092 | |
| 2093 | void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
| 2094 | if (!device) return; |
| 2095 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2096 | // Reset all command buffers before destroying them, to unlink object_bindings. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2097 | for (auto &command_buffer : commandBufferMap) { |
| 2098 | ResetCommandBufferState(command_buffer.first); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2099 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 2100 | pipelineMap.clear(); |
| 2101 | renderPassMap.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2102 | commandBufferMap.clear(); |
| 2103 | |
| 2104 | // This will also delete all sets in the pool & remove them from setMap |
| 2105 | DeleteDescriptorSetPools(); |
| 2106 | // All sets should be removed |
| 2107 | assert(setMap.empty()); |
| 2108 | descriptorSetLayoutMap.clear(); |
| 2109 | imageViewMap.clear(); |
| 2110 | imageMap.clear(); |
| 2111 | bufferViewMap.clear(); |
| 2112 | bufferMap.clear(); |
| 2113 | // Queues persist until device is destroyed |
| 2114 | queueMap.clear(); |
| 2115 | } |
| 2116 | |
| 2117 | // Loop through bound objects and increment their in_use counts. |
| 2118 | void ValidationStateTracker::IncrementBoundObjects(CMD_BUFFER_STATE const *cb_node) { |
| 2119 | for (auto obj : cb_node->object_bindings) { |
| 2120 | auto base_obj = GetStateStructPtrFromObject(obj); |
| 2121 | if (base_obj) { |
| 2122 | base_obj->in_use.fetch_add(1); |
| 2123 | } |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | // Track which resources are in-flight by atomically incrementing their "in_use" count |
| 2128 | void ValidationStateTracker::IncrementResources(CMD_BUFFER_STATE *cb_node) { |
| 2129 | cb_node->submitCount++; |
| 2130 | cb_node->in_use.fetch_add(1); |
| 2131 | |
| 2132 | // First Increment for all "generic" objects bound to cmd buffer, followed by special-case objects below |
| 2133 | IncrementBoundObjects(cb_node); |
| 2134 | // TODO : We should be able to remove the NULL look-up checks from the code below as long as |
| 2135 | // all the corresponding cases are verified to cause CB_INVALID state and the CB_INVALID state |
| 2136 | // should then be flagged prior to calling this function |
| 2137 | for (auto event : cb_node->writeEventsBeforeWait) { |
| 2138 | auto event_state = GetEventState(event); |
| 2139 | if (event_state) event_state->write_in_use++; |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | // Decrement in-use count for objects bound to command buffer |
| 2144 | void ValidationStateTracker::DecrementBoundResources(CMD_BUFFER_STATE const *cb_node) { |
| 2145 | BASE_NODE *base_obj = nullptr; |
| 2146 | for (auto obj : cb_node->object_bindings) { |
| 2147 | base_obj = GetStateStructPtrFromObject(obj); |
| 2148 | if (base_obj) { |
| 2149 | base_obj->in_use.fetch_sub(1); |
| 2150 | } |
| 2151 | } |
| 2152 | } |
| 2153 | |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2154 | void ValidationStateTracker::RetireWorkOnQueue(QUEUE_STATE *pQueue, uint64_t seq) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2155 | std::unordered_map<VkQueue, uint64_t> other_queue_seqs; |
| 2156 | std::unordered_map<VkSemaphore, uint64_t> timeline_semaphore_counters; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2157 | |
| 2158 | // Roll this queue forward, one submission at a time. |
| 2159 | while (pQueue->seq < seq) { |
| 2160 | auto &submission = pQueue->submissions.front(); |
| 2161 | |
| 2162 | for (auto &wait : submission.waitSemaphores) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2163 | auto semaphore_state = GetSemaphoreState(wait.semaphore); |
| 2164 | if (semaphore_state) { |
| 2165 | semaphore_state->in_use.fetch_sub(1); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2166 | } |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 2167 | if (wait.type == VK_SEMAPHORE_TYPE_TIMELINE_KHR) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2168 | auto &last_counter = timeline_semaphore_counters[wait.semaphore]; |
| 2169 | last_counter = std::max(last_counter, wait.payload); |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 2170 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2171 | auto &last_seq = other_queue_seqs[wait.queue]; |
| 2172 | last_seq = std::max(last_seq, wait.seq); |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 2173 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2174 | } |
| 2175 | |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 2176 | for (auto &signal : submission.signalSemaphores) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2177 | auto semaphore_state = GetSemaphoreState(signal.semaphore); |
| 2178 | if (semaphore_state) { |
| 2179 | semaphore_state->in_use.fetch_sub(1); |
| 2180 | if (semaphore_state->type == VK_SEMAPHORE_TYPE_TIMELINE_KHR && semaphore_state->payload < signal.payload) { |
| 2181 | semaphore_state->payload = signal.payload; |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 2182 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | for (auto &semaphore : submission.externalSemaphores) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2187 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2188 | if (semaphore_state) { |
| 2189 | semaphore_state->in_use.fetch_sub(1); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2190 | } |
| 2191 | } |
| 2192 | |
| 2193 | for (auto cb : submission.cbs) { |
| 2194 | auto cb_node = GetCBState(cb); |
| 2195 | if (!cb_node) { |
| 2196 | continue; |
| 2197 | } |
| 2198 | // First perform decrement on general case bound objects |
| 2199 | DecrementBoundResources(cb_node); |
| 2200 | for (auto event : cb_node->writeEventsBeforeWait) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2201 | auto event_node = eventMap.find(event); |
| 2202 | if (event_node != eventMap.end()) { |
| 2203 | event_node->second.write_in_use--; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2204 | } |
| 2205 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2206 | QueryMap local_query_to_state_map; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 2207 | VkQueryPool first_pool = VK_NULL_HANDLE; |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 2208 | for (auto &function : cb_node->queryUpdates) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2209 | 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] | 2210 | } |
| 2211 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2212 | for (auto query_state_pair : local_query_to_state_map) { |
| 2213 | if (query_state_pair.second == QUERYSTATE_ENDED) { |
| 2214 | queryToStateMap[query_state_pair.first] = QUERYSTATE_AVAILABLE; |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2215 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2216 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2217 | cb_node->in_use.fetch_sub(1); |
| 2218 | } |
| 2219 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2220 | auto fence_state = GetFenceState(submission.fence); |
| 2221 | if (fence_state && fence_state->scope == kSyncScopeInternal) { |
| 2222 | fence_state->state = FENCE_RETIRED; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | pQueue->submissions.pop_front(); |
| 2226 | pQueue->seq++; |
| 2227 | } |
| 2228 | |
| 2229 | // Roll other queues forward to the highest seq we saw a wait for |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2230 | for (auto qs : other_queue_seqs) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2231 | RetireWorkOnQueue(GetQueueState(qs.first), qs.second); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2232 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2233 | for (auto sc : timeline_semaphore_counters) { |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 2234 | RetireTimelineSemaphore(sc.first, sc.second); |
| 2235 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | // Submit a fence to a queue, delimiting previous fences and previous untracked |
| 2239 | // work by it. |
| 2240 | static void SubmitFence(QUEUE_STATE *pQueue, FENCE_STATE *pFence, uint64_t submitCount) { |
| 2241 | pFence->state = FENCE_INFLIGHT; |
| 2242 | pFence->signaler.first = pQueue->queue; |
| 2243 | pFence->signaler.second = pQueue->seq + pQueue->submissions.size() + submitCount; |
| 2244 | } |
| 2245 | |
| 2246 | void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, |
| 2247 | VkFence fence, VkResult result) { |
Mark Lobodzinski | 09379db | 2020-05-07 08:22:01 -0600 | [diff] [blame] | 2248 | if (result != VK_SUCCESS) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2249 | uint64_t early_retire_seq = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2250 | auto queue_state = GetQueueState(queue); |
| 2251 | auto fence_state = GetFenceState(fence); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2252 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2253 | if (fence_state) { |
| 2254 | if (fence_state->scope == kSyncScopeInternal) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2255 | // Mark fence in use |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2256 | SubmitFence(queue_state, fence_state, std::max(1u, submitCount)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2257 | if (!submitCount) { |
| 2258 | // If no submissions, but just dropping a fence on the end of the queue, |
| 2259 | // record an empty submission with just the fence, so we can determine |
| 2260 | // its completion. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2261 | queue_state->submissions.emplace_back(std::vector<VkCommandBuffer>(), std::vector<SEMAPHORE_WAIT>(), |
| 2262 | std::vector<SEMAPHORE_SIGNAL>(), std::vector<VkSemaphore>(), fence, 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2263 | } |
| 2264 | } else { |
| 2265 | // 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^] | 2266 | early_retire_seq = queue_state->seq + queue_state->submissions.size(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | // Now process each individual submit |
| 2271 | for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) { |
| 2272 | std::vector<VkCommandBuffer> cbs; |
| 2273 | const VkSubmitInfo *submit = &pSubmits[submit_idx]; |
Jeremy Gebben | 404e683 | 2020-09-29 14:58:07 -0600 | [diff] [blame] | 2274 | std::vector<SEMAPHORE_WAIT> semaphore_waits; |
| 2275 | std::vector<SEMAPHORE_SIGNAL> semaphore_signals; |
| 2276 | std::vector<VkSemaphore> semaphore_externals; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2277 | const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2278 | auto *timeline_semaphore_submit = lvl_find_in_chain<VkTimelineSemaphoreSubmitInfoKHR>(submit->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2279 | for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) { |
| 2280 | VkSemaphore semaphore = submit->pWaitSemaphores[i]; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2281 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2282 | if (semaphore_state) { |
| 2283 | if (semaphore_state->scope == kSyncScopeInternal) { |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 2284 | SEMAPHORE_WAIT wait; |
| 2285 | wait.semaphore = semaphore; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2286 | wait.type = semaphore_state->type; |
| 2287 | if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY_KHR) { |
| 2288 | if (semaphore_state->signaler.first != VK_NULL_HANDLE) { |
| 2289 | wait.queue = semaphore_state->signaler.first; |
| 2290 | wait.seq = semaphore_state->signaler.second; |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 2291 | semaphore_waits.push_back(wait); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2292 | semaphore_state->in_use.fetch_add(1); |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 2293 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2294 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
| 2295 | semaphore_state->signaled = false; |
| 2296 | } else if (semaphore_state->payload < timeline_semaphore_submit->pWaitSemaphoreValues[i]) { |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 2297 | wait.queue = queue; |
| 2298 | wait.seq = next_seq; |
| 2299 | wait.payload = timeline_semaphore_submit->pWaitSemaphoreValues[i]; |
| 2300 | semaphore_waits.push_back(wait); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2301 | semaphore_state->in_use.fetch_add(1); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2302 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2303 | } else { |
| 2304 | semaphore_externals.push_back(semaphore); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2305 | semaphore_state->in_use.fetch_add(1); |
| 2306 | if (semaphore_state->scope == kSyncScopeExternalTemporary) { |
| 2307 | semaphore_state->scope = kSyncScopeInternal; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2308 | } |
| 2309 | } |
| 2310 | } |
| 2311 | } |
| 2312 | for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) { |
| 2313 | VkSemaphore semaphore = submit->pSignalSemaphores[i]; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2314 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2315 | if (semaphore_state) { |
| 2316 | if (semaphore_state->scope == kSyncScopeInternal) { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2317 | SEMAPHORE_SIGNAL signal; |
| 2318 | signal.semaphore = semaphore; |
| 2319 | signal.seq = next_seq; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2320 | if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY_KHR) { |
| 2321 | semaphore_state->signaler.first = queue; |
| 2322 | semaphore_state->signaler.second = next_seq; |
| 2323 | semaphore_state->signaled = true; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2324 | } else { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2325 | signal.payload = timeline_semaphore_submit->pSignalSemaphoreValues[i]; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2326 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2327 | semaphore_state->in_use.fetch_add(1); |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2328 | semaphore_signals.push_back(signal); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2329 | } else { |
| 2330 | // Retire work up until this submit early, we will not see the wait that corresponds to this signal |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2331 | early_retire_seq = std::max(early_retire_seq, next_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | } |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 2335 | const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext); |
| 2336 | uint32_t perf_pass = perf_submit ? perf_submit->counterPassIndex : 0; |
| 2337 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2338 | for (uint32_t i = 0; i < submit->commandBufferCount; i++) { |
| 2339 | auto cb_node = GetCBState(submit->pCommandBuffers[i]); |
| 2340 | if (cb_node) { |
| 2341 | cbs.push_back(submit->pCommandBuffers[i]); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2342 | for (auto secondary_cmd_buffer : cb_node->linkedCommandBuffers) { |
| 2343 | cbs.push_back(secondary_cmd_buffer->commandBuffer); |
| 2344 | IncrementResources(secondary_cmd_buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2345 | } |
| 2346 | IncrementResources(cb_node); |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2347 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 2348 | VkQueryPool first_pool = VK_NULL_HANDLE; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2349 | EventToStageMap local_event_to_stage_map; |
| 2350 | QueryMap local_query_to_state_map; |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2351 | for (auto &function : cb_node->queryUpdates) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2352 | function(nullptr, /*do_validate*/ false, first_pool, perf_pass, &local_query_to_state_map); |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2353 | } |
| 2354 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2355 | for (auto query_state_pair : local_query_to_state_map) { |
| 2356 | queryToStateMap[query_state_pair.first] = query_state_pair.second; |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2357 | } |
| 2358 | |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2359 | for (auto &function : cb_node->eventUpdates) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2360 | function(nullptr, /*do_validate*/ false, &local_event_to_stage_map); |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2361 | } |
| 2362 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2363 | for (auto event_stage_pair : local_event_to_stage_map) { |
| 2364 | eventMap[event_stage_pair.first].stageMask = event_stage_pair.second; |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2365 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2366 | } |
| 2367 | } |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2368 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2369 | queue_state->submissions.emplace_back(cbs, semaphore_waits, semaphore_signals, semaphore_externals, |
| 2370 | submit_idx == submitCount - 1 ? fence : (VkFence)VK_NULL_HANDLE, perf_pass); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | if (early_retire_seq) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2374 | RetireWorkOnQueue(queue_state, early_retire_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, |
| 2379 | const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory, |
| 2380 | VkResult result) { |
| 2381 | if (VK_SUCCESS == result) { |
| 2382 | AddMemObjInfo(device, *pMemory, pAllocateInfo); |
| 2383 | } |
| 2384 | return; |
| 2385 | } |
| 2386 | |
| 2387 | void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) { |
| 2388 | if (!mem) return; |
| 2389 | DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem); |
| 2390 | const VulkanTypedHandle obj_struct(mem, kVulkanObjectTypeDeviceMemory); |
| 2391 | |
| 2392 | // Clear mem binding for any bound objects |
| 2393 | for (const auto &obj : mem_info->obj_bindings) { |
| 2394 | BINDABLE *bindable_state = nullptr; |
| 2395 | switch (obj.type) { |
| 2396 | case kVulkanObjectTypeImage: |
| 2397 | bindable_state = GetImageState(obj.Cast<VkImage>()); |
| 2398 | break; |
| 2399 | case kVulkanObjectTypeBuffer: |
| 2400 | bindable_state = GetBufferState(obj.Cast<VkBuffer>()); |
| 2401 | break; |
| 2402 | case kVulkanObjectTypeAccelerationStructureNV: |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2403 | bindable_state = GetAccelerationStructureStateNV(obj.Cast<VkAccelerationStructureNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2404 | break; |
| 2405 | |
| 2406 | default: |
| 2407 | // Should only have acceleration structure, buffer, or image objects bound to memory |
| 2408 | assert(0); |
| 2409 | } |
| 2410 | |
| 2411 | if (bindable_state) { |
Jeff Bolz | 41e2905 | 2020-03-29 22:33:55 -0500 | [diff] [blame] | 2412 | // Remove any sparse bindings bound to the resource that use this memory. |
| 2413 | for (auto it = bindable_state->sparse_bindings.begin(); it != bindable_state->sparse_bindings.end();) { |
| 2414 | auto nextit = it; |
| 2415 | nextit++; |
| 2416 | |
| 2417 | auto &sparse_mem_binding = *it; |
| 2418 | if (sparse_mem_binding.mem_state.get() == mem_info) { |
| 2419 | bindable_state->sparse_bindings.erase(it); |
| 2420 | } |
| 2421 | |
| 2422 | it = nextit; |
| 2423 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2424 | bindable_state->UpdateBoundMemorySet(); |
| 2425 | } |
| 2426 | } |
| 2427 | // Any bound cmd buffers are now invalid |
| 2428 | InvalidateCommandBuffers(mem_info->cb_bindings, obj_struct); |
| 2429 | RemoveAliasingImages(mem_info->bound_images); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2430 | mem_info->destroyed = true; |
John Zulauf | 7995271 | 2020-04-07 11:25:54 -0600 | [diff] [blame] | 2431 | fake_memory.Free(mem_info->fake_base_address); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2432 | memObjMap.erase(mem); |
| 2433 | } |
| 2434 | |
| 2435 | void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo, |
| 2436 | VkFence fence, VkResult result) { |
| 2437 | if (result != VK_SUCCESS) return; |
| 2438 | uint64_t early_retire_seq = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2439 | auto fence_state = GetFenceState(fence); |
| 2440 | auto queue_state = GetQueueState(queue); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2441 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2442 | if (fence_state) { |
| 2443 | if (fence_state->scope == kSyncScopeInternal) { |
| 2444 | SubmitFence(queue_state, fence_state, std::max(1u, bindInfoCount)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2445 | if (!bindInfoCount) { |
| 2446 | // No work to do, just dropping a fence in the queue by itself. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2447 | queue_state->submissions.emplace_back(std::vector<VkCommandBuffer>(), std::vector<SEMAPHORE_WAIT>(), |
| 2448 | std::vector<SEMAPHORE_SIGNAL>(), std::vector<VkSemaphore>(), fence, 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2449 | } |
| 2450 | } else { |
| 2451 | // 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^] | 2452 | early_retire_seq = queue_state->seq + queue_state->submissions.size(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2453 | } |
| 2454 | } |
| 2455 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2456 | for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) { |
| 2457 | const VkBindSparseInfo &bind_info = pBindInfo[bind_idx]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2458 | // Track objects tied to memory |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2459 | for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) { |
| 2460 | for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) { |
| 2461 | auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k]; |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 2462 | SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, sparse_binding.size, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2463 | VulkanTypedHandle(bind_info.pBufferBinds[j].buffer, kVulkanObjectTypeBuffer)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2464 | } |
| 2465 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2466 | for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) { |
| 2467 | for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) { |
| 2468 | auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k]; |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 2469 | SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, sparse_binding.size, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2470 | VulkanTypedHandle(bind_info.pImageOpaqueBinds[j].image, kVulkanObjectTypeImage)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2471 | } |
| 2472 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2473 | for (uint32_t j = 0; j < bind_info.imageBindCount; j++) { |
| 2474 | for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) { |
| 2475 | auto sparse_binding = bind_info.pImageBinds[j].pBinds[k]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2476 | // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data |
| 2477 | 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] | 2478 | SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, size, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2479 | VulkanTypedHandle(bind_info.pImageBinds[j].image, kVulkanObjectTypeImage)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | std::vector<SEMAPHORE_WAIT> semaphore_waits; |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2484 | std::vector<SEMAPHORE_SIGNAL> semaphore_signals; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2485 | std::vector<VkSemaphore> semaphore_externals; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2486 | for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) { |
| 2487 | VkSemaphore semaphore = bind_info.pWaitSemaphores[i]; |
| 2488 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2489 | if (semaphore_state) { |
| 2490 | if (semaphore_state->scope == kSyncScopeInternal) { |
| 2491 | if (semaphore_state->signaler.first != VK_NULL_HANDLE) { |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 2492 | semaphore_waits.push_back( |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2493 | {semaphore, semaphore_state->type, semaphore_state->signaler.first, semaphore_state->signaler.second}); |
| 2494 | semaphore_state->in_use.fetch_add(1); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2495 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2496 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
| 2497 | semaphore_state->signaled = false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2498 | } else { |
| 2499 | semaphore_externals.push_back(semaphore); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2500 | semaphore_state->in_use.fetch_add(1); |
| 2501 | if (semaphore_state->scope == kSyncScopeExternalTemporary) { |
| 2502 | semaphore_state->scope = kSyncScopeInternal; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2503 | } |
| 2504 | } |
| 2505 | } |
| 2506 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2507 | for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) { |
| 2508 | VkSemaphore semaphore = bind_info.pSignalSemaphores[i]; |
| 2509 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2510 | if (semaphore_state) { |
| 2511 | if (semaphore_state->scope == kSyncScopeInternal) { |
| 2512 | semaphore_state->signaler.first = queue; |
| 2513 | semaphore_state->signaler.second = queue_state->seq + queue_state->submissions.size() + 1; |
| 2514 | semaphore_state->signaled = true; |
| 2515 | semaphore_state->in_use.fetch_add(1); |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2516 | |
| 2517 | SEMAPHORE_SIGNAL signal; |
| 2518 | signal.semaphore = semaphore; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2519 | signal.seq = semaphore_state->signaler.second; |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2520 | semaphore_signals.push_back(signal); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2521 | } else { |
| 2522 | // Retire work up until this submit early, we will not see the wait that corresponds to this signal |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2523 | 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] | 2524 | } |
| 2525 | } |
| 2526 | } |
| 2527 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2528 | queue_state->submissions.emplace_back(std::vector<VkCommandBuffer>(), semaphore_waits, semaphore_signals, |
| 2529 | semaphore_externals, bind_idx == bindInfoCount - 1 ? fence : (VkFence)VK_NULL_HANDLE, |
| 2530 | 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | if (early_retire_seq) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2534 | RetireWorkOnQueue(queue_state, early_retire_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2535 | } |
| 2536 | } |
| 2537 | |
| 2538 | void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo, |
| 2539 | const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore, |
| 2540 | VkResult result) { |
| 2541 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2542 | auto semaphore_state = std::make_shared<SEMAPHORE_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2543 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
| 2544 | semaphore_state->signaler.second = 0; |
| 2545 | semaphore_state->signaled = false; |
| 2546 | semaphore_state->scope = kSyncScopeInternal; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2547 | semaphore_state->type = VK_SEMAPHORE_TYPE_BINARY_KHR; |
| 2548 | semaphore_state->payload = 0; |
| 2549 | auto semaphore_type_create_info = lvl_find_in_chain<VkSemaphoreTypeCreateInfoKHR>(pCreateInfo->pNext); |
| 2550 | if (semaphore_type_create_info) { |
| 2551 | semaphore_state->type = semaphore_type_create_info->semaphoreType; |
| 2552 | semaphore_state->payload = semaphore_type_create_info->initialValue; |
| 2553 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2554 | semaphoreMap[*pSemaphore] = std::move(semaphore_state); |
| 2555 | } |
| 2556 | |
| 2557 | void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBitsKHR handle_type, |
| 2558 | VkSemaphoreImportFlagsKHR flags) { |
| 2559 | SEMAPHORE_STATE *sema_node = GetSemaphoreState(semaphore); |
| 2560 | if (sema_node && sema_node->scope != kSyncScopeExternalPermanent) { |
| 2561 | if ((handle_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR || flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR) && |
| 2562 | sema_node->scope == kSyncScopeInternal) { |
| 2563 | sema_node->scope = kSyncScopeExternalTemporary; |
| 2564 | } else { |
| 2565 | sema_node->scope = kSyncScopeExternalPermanent; |
| 2566 | } |
| 2567 | } |
| 2568 | } |
| 2569 | |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2570 | void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfoKHR *pSignalInfo, |
| 2571 | VkResult result) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2572 | auto *semaphore_state = GetSemaphoreState(pSignalInfo->semaphore); |
| 2573 | semaphore_state->payload = pSignalInfo->value; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2576 | void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) { |
| 2577 | auto mem_info = GetDevMemState(mem); |
| 2578 | if (mem_info) { |
| 2579 | mem_info->mapped_range.offset = offset; |
| 2580 | mem_info->mapped_range.size = size; |
| 2581 | mem_info->p_driver_data = *ppData; |
| 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | void ValidationStateTracker::RetireFence(VkFence fence) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2586 | auto fence_state = GetFenceState(fence); |
| 2587 | if (fence_state && fence_state->scope == kSyncScopeInternal) { |
| 2588 | if (fence_state->signaler.first != VK_NULL_HANDLE) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2589 | // 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^] | 2590 | RetireWorkOnQueue(GetQueueState(fence_state->signaler.first), fence_state->signaler.second); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2591 | } else { |
| 2592 | // Fence signaller is the WSI. We're not tracking what the WSI op actually /was/ in CV yet, but we need to mark |
| 2593 | // the fence as retired. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2594 | fence_state->state = FENCE_RETIRED; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2595 | } |
| 2596 | } |
| 2597 | } |
| 2598 | |
| 2599 | void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, |
| 2600 | VkBool32 waitAll, uint64_t timeout, VkResult result) { |
| 2601 | if (VK_SUCCESS != result) return; |
| 2602 | |
| 2603 | // When we know that all fences are complete we can clean/remove their CBs |
| 2604 | if ((VK_TRUE == waitAll) || (1 == fenceCount)) { |
| 2605 | for (uint32_t i = 0; i < fenceCount; i++) { |
| 2606 | RetireFence(pFences[i]); |
| 2607 | } |
| 2608 | } |
| 2609 | // NOTE : Alternate case not handled here is when some fences have completed. In |
| 2610 | // this case for app to guarantee which fences completed it will have to call |
| 2611 | // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete. |
| 2612 | } |
| 2613 | |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2614 | void ValidationStateTracker::RetireTimelineSemaphore(VkSemaphore semaphore, uint64_t until_payload) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2615 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2616 | if (semaphore_state) { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2617 | for (auto &pair : queueMap) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2618 | QUEUE_STATE &queue_state = pair.second; |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2619 | uint64_t max_seq = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2620 | for (const auto &submission : queue_state.submissions) { |
| 2621 | for (const auto &signal_semaphore : submission.signalSemaphores) { |
| 2622 | if (signal_semaphore.semaphore == semaphore && signal_semaphore.payload <= until_payload) { |
| 2623 | if (signal_semaphore.seq > max_seq) { |
| 2624 | max_seq = signal_semaphore.seq; |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2625 | } |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2626 | } |
| 2627 | } |
| 2628 | } |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2629 | if (max_seq) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 2630 | RetireWorkOnQueue(&queue_state, max_seq); |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2631 | } |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2632 | } |
| 2633 | } |
| 2634 | } |
| 2635 | |
John Zulauf | f89de66 | 2020-04-13 18:57:34 -0600 | [diff] [blame] | 2636 | void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout, |
| 2637 | VkResult result) { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2638 | if (VK_SUCCESS != result) return; |
| 2639 | |
| 2640 | for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) { |
| 2641 | RetireTimelineSemaphore(pWaitInfo->pSemaphores[i], pWaitInfo->pValues[i]); |
| 2642 | } |
| 2643 | } |
| 2644 | |
John Zulauf | f89de66 | 2020-04-13 18:57:34 -0600 | [diff] [blame] | 2645 | void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout, |
| 2646 | VkResult result) { |
| 2647 | RecordWaitSemaphores(device, pWaitInfo, timeout, result); |
| 2648 | } |
| 2649 | |
| 2650 | void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, |
| 2651 | uint64_t timeout, VkResult result) { |
| 2652 | RecordWaitSemaphores(device, pWaitInfo, timeout, result); |
| 2653 | } |
| 2654 | |
Adrian Coca Lorente | c7d7610 | 2020-09-28 13:58:16 +0200 | [diff] [blame] | 2655 | void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 2656 | VkResult result) { |
| 2657 | if (VK_SUCCESS != result) return; |
| 2658 | |
| 2659 | RetireTimelineSemaphore(semaphore, *pValue); |
| 2660 | } |
| 2661 | |
| 2662 | void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 2663 | VkResult result) { |
| 2664 | RecordGetSemaphoreCounterValue(device, semaphore, pValue, result); |
| 2665 | } |
| 2666 | void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 2667 | VkResult result) { |
| 2668 | RecordGetSemaphoreCounterValue(device, semaphore, pValue, result); |
| 2669 | } |
| 2670 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2671 | void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) { |
| 2672 | if (VK_SUCCESS != result) return; |
| 2673 | RetireFence(fence); |
| 2674 | } |
| 2675 | |
| 2676 | void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkQueue queue) { |
| 2677 | // Add queue to tracking set only if it is new |
| 2678 | auto queue_is_new = queues.emplace(queue); |
| 2679 | if (queue_is_new.second == true) { |
| 2680 | QUEUE_STATE *queue_state = &queueMap[queue]; |
| 2681 | queue_state->queue = queue; |
| 2682 | queue_state->queueFamilyIndex = queue_family_index; |
| 2683 | queue_state->seq = 0; |
| 2684 | } |
| 2685 | } |
| 2686 | |
| 2687 | void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, |
| 2688 | VkQueue *pQueue) { |
| 2689 | RecordGetDeviceQueueState(queueFamilyIndex, *pQueue); |
| 2690 | } |
| 2691 | |
| 2692 | void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) { |
| 2693 | RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, *pQueue); |
| 2694 | } |
| 2695 | |
| 2696 | void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) { |
| 2697 | if (VK_SUCCESS != result) return; |
| 2698 | QUEUE_STATE *queue_state = GetQueueState(queue); |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2699 | RetireWorkOnQueue(queue_state, queue_state->seq + queue_state->submissions.size()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) { |
| 2703 | if (VK_SUCCESS != result) return; |
| 2704 | for (auto &queue : queueMap) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2705 | RetireWorkOnQueue(&queue.second, queue.second.seq + queue.second.submissions.size()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) { |
| 2710 | if (!fence) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2711 | auto fence_state = GetFenceState(fence); |
| 2712 | fence_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2713 | fenceMap.erase(fence); |
| 2714 | } |
| 2715 | |
| 2716 | void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore, |
| 2717 | const VkAllocationCallbacks *pAllocator) { |
| 2718 | if (!semaphore) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2719 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2720 | semaphore_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2721 | semaphoreMap.erase(semaphore); |
| 2722 | } |
| 2723 | |
| 2724 | void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 2725 | if (!event) return; |
| 2726 | EVENT_STATE *event_state = GetEventState(event); |
| 2727 | const VulkanTypedHandle obj_struct(event, kVulkanObjectTypeEvent); |
| 2728 | InvalidateCommandBuffers(event_state->cb_bindings, obj_struct); |
| 2729 | eventMap.erase(event); |
| 2730 | } |
| 2731 | |
| 2732 | void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool, |
| 2733 | const VkAllocationCallbacks *pAllocator) { |
| 2734 | if (!queryPool) return; |
| 2735 | QUERY_POOL_STATE *qp_state = GetQueryPoolState(queryPool); |
| 2736 | const VulkanTypedHandle obj_struct(queryPool, kVulkanObjectTypeQueryPool); |
| 2737 | InvalidateCommandBuffers(qp_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2738 | qp_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2739 | queryPoolMap.erase(queryPool); |
| 2740 | } |
| 2741 | |
| 2742 | // Object with given handle is being bound to memory w/ given mem_info struct. |
| 2743 | // Track the newly bound memory range with given memoryOffset |
| 2744 | // Also scan any previous ranges, track aliased ranges with new range, and flag an error if a linear |
| 2745 | // and non-linear range incorrectly overlap. |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2746 | void ValidationStateTracker::InsertMemoryRange(const VulkanTypedHandle &typed_handle, DEVICE_MEMORY_STATE *mem_info, |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2747 | VkDeviceSize memoryOffset) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2748 | if (typed_handle.type == kVulkanObjectTypeImage) { |
| 2749 | mem_info->bound_images.insert(typed_handle.Cast<VkImage>()); |
| 2750 | } else if (typed_handle.type == kVulkanObjectTypeBuffer) { |
locke-lunarg | 37c410a | 2020-02-17 17:34:13 -0700 | [diff] [blame] | 2751 | mem_info->bound_buffers.insert(typed_handle.Cast<VkBuffer>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2752 | } else if (typed_handle.type == kVulkanObjectTypeAccelerationStructureNV) { |
locke-lunarg | 37c410a | 2020-02-17 17:34:13 -0700 | [diff] [blame] | 2753 | mem_info->bound_acceleration_structures.insert(typed_handle.Cast<VkAccelerationStructureNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2754 | } else { |
| 2755 | // Unsupported object type |
| 2756 | assert(false); |
| 2757 | } |
| 2758 | } |
| 2759 | |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2760 | void ValidationStateTracker::InsertImageMemoryRange(VkImage image, DEVICE_MEMORY_STATE *mem_info, VkDeviceSize mem_offset) { |
| 2761 | InsertMemoryRange(VulkanTypedHandle(image, kVulkanObjectTypeImage), mem_info, mem_offset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2762 | } |
| 2763 | |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2764 | void ValidationStateTracker::InsertBufferMemoryRange(VkBuffer buffer, DEVICE_MEMORY_STATE *mem_info, VkDeviceSize mem_offset) { |
| 2765 | InsertMemoryRange(VulkanTypedHandle(buffer, kVulkanObjectTypeBuffer), mem_info, mem_offset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | void ValidationStateTracker::InsertAccelerationStructureMemoryRange(VkAccelerationStructureNV as, DEVICE_MEMORY_STATE *mem_info, |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2769 | VkDeviceSize mem_offset) { |
| 2770 | InsertMemoryRange(VulkanTypedHandle(as, kVulkanObjectTypeAccelerationStructureNV), mem_info, mem_offset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | // This function will remove the handle-to-index mapping from the appropriate map. |
| 2774 | static void RemoveMemoryRange(const VulkanTypedHandle &typed_handle, DEVICE_MEMORY_STATE *mem_info) { |
| 2775 | if (typed_handle.type == kVulkanObjectTypeImage) { |
| 2776 | mem_info->bound_images.erase(typed_handle.Cast<VkImage>()); |
| 2777 | } else if (typed_handle.type == kVulkanObjectTypeBuffer) { |
locke-lunarg | 37c410a | 2020-02-17 17:34:13 -0700 | [diff] [blame] | 2778 | mem_info->bound_buffers.erase(typed_handle.Cast<VkBuffer>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2779 | } else if (typed_handle.type == kVulkanObjectTypeAccelerationStructureNV) { |
locke-lunarg | 37c410a | 2020-02-17 17:34:13 -0700 | [diff] [blame] | 2780 | mem_info->bound_acceleration_structures.erase(typed_handle.Cast<VkAccelerationStructureNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2781 | } else { |
| 2782 | // Unsupported object type |
| 2783 | assert(false); |
| 2784 | } |
| 2785 | } |
| 2786 | |
| 2787 | void ValidationStateTracker::RemoveBufferMemoryRange(VkBuffer buffer, DEVICE_MEMORY_STATE *mem_info) { |
| 2788 | RemoveMemoryRange(VulkanTypedHandle(buffer, kVulkanObjectTypeBuffer), mem_info); |
| 2789 | } |
| 2790 | |
| 2791 | void ValidationStateTracker::RemoveImageMemoryRange(VkImage image, DEVICE_MEMORY_STATE *mem_info) { |
| 2792 | RemoveMemoryRange(VulkanTypedHandle(image, kVulkanObjectTypeImage), mem_info); |
| 2793 | } |
| 2794 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2795 | void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) { |
| 2796 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 2797 | if (buffer_state) { |
| 2798 | // Track bound memory range information |
| 2799 | auto mem_info = GetDevMemState(mem); |
| 2800 | if (mem_info) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2801 | InsertBufferMemoryRange(buffer, mem_info, memoryOffset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2802 | } |
| 2803 | // Track objects tied to memory |
| 2804 | SetMemBinding(mem, buffer_state, memoryOffset, VulkanTypedHandle(buffer, kVulkanObjectTypeBuffer)); |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem, |
| 2809 | VkDeviceSize memoryOffset, VkResult result) { |
| 2810 | if (VK_SUCCESS != result) return; |
| 2811 | UpdateBindBufferMemoryState(buffer, mem, memoryOffset); |
| 2812 | } |
| 2813 | |
| 2814 | void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
| 2815 | const VkBindBufferMemoryInfoKHR *pBindInfos, VkResult result) { |
| 2816 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 2817 | UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset); |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
| 2822 | const VkBindBufferMemoryInfoKHR *pBindInfos, VkResult result) { |
| 2823 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 2824 | UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset); |
| 2825 | } |
| 2826 | } |
| 2827 | |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2828 | void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2829 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 2830 | if (buffer_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2831 | buffer_state->memory_requirements_checked = true; |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer, |
| 2836 | VkMemoryRequirements *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2837 | RecordGetBufferMemoryRequirementsState(buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device, |
| 2841 | const VkBufferMemoryRequirementsInfo2KHR *pInfo, |
| 2842 | VkMemoryRequirements2KHR *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2843 | RecordGetBufferMemoryRequirementsState(pInfo->buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device, |
| 2847 | const VkBufferMemoryRequirementsInfo2KHR *pInfo, |
| 2848 | VkMemoryRequirements2KHR *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2849 | RecordGetBufferMemoryRequirementsState(pInfo->buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2850 | } |
| 2851 | |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2852 | void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2853 | const VkImagePlaneMemoryRequirementsInfo *plane_info = |
| 2854 | (pInfo == nullptr) ? nullptr : lvl_find_in_chain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2855 | IMAGE_STATE *image_state = GetImageState(image); |
| 2856 | if (image_state) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2857 | if (plane_info != nullptr) { |
| 2858 | // Multi-plane image |
| 2859 | image_state->memory_requirements_checked = false; // Each image plane needs to be checked itself |
| 2860 | if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) { |
| 2861 | image_state->plane0_memory_requirements_checked = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2862 | } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) { |
| 2863 | image_state->plane1_memory_requirements_checked = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2864 | } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) { |
| 2865 | image_state->plane2_memory_requirements_checked = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2866 | } |
| 2867 | } else { |
| 2868 | // Single Plane image |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2869 | image_state->memory_requirements_checked = true; |
| 2870 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image, |
| 2875 | VkMemoryRequirements *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2876 | RecordGetImageMemoryRequirementsState(image, nullptr); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo, |
| 2880 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2881 | RecordGetImageMemoryRequirementsState(pInfo->image, pInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device, |
| 2885 | const VkImageMemoryRequirementsInfo2 *pInfo, |
| 2886 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2887 | RecordGetImageMemoryRequirementsState(pInfo->image, pInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | static void RecordGetImageSparseMemoryRequirementsState(IMAGE_STATE *image_state, |
| 2891 | VkSparseImageMemoryRequirements *sparse_image_memory_requirements) { |
| 2892 | image_state->sparse_requirements.emplace_back(*sparse_image_memory_requirements); |
| 2893 | if (sparse_image_memory_requirements->formatProperties.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 2894 | image_state->sparse_metadata_required = true; |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements( |
| 2899 | VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount, |
| 2900 | VkSparseImageMemoryRequirements *pSparseMemoryRequirements) { |
| 2901 | auto image_state = GetImageState(image); |
| 2902 | image_state->get_sparse_reqs_called = true; |
| 2903 | if (!pSparseMemoryRequirements) return; |
| 2904 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2905 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i]); |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2( |
| 2910 | VkDevice device, const VkImageSparseMemoryRequirementsInfo2KHR *pInfo, uint32_t *pSparseMemoryRequirementCount, |
| 2911 | VkSparseImageMemoryRequirements2KHR *pSparseMemoryRequirements) { |
| 2912 | auto image_state = GetImageState(pInfo->image); |
| 2913 | image_state->get_sparse_reqs_called = true; |
| 2914 | if (!pSparseMemoryRequirements) return; |
| 2915 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2916 | assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it |
| 2917 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements); |
| 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR( |
| 2922 | VkDevice device, const VkImageSparseMemoryRequirementsInfo2KHR *pInfo, uint32_t *pSparseMemoryRequirementCount, |
| 2923 | VkSparseImageMemoryRequirements2KHR *pSparseMemoryRequirements) { |
| 2924 | auto image_state = GetImageState(pInfo->image); |
| 2925 | image_state->get_sparse_reqs_called = true; |
| 2926 | if (!pSparseMemoryRequirements) return; |
| 2927 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2928 | assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it |
| 2929 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements); |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, |
| 2934 | const VkAllocationCallbacks *pAllocator) { |
| 2935 | if (!shaderModule) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2936 | auto shader_module_state = GetShaderModuleState(shaderModule); |
| 2937 | shader_module_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2938 | shaderModuleMap.erase(shaderModule); |
| 2939 | } |
| 2940 | |
| 2941 | void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline, |
| 2942 | const VkAllocationCallbacks *pAllocator) { |
| 2943 | if (!pipeline) return; |
| 2944 | PIPELINE_STATE *pipeline_state = GetPipelineState(pipeline); |
| 2945 | const VulkanTypedHandle obj_struct(pipeline, kVulkanObjectTypePipeline); |
| 2946 | // Any bound cmd buffers are now invalid |
| 2947 | InvalidateCommandBuffers(pipeline_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2948 | pipeline_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2949 | pipelineMap.erase(pipeline); |
| 2950 | } |
| 2951 | |
| 2952 | void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, |
| 2953 | const VkAllocationCallbacks *pAllocator) { |
| 2954 | if (!pipelineLayout) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2955 | auto pipeline_layout_state = GetPipelineLayout(pipelineLayout); |
| 2956 | pipeline_layout_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2957 | pipelineLayoutMap.erase(pipelineLayout); |
| 2958 | } |
| 2959 | |
| 2960 | void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler, |
| 2961 | const VkAllocationCallbacks *pAllocator) { |
| 2962 | if (!sampler) return; |
| 2963 | SAMPLER_STATE *sampler_state = GetSamplerState(sampler); |
| 2964 | const VulkanTypedHandle obj_struct(sampler, kVulkanObjectTypeSampler); |
| 2965 | // Any bound cmd buffers are now invalid |
| 2966 | if (sampler_state) { |
| 2967 | InvalidateCommandBuffers(sampler_state->cb_bindings, obj_struct); |
Yuly Novikov | 424cdd5 | 2020-05-26 16:45:12 -0400 | [diff] [blame] | 2968 | |
| 2969 | if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT || |
| 2970 | sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) { |
| 2971 | custom_border_color_sampler_count--; |
| 2972 | } |
| 2973 | |
| 2974 | sampler_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2975 | } |
| 2976 | samplerMap.erase(sampler); |
| 2977 | } |
| 2978 | |
| 2979 | void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, |
| 2980 | const VkAllocationCallbacks *pAllocator) { |
| 2981 | if (!descriptorSetLayout) return; |
| 2982 | auto layout_it = descriptorSetLayoutMap.find(descriptorSetLayout); |
| 2983 | if (layout_it != descriptorSetLayoutMap.end()) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 2984 | layout_it->second.get()->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2985 | descriptorSetLayoutMap.erase(layout_it); |
| 2986 | } |
| 2987 | } |
| 2988 | |
| 2989 | void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, |
| 2990 | const VkAllocationCallbacks *pAllocator) { |
| 2991 | if (!descriptorPool) return; |
| 2992 | DESCRIPTOR_POOL_STATE *desc_pool_state = GetDescriptorPoolState(descriptorPool); |
| 2993 | const VulkanTypedHandle obj_struct(descriptorPool, kVulkanObjectTypeDescriptorPool); |
| 2994 | if (desc_pool_state) { |
| 2995 | // Any bound cmd buffers are now invalid |
| 2996 | InvalidateCommandBuffers(desc_pool_state->cb_bindings, obj_struct); |
| 2997 | // Free sets that were in this pool |
| 2998 | for (auto ds : desc_pool_state->sets) { |
| 2999 | FreeDescriptorSet(ds); |
| 3000 | } |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3001 | desc_pool_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3002 | descriptorPoolMap.erase(descriptorPool); |
| 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | // Free all command buffers in given list, removing all references/links to them using ResetCommandBufferState |
| 3007 | void ValidationStateTracker::FreeCommandBufferStates(COMMAND_POOL_STATE *pool_state, const uint32_t command_buffer_count, |
| 3008 | const VkCommandBuffer *command_buffers) { |
| 3009 | for (uint32_t i = 0; i < command_buffer_count; i++) { |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 3010 | // Allow any derived class to clean up command buffer state |
| 3011 | if (command_buffer_free_callback) { |
| 3012 | (*command_buffer_free_callback)(command_buffers[i]); |
| 3013 | } |
| 3014 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3015 | auto cb_state = GetCBState(command_buffers[i]); |
| 3016 | // Remove references to command buffer's state and delete |
| 3017 | if (cb_state) { |
| 3018 | // reset prior to delete, removing various references to it. |
| 3019 | // TODO: fix this, it's insane. |
| 3020 | ResetCommandBufferState(cb_state->commandBuffer); |
| 3021 | // Remove the cb_state's references from COMMAND_POOL_STATEs |
| 3022 | pool_state->commandBuffers.erase(command_buffers[i]); |
| 3023 | // Remove the cb debug labels |
| 3024 | EraseCmdDebugUtilsLabel(report_data, cb_state->commandBuffer); |
| 3025 | // Remove CBState from CB map |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3026 | cb_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3027 | commandBufferMap.erase(cb_state->commandBuffer); |
| 3028 | } |
| 3029 | } |
| 3030 | } |
| 3031 | |
| 3032 | void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, |
| 3033 | uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3034 | auto pool = GetCommandPoolState(commandPool); |
| 3035 | FreeCommandBufferStates(pool, commandBufferCount, pCommandBuffers); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo, |
| 3039 | const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool, |
| 3040 | VkResult result) { |
| 3041 | if (VK_SUCCESS != result) return; |
sfricke-samsung | c154337 | 2020-08-18 22:37:27 -0700 | [diff] [blame] | 3042 | VkCommandPool command_pool = *pCommandPool; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3043 | auto cmd_pool_state = std::make_shared<COMMAND_POOL_STATE>(); |
sfricke-samsung | c154337 | 2020-08-18 22:37:27 -0700 | [diff] [blame] | 3044 | cmd_pool_state->commandPool = command_pool; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3045 | cmd_pool_state->createFlags = pCreateInfo->flags; |
| 3046 | cmd_pool_state->queueFamilyIndex = pCreateInfo->queueFamilyIndex; |
sfricke-samsung | 0c45edc | 2020-07-01 22:19:53 -0700 | [diff] [blame] | 3047 | 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] | 3048 | commandPoolMap[command_pool] = std::move(cmd_pool_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo, |
| 3052 | const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool, |
| 3053 | VkResult result) { |
| 3054 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3055 | auto query_pool_state = std::make_shared<QUERY_POOL_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3056 | query_pool_state->createInfo = *pCreateInfo; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3057 | query_pool_state->pool = *pQueryPool; |
| 3058 | if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) { |
| 3059 | const auto *perf = lvl_find_in_chain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext); |
Mark Lobodzinski | 7e948e4 | 2020-09-09 10:23:36 -0600 | [diff] [blame] | 3060 | query_pool_state->perf_counter_index_count = perf->counterIndexCount; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3061 | |
Mark Lobodzinski | 7e948e4 | 2020-09-09 10:23:36 -0600 | [diff] [blame] | 3062 | 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] | 3063 | for (uint32_t i = 0; i < perf->counterIndexCount; i++) { |
| 3064 | const auto &counter = counters.counters[perf->pCounterIndices[i]]; |
| 3065 | switch (counter.scope) { |
| 3066 | case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR: |
| 3067 | query_pool_state->has_perf_scope_command_buffer = true; |
| 3068 | break; |
| 3069 | case VK_QUERY_SCOPE_RENDER_PASS_KHR: |
| 3070 | query_pool_state->has_perf_scope_render_pass = true; |
| 3071 | break; |
| 3072 | default: |
| 3073 | break; |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->phys_device, perf, |
| 3078 | &query_pool_state->n_performance_passes); |
| 3079 | } |
| 3080 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3081 | queryPoolMap[*pQueryPool] = std::move(query_pool_state); |
| 3082 | |
| 3083 | QueryObject query_obj{*pQueryPool, 0u}; |
| 3084 | for (uint32_t i = 0; i < pCreateInfo->queryCount; ++i) { |
| 3085 | query_obj.query = i; |
| 3086 | queryToStateMap[query_obj] = QUERYSTATE_UNKNOWN; |
| 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool, |
| 3091 | const VkAllocationCallbacks *pAllocator) { |
| 3092 | if (!commandPool) return; |
| 3093 | COMMAND_POOL_STATE *cp_state = GetCommandPoolState(commandPool); |
| 3094 | // Remove cmdpool from cmdpoolmap, after freeing layer data for the command buffers |
| 3095 | // "When a pool is destroyed, all command buffers allocated from the pool are freed." |
| 3096 | if (cp_state) { |
| 3097 | // Create a vector, as FreeCommandBufferStates deletes from cp_state->commandBuffers during iteration. |
| 3098 | std::vector<VkCommandBuffer> cb_vec{cp_state->commandBuffers.begin(), cp_state->commandBuffers.end()}; |
| 3099 | 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] | 3100 | cp_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3101 | commandPoolMap.erase(commandPool); |
| 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool, |
| 3106 | VkCommandPoolResetFlags flags, VkResult result) { |
| 3107 | if (VK_SUCCESS != result) return; |
| 3108 | // Reset all of the CBs allocated from this pool |
| 3109 | auto command_pool_state = GetCommandPoolState(commandPool); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3110 | for (auto cmd_buffer : command_pool_state->commandBuffers) { |
| 3111 | ResetCommandBufferState(cmd_buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, |
| 3116 | VkResult result) { |
| 3117 | for (uint32_t i = 0; i < fenceCount; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3118 | auto fence_state = GetFenceState(pFences[i]); |
| 3119 | if (fence_state) { |
| 3120 | if (fence_state->scope == kSyncScopeInternal) { |
| 3121 | fence_state->state = FENCE_UNSIGNALED; |
| 3122 | } else if (fence_state->scope == kSyncScopeExternalTemporary) { |
| 3123 | fence_state->scope = kSyncScopeInternal; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3124 | } |
| 3125 | } |
| 3126 | } |
| 3127 | } |
| 3128 | |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3129 | // For given cb_nodes, invalidate them and track object causing invalidation. |
| 3130 | // InvalidateCommandBuffers and InvalidateLinkedCommandBuffers are essentially |
| 3131 | // the same, except one takes a map and one takes a set, and InvalidateCommandBuffers |
| 3132 | // can also unlink objects from command buffers. |
| 3133 | void ValidationStateTracker::InvalidateCommandBuffers(small_unordered_map<CMD_BUFFER_STATE *, int, 8> &cb_nodes, |
| 3134 | const VulkanTypedHandle &obj, bool unlink) { |
| 3135 | for (const auto &cb_node_pair : cb_nodes) { |
| 3136 | auto &cb_node = cb_node_pair.first; |
| 3137 | if (cb_node->state == CB_RECORDING) { |
| 3138 | cb_node->state = CB_INVALID_INCOMPLETE; |
| 3139 | } else if (cb_node->state == CB_RECORDED) { |
| 3140 | cb_node->state = CB_INVALID_COMPLETE; |
| 3141 | } |
| 3142 | cb_node->broken_bindings.push_back(obj); |
| 3143 | |
| 3144 | // if secondary, then propagate the invalidation to the primaries that will call us. |
| 3145 | if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
| 3146 | InvalidateLinkedCommandBuffers(cb_node->linkedCommandBuffers, obj); |
| 3147 | } |
| 3148 | if (unlink) { |
| 3149 | int index = cb_node_pair.second; |
| 3150 | assert(cb_node->object_bindings[index] == obj); |
| 3151 | cb_node->object_bindings[index] = VulkanTypedHandle(); |
| 3152 | } |
| 3153 | } |
| 3154 | if (unlink) { |
| 3155 | cb_nodes.clear(); |
| 3156 | } |
| 3157 | } |
| 3158 | |
| 3159 | void ValidationStateTracker::InvalidateLinkedCommandBuffers(std::unordered_set<CMD_BUFFER_STATE *> &cb_nodes, |
| 3160 | const VulkanTypedHandle &obj) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3161 | for (auto cb_node : cb_nodes) { |
| 3162 | if (cb_node->state == CB_RECORDING) { |
| 3163 | cb_node->state = CB_INVALID_INCOMPLETE; |
| 3164 | } else if (cb_node->state == CB_RECORDED) { |
| 3165 | cb_node->state = CB_INVALID_COMPLETE; |
| 3166 | } |
| 3167 | cb_node->broken_bindings.push_back(obj); |
| 3168 | |
| 3169 | // if secondary, then propagate the invalidation to the primaries that will call us. |
| 3170 | if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3171 | InvalidateLinkedCommandBuffers(cb_node->linkedCommandBuffers, obj); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3172 | } |
| 3173 | } |
| 3174 | } |
| 3175 | |
| 3176 | void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, |
| 3177 | const VkAllocationCallbacks *pAllocator) { |
| 3178 | if (!framebuffer) return; |
| 3179 | FRAMEBUFFER_STATE *framebuffer_state = GetFramebufferState(framebuffer); |
| 3180 | const VulkanTypedHandle obj_struct(framebuffer, kVulkanObjectTypeFramebuffer); |
| 3181 | InvalidateCommandBuffers(framebuffer_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3182 | framebuffer_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3183 | frameBufferMap.erase(framebuffer); |
| 3184 | } |
| 3185 | |
| 3186 | void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass, |
| 3187 | const VkAllocationCallbacks *pAllocator) { |
| 3188 | if (!renderPass) return; |
| 3189 | RENDER_PASS_STATE *rp_state = GetRenderPassState(renderPass); |
| 3190 | const VulkanTypedHandle obj_struct(renderPass, kVulkanObjectTypeRenderPass); |
| 3191 | InvalidateCommandBuffers(rp_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3192 | rp_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3193 | renderPassMap.erase(renderPass); |
| 3194 | } |
| 3195 | |
| 3196 | void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo, |
| 3197 | const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) { |
| 3198 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3199 | auto fence_state = std::make_shared<FENCE_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3200 | fence_state->fence = *pFence; |
| 3201 | fence_state->createInfo = *pCreateInfo; |
| 3202 | fence_state->state = (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) ? FENCE_RETIRED : FENCE_UNSIGNALED; |
| 3203 | fenceMap[*pFence] = std::move(fence_state); |
| 3204 | } |
| 3205 | |
| 3206 | bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 3207 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 3208 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3209 | void *cgpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3210 | // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use. |
| 3211 | create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data); |
| 3212 | cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis |
| 3213 | cgpl_state->pipe_state.reserve(count); |
| 3214 | for (uint32_t i = 0; i < count; i++) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3215 | cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 3216 | (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] | 3217 | (cgpl_state->pipe_state)[i]->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3218 | } |
| 3219 | return false; |
| 3220 | } |
| 3221 | |
| 3222 | void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 3223 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 3224 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 3225 | VkResult result, void *cgpl_state_data) { |
| 3226 | create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data); |
| 3227 | // This API may create pipelines regardless of the return value |
| 3228 | for (uint32_t i = 0; i < count; i++) { |
| 3229 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3230 | (cgpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3231 | pipelineMap[pPipelines[i]] = std::move((cgpl_state->pipe_state)[i]); |
| 3232 | } |
| 3233 | } |
| 3234 | cgpl_state->pipe_state.clear(); |
| 3235 | } |
| 3236 | |
| 3237 | bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 3238 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 3239 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3240 | void *ccpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3241 | auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data); |
| 3242 | ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis |
| 3243 | ccpl_state->pipe_state.reserve(count); |
| 3244 | for (uint32_t i = 0; i < count; i++) { |
| 3245 | // Create and initialize internal tracking data structure |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3246 | ccpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3247 | ccpl_state->pipe_state.back()->initComputePipeline(this, &pCreateInfos[i]); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3248 | ccpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3249 | } |
| 3250 | return false; |
| 3251 | } |
| 3252 | |
| 3253 | void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 3254 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 3255 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 3256 | VkResult result, void *ccpl_state_data) { |
| 3257 | create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data); |
| 3258 | |
| 3259 | // This API may create pipelines regardless of the return value |
| 3260 | for (uint32_t i = 0; i < count; i++) { |
| 3261 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3262 | (ccpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3263 | pipelineMap[pPipelines[i]] = std::move((ccpl_state->pipe_state)[i]); |
| 3264 | } |
| 3265 | } |
| 3266 | ccpl_state->pipe_state.clear(); |
| 3267 | } |
| 3268 | |
| 3269 | bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, |
| 3270 | uint32_t count, |
| 3271 | const VkRayTracingPipelineCreateInfoNV *pCreateInfos, |
| 3272 | const VkAllocationCallbacks *pAllocator, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3273 | VkPipeline *pPipelines, void *crtpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3274 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data); |
| 3275 | crtpl_state->pipe_state.reserve(count); |
| 3276 | for (uint32_t i = 0; i < count; i++) { |
| 3277 | // Create and initialize internal tracking data structure |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3278 | crtpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 3279 | crtpl_state->pipe_state.back()->initRayTracingPipeline(this, &pCreateInfos[i]); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3280 | crtpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3281 | } |
| 3282 | return false; |
| 3283 | } |
| 3284 | |
| 3285 | void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV( |
| 3286 | VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos, |
| 3287 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) { |
| 3288 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data); |
| 3289 | // This API may create pipelines regardless of the return value |
| 3290 | for (uint32_t i = 0; i < count; i++) { |
| 3291 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3292 | (crtpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3293 | pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]); |
| 3294 | } |
| 3295 | } |
| 3296 | crtpl_state->pipe_state.clear(); |
| 3297 | } |
| 3298 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3299 | bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation, |
| 3300 | VkPipelineCache pipelineCache, uint32_t count, |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 3301 | const VkRayTracingPipelineCreateInfoKHR *pCreateInfos, |
| 3302 | const VkAllocationCallbacks *pAllocator, |
| 3303 | VkPipeline *pPipelines, void *crtpl_state_data) const { |
| 3304 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
| 3305 | crtpl_state->pipe_state.reserve(count); |
| 3306 | for (uint32_t i = 0; i < count; i++) { |
| 3307 | // Create and initialize internal tracking data structure |
| 3308 | crtpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
| 3309 | crtpl_state->pipe_state.back()->initRayTracingPipeline(this, &pCreateInfos[i]); |
| 3310 | crtpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
| 3311 | } |
| 3312 | return false; |
| 3313 | } |
| 3314 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3315 | void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation, |
| 3316 | VkPipelineCache pipelineCache, uint32_t count, |
| 3317 | const VkRayTracingPipelineCreateInfoKHR *pCreateInfos, |
| 3318 | const VkAllocationCallbacks *pAllocator, |
| 3319 | VkPipeline *pPipelines, VkResult result, |
| 3320 | void *crtpl_state_data) { |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 3321 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
| 3322 | // This API may create pipelines regardless of the return value |
| 3323 | for (uint32_t i = 0; i < count; i++) { |
| 3324 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3325 | (crtpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3326 | pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]); |
| 3327 | } |
| 3328 | } |
| 3329 | crtpl_state->pipe_state.clear(); |
| 3330 | } |
| 3331 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3332 | void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, |
| 3333 | const VkAllocationCallbacks *pAllocator, VkSampler *pSampler, |
| 3334 | VkResult result) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3335 | samplerMap[*pSampler] = std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3336 | if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT || |
| 3337 | pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) { |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 3338 | custom_border_color_sampler_count++; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3339 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device, |
| 3343 | const VkDescriptorSetLayoutCreateInfo *pCreateInfo, |
| 3344 | const VkAllocationCallbacks *pAllocator, |
| 3345 | VkDescriptorSetLayout *pSetLayout, VkResult result) { |
| 3346 | if (VK_SUCCESS != result) return; |
| 3347 | descriptorSetLayoutMap[*pSetLayout] = std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout); |
| 3348 | } |
| 3349 | |
| 3350 | // For repeatable sorting, not very useful for "memory in range" search |
| 3351 | struct PushConstantRangeCompare { |
| 3352 | bool operator()(const VkPushConstantRange *lhs, const VkPushConstantRange *rhs) const { |
| 3353 | if (lhs->offset == rhs->offset) { |
| 3354 | if (lhs->size == rhs->size) { |
| 3355 | // The comparison is arbitrary, but avoids false aliasing by comparing all fields. |
| 3356 | return lhs->stageFlags < rhs->stageFlags; |
| 3357 | } |
| 3358 | // If the offsets are the same then sorting by the end of range is useful for validation |
| 3359 | return lhs->size < rhs->size; |
| 3360 | } |
| 3361 | return lhs->offset < rhs->offset; |
| 3362 | } |
| 3363 | }; |
| 3364 | |
| 3365 | static PushConstantRangesDict push_constant_ranges_dict; |
| 3366 | |
| 3367 | PushConstantRangesId GetCanonicalId(const VkPipelineLayoutCreateInfo *info) { |
| 3368 | if (!info->pPushConstantRanges) { |
| 3369 | // Hand back the empty entry (creating as needed)... |
| 3370 | return push_constant_ranges_dict.look_up(PushConstantRanges()); |
| 3371 | } |
| 3372 | |
| 3373 | // Sort the input ranges to ensure equivalent ranges map to the same id |
| 3374 | std::set<const VkPushConstantRange *, PushConstantRangeCompare> sorted; |
| 3375 | for (uint32_t i = 0; i < info->pushConstantRangeCount; i++) { |
| 3376 | sorted.insert(info->pPushConstantRanges + i); |
| 3377 | } |
| 3378 | |
Jeremy Hayes | f34b9fb | 2019-12-06 09:37:03 -0700 | [diff] [blame] | 3379 | PushConstantRanges ranges; |
| 3380 | ranges.reserve(sorted.size()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3381 | for (const auto range : sorted) { |
| 3382 | ranges.emplace_back(*range); |
| 3383 | } |
| 3384 | return push_constant_ranges_dict.look_up(std::move(ranges)); |
| 3385 | } |
| 3386 | |
| 3387 | // Dictionary of canoncial form of the pipeline set layout of descriptor set layouts |
| 3388 | static PipelineLayoutSetLayoutsDict pipeline_layout_set_layouts_dict; |
| 3389 | |
| 3390 | // Dictionary of canonical form of the "compatible for set" records |
| 3391 | static PipelineLayoutCompatDict pipeline_layout_compat_dict; |
| 3392 | |
| 3393 | static PipelineLayoutCompatId GetCanonicalId(const uint32_t set_index, const PushConstantRangesId pcr_id, |
| 3394 | const PipelineLayoutSetLayoutsId set_layouts_id) { |
| 3395 | return pipeline_layout_compat_dict.look_up(PipelineLayoutCompatDef(set_index, pcr_id, set_layouts_id)); |
| 3396 | } |
| 3397 | |
| 3398 | void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo, |
| 3399 | const VkAllocationCallbacks *pAllocator, |
| 3400 | VkPipelineLayout *pPipelineLayout, VkResult result) { |
| 3401 | if (VK_SUCCESS != result) return; |
| 3402 | |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3403 | auto pipeline_layout_state = std::make_shared<PIPELINE_LAYOUT_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3404 | pipeline_layout_state->layout = *pPipelineLayout; |
| 3405 | pipeline_layout_state->set_layouts.resize(pCreateInfo->setLayoutCount); |
| 3406 | PipelineLayoutSetLayoutsDef set_layouts(pCreateInfo->setLayoutCount); |
| 3407 | for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 3408 | pipeline_layout_state->set_layouts[i] = GetDescriptorSetLayoutShared(pCreateInfo->pSetLayouts[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3409 | set_layouts[i] = pipeline_layout_state->set_layouts[i]->GetLayoutId(); |
| 3410 | } |
| 3411 | |
| 3412 | // Get canonical form IDs for the "compatible for set" contents |
| 3413 | pipeline_layout_state->push_constant_ranges = GetCanonicalId(pCreateInfo); |
| 3414 | auto set_layouts_id = pipeline_layout_set_layouts_dict.look_up(set_layouts); |
| 3415 | pipeline_layout_state->compat_for_set.reserve(pCreateInfo->setLayoutCount); |
| 3416 | |
| 3417 | // Create table of "compatible for set N" cannonical forms for trivial accept validation |
| 3418 | for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) { |
| 3419 | pipeline_layout_state->compat_for_set.emplace_back( |
| 3420 | GetCanonicalId(i, pipeline_layout_state->push_constant_ranges, set_layouts_id)); |
| 3421 | } |
| 3422 | pipelineLayoutMap[*pPipelineLayout] = std::move(pipeline_layout_state); |
| 3423 | } |
| 3424 | |
| 3425 | void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo, |
| 3426 | const VkAllocationCallbacks *pAllocator, |
| 3427 | VkDescriptorPool *pDescriptorPool, VkResult result) { |
| 3428 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3429 | descriptorPoolMap[*pDescriptorPool] = std::make_shared<DESCRIPTOR_POOL_STATE>(*pDescriptorPool, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, |
| 3433 | VkDescriptorPoolResetFlags flags, VkResult result) { |
| 3434 | if (VK_SUCCESS != result) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3435 | DESCRIPTOR_POOL_STATE *pool = GetDescriptorPoolState(descriptorPool); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3436 | // TODO: validate flags |
| 3437 | // For every set off of this pool, clear it, remove from setMap, and free cvdescriptorset::DescriptorSet |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3438 | for (auto ds : pool->sets) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3439 | FreeDescriptorSet(ds); |
| 3440 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3441 | pool->sets.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3442 | // Reset available count for each type and available sets for this pool |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3443 | for (auto it = pool->availableDescriptorTypeCount.begin(); it != pool->availableDescriptorTypeCount.end(); ++it) { |
| 3444 | pool->availableDescriptorTypeCount[it->first] = pool->maxDescriptorTypeCount[it->first]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3445 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3446 | pool->availableSets = pool->maxSets; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device, |
| 3450 | const VkDescriptorSetAllocateInfo *pAllocateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3451 | VkDescriptorSet *pDescriptorSets, void *ads_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3452 | // Always update common data |
| 3453 | cvdescriptorset::AllocateDescriptorSetsData *ads_state = |
| 3454 | reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data); |
| 3455 | UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state); |
| 3456 | |
| 3457 | return false; |
| 3458 | } |
| 3459 | |
| 3460 | // Allocation state was good and call down chain was made so update state based on allocating descriptor sets |
| 3461 | void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, |
| 3462 | VkDescriptorSet *pDescriptorSets, VkResult result, |
| 3463 | void *ads_state_data) { |
| 3464 | if (VK_SUCCESS != result) return; |
| 3465 | // All the updates are contained in a single cvdescriptorset function |
| 3466 | cvdescriptorset::AllocateDescriptorSetsData *ads_state = |
| 3467 | reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data); |
| 3468 | PerformAllocateDescriptorSets(pAllocateInfo, pDescriptorSets, ads_state); |
| 3469 | } |
| 3470 | |
| 3471 | void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, |
| 3472 | const VkDescriptorSet *pDescriptorSets) { |
| 3473 | DESCRIPTOR_POOL_STATE *pool_state = GetDescriptorPoolState(descriptorPool); |
| 3474 | // Update available descriptor sets in pool |
| 3475 | pool_state->availableSets += count; |
| 3476 | |
| 3477 | // For each freed descriptor add its resources back into the pool as available and remove from pool and setMap |
| 3478 | for (uint32_t i = 0; i < count; ++i) { |
| 3479 | if (pDescriptorSets[i] != VK_NULL_HANDLE) { |
| 3480 | auto descriptor_set = setMap[pDescriptorSets[i]].get(); |
| 3481 | uint32_t type_index = 0, descriptor_count = 0; |
| 3482 | for (uint32_t j = 0; j < descriptor_set->GetBindingCount(); ++j) { |
| 3483 | type_index = static_cast<uint32_t>(descriptor_set->GetTypeFromIndex(j)); |
| 3484 | descriptor_count = descriptor_set->GetDescriptorCountFromIndex(j); |
| 3485 | pool_state->availableDescriptorTypeCount[type_index] += descriptor_count; |
| 3486 | } |
| 3487 | FreeDescriptorSet(descriptor_set); |
| 3488 | pool_state->sets.erase(descriptor_set); |
| 3489 | } |
| 3490 | } |
| 3491 | } |
| 3492 | |
| 3493 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, |
| 3494 | const VkWriteDescriptorSet *pDescriptorWrites, |
| 3495 | uint32_t descriptorCopyCount, |
| 3496 | const VkCopyDescriptorSet *pDescriptorCopies) { |
| 3497 | cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, |
| 3498 | pDescriptorCopies); |
| 3499 | } |
| 3500 | |
| 3501 | void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo, |
| 3502 | VkCommandBuffer *pCommandBuffer, VkResult result) { |
| 3503 | if (VK_SUCCESS != result) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3504 | auto pool = GetCommandPoolShared(pCreateInfo->commandPool); |
| 3505 | if (pool) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3506 | for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) { |
| 3507 | // Add command buffer to its commandPool map |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3508 | pool->commandBuffers.insert(pCommandBuffer[i]); |
| 3509 | auto cb_state = std::make_shared<CMD_BUFFER_STATE>(); |
| 3510 | cb_state->createInfo = *pCreateInfo; |
| 3511 | cb_state->command_pool = pool; |
| 3512 | cb_state->unprotected = pool->unprotected; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3513 | // Add command buffer to map |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3514 | commandBufferMap[pCommandBuffer[i]] = std::move(cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3515 | ResetCommandBufferState(pCommandBuffer[i]); |
| 3516 | } |
| 3517 | } |
| 3518 | } |
| 3519 | |
| 3520 | // Add bindings between the given cmd buffer & framebuffer and the framebuffer's children |
| 3521 | void ValidationStateTracker::AddFramebufferBinding(CMD_BUFFER_STATE *cb_state, FRAMEBUFFER_STATE *fb_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3522 | AddCommandBufferBinding(fb_state->cb_bindings, VulkanTypedHandle(fb_state->framebuffer, kVulkanObjectTypeFramebuffer, fb_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3523 | cb_state); |
Mark Lobodzinski | 544b3dd | 2019-12-03 14:44:54 -0700 | [diff] [blame] | 3524 | // If imageless fb, skip fb binding |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3525 | if (!fb_state || fb_state->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 3526 | const uint32_t attachment_count = fb_state->createInfo.attachmentCount; |
| 3527 | for (uint32_t attachment = 0; attachment < attachment_count; ++attachment) { |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3528 | auto view_state = GetActiveAttachmentImageViewState(cb_state, attachment); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3529 | if (view_state) { |
| 3530 | AddCommandBufferBindingImageView(cb_state, view_state); |
| 3531 | } |
| 3532 | } |
| 3533 | } |
| 3534 | |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3535 | void UpdateSubpassAttachments(const safe_VkSubpassDescription2 &subpass, std::vector<SUBPASS_INFO> &subpasses) { |
| 3536 | for (uint32_t index = 0; index < subpass.inputAttachmentCount; ++index) { |
| 3537 | const uint32_t attachment_index = subpass.pInputAttachments[index].attachment; |
| 3538 | if (attachment_index != VK_ATTACHMENT_UNUSED) { |
| 3539 | subpasses[attachment_index].used = true; |
| 3540 | subpasses[attachment_index].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; |
| 3541 | subpasses[attachment_index].layout = subpass.pInputAttachments[index].layout; |
| 3542 | } |
| 3543 | } |
| 3544 | |
| 3545 | for (uint32_t index = 0; index < subpass.colorAttachmentCount; ++index) { |
| 3546 | const uint32_t attachment_index = subpass.pColorAttachments[index].attachment; |
| 3547 | if (attachment_index != VK_ATTACHMENT_UNUSED) { |
| 3548 | subpasses[attachment_index].used = true; |
| 3549 | subpasses[attachment_index].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 3550 | subpasses[attachment_index].layout = subpass.pColorAttachments[index].layout; |
| 3551 | } |
| 3552 | if (subpass.pResolveAttachments) { |
| 3553 | const uint32_t attachment_index2 = subpass.pResolveAttachments[index].attachment; |
| 3554 | if (attachment_index2 != VK_ATTACHMENT_UNUSED) { |
| 3555 | subpasses[attachment_index2].used = true; |
| 3556 | subpasses[attachment_index2].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 3557 | subpasses[attachment_index2].layout = subpass.pResolveAttachments[index].layout; |
| 3558 | } |
| 3559 | } |
| 3560 | } |
| 3561 | |
| 3562 | if (subpass.pDepthStencilAttachment) { |
| 3563 | const uint32_t attachment_index = subpass.pDepthStencilAttachment->attachment; |
| 3564 | if (attachment_index != VK_ATTACHMENT_UNUSED) { |
| 3565 | subpasses[attachment_index].used = true; |
| 3566 | subpasses[attachment_index].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 3567 | subpasses[attachment_index].layout = subpass.pDepthStencilAttachment->layout; |
| 3568 | } |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | void UpdateAttachmentsView(ValidationStateTracker &tracker, CMD_BUFFER_STATE &cb_state, const FRAMEBUFFER_STATE &framebuffer, |
| 3573 | const VkRenderPassBeginInfo *pRenderPassBegin) { |
| 3574 | auto &attachments = *(cb_state.active_attachments.get()); |
| 3575 | const bool imageless = (framebuffer.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) ? true : false; |
| 3576 | const VkRenderPassAttachmentBeginInfo *attachment_info_struct = nullptr; |
| 3577 | if (pRenderPassBegin) attachment_info_struct = lvl_find_in_chain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
| 3578 | |
| 3579 | for (uint32_t i = 0; i < attachments.size(); ++i) { |
| 3580 | if (imageless) { |
| 3581 | if (attachment_info_struct && i < attachment_info_struct->attachmentCount) { |
| 3582 | auto res = cb_state.attachments_view_states.insert( |
| 3583 | tracker.GetShared<IMAGE_VIEW_STATE>(attachment_info_struct->pAttachments[i])); |
| 3584 | attachments[i] = res.first->get(); |
| 3585 | } |
| 3586 | } else { |
| 3587 | auto res = cb_state.attachments_view_states.insert(framebuffer.attachments_view_state[i]); |
| 3588 | attachments[i] = res.first->get(); |
| 3589 | } |
| 3590 | } |
| 3591 | } |
| 3592 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3593 | void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, |
| 3594 | const VkCommandBufferBeginInfo *pBeginInfo) { |
| 3595 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3596 | if (!cb_state) return; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3597 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3598 | if (CB_RECORDED == cb_state->state || CB_INVALID_COMPLETE == cb_state->state) { |
| 3599 | ResetCommandBufferState(commandBuffer); |
| 3600 | } |
| 3601 | // Set updated state here in case implicit reset occurs above |
| 3602 | cb_state->state = CB_RECORDING; |
| 3603 | cb_state->beginInfo = *pBeginInfo; |
| 3604 | if (cb_state->beginInfo.pInheritanceInfo) { |
| 3605 | cb_state->inheritanceInfo = *(cb_state->beginInfo.pInheritanceInfo); |
| 3606 | cb_state->beginInfo.pInheritanceInfo = &cb_state->inheritanceInfo; |
| 3607 | // If we are a secondary command-buffer and inheriting. Update the items we should inherit. |
| 3608 | if ((cb_state->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) && |
| 3609 | (cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) { |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 3610 | cb_state->activeRenderPass = GetShared<RENDER_PASS_STATE>(cb_state->beginInfo.pInheritanceInfo->renderPass); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3611 | cb_state->activeSubpass = cb_state->beginInfo.pInheritanceInfo->subpass; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3612 | |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 3613 | if (cb_state->beginInfo.pInheritanceInfo->framebuffer) { |
| 3614 | cb_state->activeFramebuffer = GetShared<FRAMEBUFFER_STATE>(cb_state->beginInfo.pInheritanceInfo->framebuffer); |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 3615 | cb_state->active_subpasses = nullptr; |
| 3616 | cb_state->active_attachments = nullptr; |
| 3617 | |
| 3618 | if (cb_state->activeFramebuffer) { |
| 3619 | cb_state->framebuffers.insert(cb_state->activeFramebuffer); |
| 3620 | |
| 3621 | // Set cb_state->active_subpasses |
| 3622 | cb_state->active_subpasses = |
| 3623 | std::make_shared<std::vector<SUBPASS_INFO>>(cb_state->activeFramebuffer->createInfo.attachmentCount); |
| 3624 | const auto &subpass = cb_state->activeRenderPass->createInfo.pSubpasses[cb_state->activeSubpass]; |
| 3625 | UpdateSubpassAttachments(subpass, *cb_state->active_subpasses); |
| 3626 | |
| 3627 | // Set cb_state->active_attachments & cb_state->attachments_view_states |
| 3628 | cb_state->active_attachments = |
| 3629 | std::make_shared<std::vector<IMAGE_VIEW_STATE *>>(cb_state->activeFramebuffer->createInfo.attachmentCount); |
| 3630 | UpdateAttachmentsView(*this, *cb_state, *cb_state->activeFramebuffer, nullptr); |
| 3631 | |
| 3632 | // Connect this framebuffer and its children to this cmdBuffer |
| 3633 | AddFramebufferBinding(cb_state, cb_state->activeFramebuffer.get()); |
| 3634 | } |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 3635 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3636 | } |
| 3637 | } |
| 3638 | |
| 3639 | auto chained_device_group_struct = lvl_find_in_chain<VkDeviceGroupCommandBufferBeginInfo>(pBeginInfo->pNext); |
| 3640 | if (chained_device_group_struct) { |
| 3641 | cb_state->initial_device_mask = chained_device_group_struct->deviceMask; |
| 3642 | } else { |
| 3643 | cb_state->initial_device_mask = (1 << physical_device_count) - 1; |
| 3644 | } |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3645 | |
| 3646 | cb_state->performance_lock_acquired = performance_lock_acquired; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) { |
| 3650 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3651 | if (!cb_state) return; |
| 3652 | // Cached validation is specific to a specific recording of a specific command buffer. |
| 3653 | for (auto descriptor_set : cb_state->validated_descriptor_sets) { |
| 3654 | descriptor_set->ClearCachedValidation(cb_state); |
| 3655 | } |
| 3656 | cb_state->validated_descriptor_sets.clear(); |
| 3657 | if (VK_SUCCESS == result) { |
| 3658 | cb_state->state = CB_RECORDED; |
| 3659 | } |
| 3660 | } |
| 3661 | |
| 3662 | void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags, |
| 3663 | VkResult result) { |
| 3664 | if (VK_SUCCESS == result) { |
| 3665 | ResetCommandBufferState(commandBuffer); |
| 3666 | } |
| 3667 | } |
| 3668 | |
| 3669 | CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) { |
| 3670 | // initially assume everything is static state |
| 3671 | CBStatusFlags flags = CBSTATUS_ALL_STATE_SET; |
| 3672 | |
| 3673 | if (ds) { |
| 3674 | for (uint32_t i = 0; i < ds->dynamicStateCount; i++) { |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 3675 | flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3676 | } |
| 3677 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3678 | return flags; |
| 3679 | } |
| 3680 | |
| 3681 | // Validation cache: |
| 3682 | // CV is the bottommost implementor of this extension. Don't pass calls down. |
| 3683 | // utility function to set collective state for pipeline |
| 3684 | void SetPipelineState(PIPELINE_STATE *pPipe) { |
| 3685 | // If any attachment used by this pipeline has blendEnable, set top-level blendEnable |
| 3686 | if (pPipe->graphicsPipelineCI.pColorBlendState) { |
| 3687 | for (size_t i = 0; i < pPipe->attachments.size(); ++i) { |
| 3688 | if (VK_TRUE == pPipe->attachments[i].blendEnable) { |
| 3689 | if (((pPipe->attachments[i].dstAlphaBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3690 | (pPipe->attachments[i].dstAlphaBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 3691 | ((pPipe->attachments[i].dstColorBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3692 | (pPipe->attachments[i].dstColorBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 3693 | ((pPipe->attachments[i].srcAlphaBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3694 | (pPipe->attachments[i].srcAlphaBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 3695 | ((pPipe->attachments[i].srcColorBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3696 | (pPipe->attachments[i].srcColorBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA))) { |
| 3697 | pPipe->blendConstantsEnabled = true; |
| 3698 | } |
| 3699 | } |
| 3700 | } |
| 3701 | } |
sfricke-samsung | 8f658d4 | 2020-05-03 20:12:24 -0700 | [diff] [blame] | 3702 | // Check if sample location is enabled |
| 3703 | if (pPipe->graphicsPipelineCI.pMultisampleState) { |
| 3704 | const VkPipelineSampleLocationsStateCreateInfoEXT *sample_location_state = |
| 3705 | lvl_find_in_chain<VkPipelineSampleLocationsStateCreateInfoEXT>(pPipe->graphicsPipelineCI.pMultisampleState->pNext); |
| 3706 | if (sample_location_state != nullptr) { |
| 3707 | pPipe->sample_location_enabled = sample_location_state->sampleLocationsEnable; |
| 3708 | } |
| 3709 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3710 | } |
| 3711 | |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 3712 | void UpdateSamplerDescriptorsUsedByImage(LAST_BOUND_STATE &last_bound_state) { |
| 3713 | if (!last_bound_state.pipeline_state) return; |
| 3714 | if (last_bound_state.per_set.empty()) return; |
| 3715 | |
| 3716 | for (auto &slot : last_bound_state.pipeline_state->active_slots) { |
| 3717 | for (auto &req : slot.second) { |
| 3718 | for (auto &samplers : req.second.samplers_used_by_image) { |
| 3719 | for (auto &sampler : samplers) { |
| 3720 | if (sampler.first.sampler_slot.first < last_bound_state.per_set.size() && |
| 3721 | last_bound_state.per_set[sampler.first.sampler_slot.first].bound_descriptor_set) { |
| 3722 | sampler.second = last_bound_state.per_set[sampler.first.sampler_slot.first] |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 3723 | .bound_descriptor_set->GetDescriptorFromBinding(sampler.first.sampler_slot.second, |
| 3724 | sampler.first.sampler_index); |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 3725 | } |
| 3726 | } |
| 3727 | } |
| 3728 | } |
| 3729 | } |
| 3730 | } |
| 3731 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3732 | void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 3733 | VkPipeline pipeline) { |
| 3734 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3735 | assert(cb_state); |
| 3736 | |
| 3737 | auto pipe_state = GetPipelineState(pipeline); |
| 3738 | if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) { |
| 3739 | cb_state->status &= ~cb_state->static_status; |
| 3740 | cb_state->static_status = MakeStaticStateMask(pipe_state->graphicsPipelineCI.ptr()->pDynamicState); |
| 3741 | cb_state->status |= cb_state->static_status; |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 3742 | cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3743 | } |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3744 | ResetCommandBufferPushConstantDataIfIncompatible(cb_state, pipe_state->pipeline_layout->layout); |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 3745 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 3746 | cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3747 | SetPipelineState(pipe_state); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3748 | AddCommandBufferBinding(pipe_state->cb_bindings, VulkanTypedHandle(pipeline, kVulkanObjectTypePipeline), cb_state); |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 3749 | |
| 3750 | for (auto &slot : pipe_state->active_slots) { |
| 3751 | for (auto &req : slot.second) { |
| 3752 | for (auto &sampler : req.second.samplers_used_by_image) { |
| 3753 | for (auto &des : sampler) { |
| 3754 | des.second = nullptr; |
| 3755 | } |
| 3756 | } |
| 3757 | } |
| 3758 | } |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 3759 | UpdateSamplerDescriptorsUsedByImage(cb_state->lastBound[lv_bind_point]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 3763 | uint32_t viewportCount, const VkViewport *pViewports) { |
| 3764 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3765 | cb_state->viewportMask |= ((1u << viewportCount) - 1u) << firstViewport; |
| 3766 | cb_state->status |= CBSTATUS_VIEWPORT_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3767 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor, |
| 3771 | uint32_t exclusiveScissorCount, |
| 3772 | const VkRect2D *pExclusiveScissors) { |
| 3773 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3774 | // TODO: We don't have VUIDs for validating that all exclusive scissors have been set. |
| 3775 | // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor; |
| 3776 | cb_state->status |= CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3777 | cb_state->static_status &= ~CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView, |
| 3781 | VkImageLayout imageLayout) { |
| 3782 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3783 | |
| 3784 | if (imageView != VK_NULL_HANDLE) { |
| 3785 | auto view_state = GetImageViewState(imageView); |
| 3786 | AddCommandBufferBindingImageView(cb_state, view_state); |
| 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 3791 | uint32_t viewportCount, |
| 3792 | const VkShadingRatePaletteNV *pShadingRatePalettes) { |
| 3793 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3794 | // TODO: We don't have VUIDs for validating that all shading rate palettes have been set. |
| 3795 | // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport; |
| 3796 | cb_state->status |= CBSTATUS_SHADING_RATE_PALETTE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3797 | cb_state->static_status &= ~CBSTATUS_SHADING_RATE_PALETTE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device, |
| 3801 | const VkAccelerationStructureCreateInfoNV *pCreateInfo, |
| 3802 | const VkAllocationCallbacks *pAllocator, |
| 3803 | VkAccelerationStructureNV *pAccelerationStructure, |
| 3804 | VkResult result) { |
| 3805 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3806 | auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3807 | |
| 3808 | // Query the requirements in case the application doesn't (to avoid bind/validation time query) |
| 3809 | VkAccelerationStructureMemoryRequirementsInfoNV as_memory_requirements_info = {}; |
| 3810 | as_memory_requirements_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV; |
| 3811 | as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV; |
| 3812 | as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure; |
| 3813 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements); |
| 3814 | |
| 3815 | VkAccelerationStructureMemoryRequirementsInfoNV scratch_memory_req_info = {}; |
| 3816 | scratch_memory_req_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV; |
| 3817 | scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV; |
| 3818 | scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure; |
| 3819 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info, |
| 3820 | &as_state->build_scratch_memory_requirements); |
| 3821 | |
| 3822 | VkAccelerationStructureMemoryRequirementsInfoNV update_memory_req_info = {}; |
| 3823 | update_memory_req_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV; |
| 3824 | update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV; |
| 3825 | update_memory_req_info.accelerationStructure = as_state->acceleration_structure; |
| 3826 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info, |
| 3827 | &as_state->update_scratch_memory_requirements); |
Mark Lobodzinski | 17dc460 | 2020-05-29 07:48:40 -0600 | [diff] [blame] | 3828 | as_state->allocator = pAllocator; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3829 | accelerationStructureMap[*pAccelerationStructure] = std::move(as_state); |
| 3830 | } |
| 3831 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3832 | void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device, |
| 3833 | const VkAccelerationStructureCreateInfoKHR *pCreateInfo, |
| 3834 | const VkAllocationCallbacks *pAllocator, |
| 3835 | VkAccelerationStructureKHR *pAccelerationStructure, |
| 3836 | VkResult result) { |
| 3837 | if (VK_SUCCESS != result) return; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3838 | auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo); |
Mark Lobodzinski | 17dc460 | 2020-05-29 07:48:40 -0600 | [diff] [blame] | 3839 | as_state->allocator = pAllocator; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3840 | accelerationStructureMap_khr[*pAccelerationStructure] = std::move(as_state); |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3841 | } |
| 3842 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3843 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR( |
| 3844 | VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, |
| 3845 | const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) { |
| 3846 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3847 | if (cb_state == nullptr) { |
| 3848 | return; |
| 3849 | } |
| 3850 | for (uint32_t i = 0; i < infoCount; ++i) { |
| 3851 | ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure); |
| 3852 | ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure); |
| 3853 | if (dst_as_state != nullptr) { |
| 3854 | dst_as_state->built = true; |
| 3855 | dst_as_state->build_info_khr.initialize(&pInfos[i]); |
| 3856 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 3857 | } |
| 3858 | if (src_as_state != nullptr) { |
| 3859 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 3860 | } |
| 3861 | } |
| 3862 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 3863 | } |
| 3864 | |
| 3865 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR( |
| 3866 | VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, |
| 3867 | const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides, |
| 3868 | const uint32_t *const *ppMaxPrimitiveCounts) { |
| 3869 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3870 | if (cb_state == nullptr) { |
| 3871 | return; |
| 3872 | } |
| 3873 | for (uint32_t i = 0; i < infoCount; ++i) { |
| 3874 | ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure); |
| 3875 | ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure); |
| 3876 | if (dst_as_state != nullptr) { |
| 3877 | dst_as_state->built = true; |
| 3878 | dst_as_state->build_info_khr.initialize(&pInfos[i]); |
| 3879 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 3880 | } |
| 3881 | if (src_as_state != nullptr) { |
| 3882 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 3883 | } |
| 3884 | } |
| 3885 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 3886 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3887 | void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV( |
| 3888 | VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2KHR *pMemoryRequirements) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3889 | ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(pInfo->accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3890 | if (as_state != nullptr) { |
| 3891 | if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) { |
| 3892 | as_state->memory_requirements = *pMemoryRequirements; |
| 3893 | as_state->memory_requirements_checked = true; |
| 3894 | } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) { |
| 3895 | as_state->build_scratch_memory_requirements = *pMemoryRequirements; |
| 3896 | as_state->build_scratch_memory_requirements_checked = true; |
| 3897 | } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) { |
| 3898 | as_state->update_scratch_memory_requirements = *pMemoryRequirements; |
| 3899 | as_state->update_scratch_memory_requirements_checked = true; |
| 3900 | } |
| 3901 | } |
| 3902 | } |
| 3903 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3904 | void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV( |
| 3905 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3906 | if (VK_SUCCESS != result) return; |
| 3907 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3908 | const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3909 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3910 | ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(info.accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3911 | if (as_state) { |
| 3912 | // Track bound memory range information |
| 3913 | auto mem_info = GetDevMemState(info.memory); |
| 3914 | if (mem_info) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 3915 | InsertAccelerationStructureMemoryRange(info.accelerationStructure, mem_info, info.memoryOffset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3916 | } |
| 3917 | // Track objects tied to memory |
| 3918 | SetMemBinding(info.memory, as_state, info.memoryOffset, |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3919 | VulkanTypedHandle(info.accelerationStructure, kVulkanObjectTypeAccelerationStructureNV)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3920 | |
| 3921 | // GPU validation of top level acceleration structure building needs acceleration structure handles. |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3922 | // XXX TODO: Query device address for KHR extension |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3923 | if (enabled[gpu_validation]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3924 | DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle); |
| 3925 | } |
| 3926 | } |
| 3927 | } |
| 3928 | } |
| 3929 | |
| 3930 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV( |
| 3931 | VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset, |
| 3932 | VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) { |
| 3933 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3934 | if (cb_state == nullptr) { |
| 3935 | return; |
| 3936 | } |
| 3937 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3938 | ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst); |
| 3939 | ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3940 | if (dst_as_state != nullptr) { |
| 3941 | dst_as_state->built = true; |
| 3942 | dst_as_state->build_info.initialize(pInfo); |
| 3943 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 3944 | } |
| 3945 | if (src_as_state != nullptr) { |
| 3946 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 3947 | } |
| 3948 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 3949 | } |
| 3950 | |
| 3951 | void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer, |
| 3952 | VkAccelerationStructureNV dst, |
| 3953 | VkAccelerationStructureNV src, |
| 3954 | VkCopyAccelerationStructureModeNV mode) { |
| 3955 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3956 | if (cb_state) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3957 | ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src); |
| 3958 | ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3959 | if (dst_as_state != nullptr && src_as_state != nullptr) { |
| 3960 | dst_as_state->built = true; |
| 3961 | dst_as_state->build_info = src_as_state->build_info; |
| 3962 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 3963 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 3964 | } |
| 3965 | } |
| 3966 | } |
| 3967 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3968 | void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device, |
| 3969 | VkAccelerationStructureKHR accelerationStructure, |
| 3970 | const VkAllocationCallbacks *pAllocator) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3971 | if (!accelerationStructure) return; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3972 | auto *as_state = GetAccelerationStructureStateKHR(accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3973 | if (as_state) { |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3974 | const VulkanTypedHandle obj_struct(accelerationStructure, kVulkanObjectTypeAccelerationStructureKHR); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3975 | InvalidateCommandBuffers(as_state->cb_bindings, obj_struct); |
| 3976 | for (auto mem_binding : as_state->GetBoundMemory()) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3977 | RemoveMemoryRange(obj_struct, mem_binding); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3978 | } |
| 3979 | ClearMemoryObjectBindings(obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3980 | as_state->destroyed = true; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3981 | accelerationStructureMap_khr.erase(accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3982 | } |
| 3983 | } |
| 3984 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3985 | void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device, |
| 3986 | VkAccelerationStructureNV accelerationStructure, |
| 3987 | const VkAllocationCallbacks *pAllocator) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3988 | if (!accelerationStructure) return; |
| 3989 | auto *as_state = GetAccelerationStructureStateNV(accelerationStructure); |
| 3990 | if (as_state) { |
| 3991 | const VulkanTypedHandle obj_struct(accelerationStructure, kVulkanObjectTypeAccelerationStructureNV); |
| 3992 | InvalidateCommandBuffers(as_state->cb_bindings, obj_struct); |
| 3993 | for (auto mem_binding : as_state->GetBoundMemory()) { |
| 3994 | RemoveMemoryRange(obj_struct, mem_binding); |
| 3995 | } |
| 3996 | ClearMemoryObjectBindings(obj_struct); |
| 3997 | as_state->destroyed = true; |
| 3998 | accelerationStructureMap.erase(accelerationStructure); |
| 3999 | } |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 4000 | } |
| 4001 | |
Chris Mayer | 9ded5eb | 2019-09-19 16:33:26 +0200 | [diff] [blame] | 4002 | void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 4003 | uint32_t viewportCount, |
| 4004 | const VkViewportWScalingNV *pViewportWScalings) { |
| 4005 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4006 | cb_state->status |= CBSTATUS_VIEWPORT_W_SCALING_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4007 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_W_SCALING_SET; |
Chris Mayer | 9ded5eb | 2019-09-19 16:33:26 +0200 | [diff] [blame] | 4008 | } |
| 4009 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4010 | void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) { |
| 4011 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4012 | cb_state->status |= CBSTATUS_LINE_WIDTH_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4013 | cb_state->static_status &= ~CBSTATUS_LINE_WIDTH_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor, |
| 4017 | uint16_t lineStipplePattern) { |
| 4018 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4019 | cb_state->status |= CBSTATUS_LINE_STIPPLE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4020 | cb_state->static_status &= ~CBSTATUS_LINE_STIPPLE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor, |
| 4024 | float depthBiasClamp, float depthBiasSlopeFactor) { |
| 4025 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4026 | cb_state->status |= CBSTATUS_DEPTH_BIAS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4027 | cb_state->static_status &= ~CBSTATUS_DEPTH_BIAS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4028 | } |
| 4029 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4030 | void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, |
| 4031 | const VkRect2D *pScissors) { |
| 4032 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4033 | cb_state->scissorMask |= ((1u << scissorCount) - 1u) << firstScissor; |
| 4034 | cb_state->status |= CBSTATUS_SCISSOR_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4035 | cb_state->static_status &= ~CBSTATUS_SCISSOR_SET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4036 | } |
| 4037 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4038 | void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) { |
| 4039 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4040 | cb_state->status |= CBSTATUS_BLEND_CONSTANTS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4041 | cb_state->static_status &= ~CBSTATUS_BLEND_CONSTANTS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds, |
| 4045 | float maxDepthBounds) { |
| 4046 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4047 | cb_state->status |= CBSTATUS_DEPTH_BOUNDS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4048 | cb_state->static_status &= ~CBSTATUS_DEPTH_BOUNDS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 4052 | uint32_t compareMask) { |
| 4053 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4054 | cb_state->status |= CBSTATUS_STENCIL_READ_MASK_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4055 | cb_state->static_status &= ~CBSTATUS_STENCIL_READ_MASK_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4056 | } |
| 4057 | |
| 4058 | void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 4059 | uint32_t writeMask) { |
| 4060 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4061 | cb_state->status |= CBSTATUS_STENCIL_WRITE_MASK_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4062 | cb_state->static_status &= ~CBSTATUS_STENCIL_WRITE_MASK_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 4066 | uint32_t reference) { |
| 4067 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4068 | cb_state->status |= CBSTATUS_STENCIL_REFERENCE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4069 | cb_state->static_status &= ~CBSTATUS_STENCIL_REFERENCE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | // Update pipeline_layout bind points applying the "Pipeline Layout Compatibility" rules. |
| 4073 | // One of pDescriptorSets or push_descriptor_set should be nullptr, indicating whether this |
| 4074 | // is called for CmdBindDescriptorSets or CmdPushDescriptorSet. |
| 4075 | void ValidationStateTracker::UpdateLastBoundDescriptorSets(CMD_BUFFER_STATE *cb_state, VkPipelineBindPoint pipeline_bind_point, |
| 4076 | const PIPELINE_LAYOUT_STATE *pipeline_layout, uint32_t first_set, |
| 4077 | uint32_t set_count, const VkDescriptorSet *pDescriptorSets, |
| 4078 | cvdescriptorset::DescriptorSet *push_descriptor_set, |
| 4079 | uint32_t dynamic_offset_count, const uint32_t *p_dynamic_offsets) { |
| 4080 | assert((pDescriptorSets == nullptr) ^ (push_descriptor_set == nullptr)); |
| 4081 | // Defensive |
| 4082 | assert(pipeline_layout); |
| 4083 | if (!pipeline_layout) return; |
| 4084 | |
| 4085 | uint32_t required_size = first_set + set_count; |
| 4086 | const uint32_t last_binding_index = required_size - 1; |
| 4087 | assert(last_binding_index < pipeline_layout->compat_for_set.size()); |
| 4088 | |
| 4089 | // Some useful shorthand |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 4090 | const auto lv_bind_point = ConvertToLvlBindPoint(pipeline_bind_point); |
| 4091 | auto &last_bound = cb_state->lastBound[lv_bind_point]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4092 | auto &pipe_compat_ids = pipeline_layout->compat_for_set; |
| 4093 | const uint32_t current_size = static_cast<uint32_t>(last_bound.per_set.size()); |
| 4094 | |
| 4095 | // We need this three times in this function, but nowhere else |
| 4096 | auto push_descriptor_cleanup = [&last_bound](const cvdescriptorset::DescriptorSet *ds) -> bool { |
| 4097 | if (ds && ds->IsPushDescriptor()) { |
| 4098 | assert(ds == last_bound.push_descriptor_set.get()); |
| 4099 | last_bound.push_descriptor_set = nullptr; |
| 4100 | return true; |
| 4101 | } |
| 4102 | return false; |
| 4103 | }; |
| 4104 | |
| 4105 | // Clean up the "disturbed" before and after the range to be set |
| 4106 | if (required_size < current_size) { |
| 4107 | if (last_bound.per_set[last_binding_index].compat_id_for_set != pipe_compat_ids[last_binding_index]) { |
| 4108 | // We're disturbing those after last, we'll shrink below, but first need to check for and cleanup the push_descriptor |
| 4109 | for (auto set_idx = required_size; set_idx < current_size; ++set_idx) { |
| 4110 | if (push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set)) break; |
| 4111 | } |
| 4112 | } else { |
| 4113 | // We're not disturbing past last, so leave the upper binding data alone. |
| 4114 | required_size = current_size; |
| 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | // We resize if we need more set entries or if those past "last" are disturbed |
| 4119 | if (required_size != current_size) { |
| 4120 | last_bound.per_set.resize(required_size); |
| 4121 | } |
| 4122 | |
| 4123 | // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update |
| 4124 | for (uint32_t set_idx = 0; set_idx < first_set; ++set_idx) { |
| 4125 | if (last_bound.per_set[set_idx].compat_id_for_set != pipe_compat_ids[set_idx]) { |
| 4126 | push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set); |
| 4127 | last_bound.per_set[set_idx].bound_descriptor_set = nullptr; |
| 4128 | last_bound.per_set[set_idx].dynamicOffsets.clear(); |
| 4129 | last_bound.per_set[set_idx].compat_id_for_set = pipe_compat_ids[set_idx]; |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | // Now update the bound sets with the input sets |
| 4134 | const uint32_t *input_dynamic_offsets = p_dynamic_offsets; // "read" pointer for dynamic offset data |
| 4135 | for (uint32_t input_idx = 0; input_idx < set_count; input_idx++) { |
| 4136 | auto set_idx = input_idx + first_set; // set_idx is index within layout, input_idx is index within input descriptor sets |
| 4137 | cvdescriptorset::DescriptorSet *descriptor_set = |
| 4138 | push_descriptor_set ? push_descriptor_set : GetSetNode(pDescriptorSets[input_idx]); |
| 4139 | |
| 4140 | // Record binding (or push) |
| 4141 | if (descriptor_set != last_bound.push_descriptor_set.get()) { |
| 4142 | // Only cleanup the push descriptors if they aren't the currently used set. |
| 4143 | push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set); |
| 4144 | } |
| 4145 | last_bound.per_set[set_idx].bound_descriptor_set = descriptor_set; |
| 4146 | last_bound.per_set[set_idx].compat_id_for_set = pipe_compat_ids[set_idx]; // compat ids are canonical *per* set index |
| 4147 | |
| 4148 | if (descriptor_set) { |
| 4149 | auto set_dynamic_descriptor_count = descriptor_set->GetDynamicDescriptorCount(); |
| 4150 | // TODO: Add logic for tracking push_descriptor offsets (here or in caller) |
| 4151 | if (set_dynamic_descriptor_count && input_dynamic_offsets) { |
| 4152 | const uint32_t *end_offset = input_dynamic_offsets + set_dynamic_descriptor_count; |
| 4153 | last_bound.per_set[set_idx].dynamicOffsets = std::vector<uint32_t>(input_dynamic_offsets, end_offset); |
| 4154 | input_dynamic_offsets = end_offset; |
| 4155 | assert(input_dynamic_offsets <= (p_dynamic_offsets + dynamic_offset_count)); |
| 4156 | } else { |
| 4157 | last_bound.per_set[set_idx].dynamicOffsets.clear(); |
| 4158 | } |
| 4159 | if (!descriptor_set->IsPushDescriptor()) { |
| 4160 | // Can't cache validation of push_descriptors |
| 4161 | cb_state->validated_descriptor_sets.insert(descriptor_set); |
| 4162 | } |
| 4163 | } |
| 4164 | } |
| 4165 | } |
| 4166 | |
| 4167 | // Update the bound state for the bind point, including the effects of incompatible pipeline layouts |
| 4168 | void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer, |
| 4169 | VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, |
| 4170 | uint32_t firstSet, uint32_t setCount, |
| 4171 | const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount, |
| 4172 | const uint32_t *pDynamicOffsets) { |
| 4173 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4174 | auto pipeline_layout = GetPipelineLayout(layout); |
| 4175 | |
| 4176 | // Resize binding arrays |
| 4177 | uint32_t last_set_index = firstSet + setCount - 1; |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 4178 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 4179 | if (last_set_index >= cb_state->lastBound[lv_bind_point].per_set.size()) { |
| 4180 | 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] | 4181 | } |
| 4182 | |
| 4183 | UpdateLastBoundDescriptorSets(cb_state, pipelineBindPoint, pipeline_layout, firstSet, setCount, pDescriptorSets, nullptr, |
| 4184 | dynamicOffsetCount, pDynamicOffsets); |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 4185 | cb_state->lastBound[lv_bind_point].pipeline_layout = layout; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4186 | ResetCommandBufferPushConstantDataIfIncompatible(cb_state, layout); |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 4187 | UpdateSamplerDescriptorsUsedByImage(cb_state->lastBound[lv_bind_point]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | void ValidationStateTracker::RecordCmdPushDescriptorSetState(CMD_BUFFER_STATE *cb_state, VkPipelineBindPoint pipelineBindPoint, |
| 4191 | VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount, |
| 4192 | const VkWriteDescriptorSet *pDescriptorWrites) { |
| 4193 | const auto &pipeline_layout = GetPipelineLayout(layout); |
| 4194 | // Short circuit invalid updates |
| 4195 | 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^] | 4196 | !pipeline_layout->set_layouts[set]->IsPushDescriptor()) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4197 | return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 4198 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4199 | |
| 4200 | // We need a descriptor set to update the bindings with, compatible with the passed layout |
| 4201 | const auto dsl = pipeline_layout->set_layouts[set]; |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 4202 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 4203 | auto &last_bound = cb_state->lastBound[lv_bind_point]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4204 | auto &push_descriptor_set = last_bound.push_descriptor_set; |
| 4205 | // If we are disturbing the current push_desriptor_set clear it |
| 4206 | 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] | 4207 | last_bound.UnbindAndResetPushDescriptorSet(new cvdescriptorset::DescriptorSet(0, nullptr, dsl, 0, this)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | UpdateLastBoundDescriptorSets(cb_state, pipelineBindPoint, pipeline_layout, set, 1, nullptr, push_descriptor_set.get(), 0, |
| 4211 | nullptr); |
| 4212 | last_bound.pipeline_layout = layout; |
| 4213 | |
| 4214 | // 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] | 4215 | push_descriptor_set->PerformPushDescriptorsUpdate(this, descriptorWriteCount, pDescriptorWrites); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, |
| 4219 | VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, |
| 4220 | uint32_t set, uint32_t descriptorWriteCount, |
| 4221 | const VkWriteDescriptorSet *pDescriptorWrites) { |
| 4222 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4223 | RecordCmdPushDescriptorSetState(cb_state, pipelineBindPoint, layout, set, descriptorWriteCount, pDescriptorWrites); |
| 4224 | } |
| 4225 | |
Tony-LunarG | 6bb1d0c | 2019-09-23 10:39:25 -0600 | [diff] [blame] | 4226 | void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout, |
| 4227 | VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, |
| 4228 | const void *pValues) { |
| 4229 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4230 | if (cb_state != nullptr) { |
| 4231 | ResetCommandBufferPushConstantDataIfIncompatible(cb_state, layout); |
| 4232 | |
| 4233 | auto &push_constant_data = cb_state->push_constant_data; |
| 4234 | assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size())); |
| 4235 | 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] | 4236 | cb_state->push_constant_pipeline_layout_set = layout; |
| 4237 | |
| 4238 | auto flags = stageFlags; |
| 4239 | uint32_t bit_shift = 0; |
| 4240 | while (flags) { |
| 4241 | if (flags & 1) { |
| 4242 | VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift); |
| 4243 | const auto it = cb_state->push_constant_data_update.find(flag); |
| 4244 | |
| 4245 | if (it != cb_state->push_constant_data_update.end()) { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 4246 | 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] | 4247 | } |
| 4248 | } |
| 4249 | flags = flags >> 1; |
| 4250 | ++bit_shift; |
| 4251 | } |
Tony-LunarG | 6bb1d0c | 2019-09-23 10:39:25 -0600 | [diff] [blame] | 4252 | } |
| 4253 | } |
| 4254 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4255 | void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4256 | VkIndexType indexType) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4257 | auto cb_state = GetCBState(commandBuffer); |
| 4258 | |
| 4259 | cb_state->status |= CBSTATUS_INDEX_BUFFER_BOUND; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4260 | cb_state->static_status &= ~CBSTATUS_INDEX_BUFFER_BOUND; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4261 | cb_state->index_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(buffer); |
| 4262 | 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] | 4263 | cb_state->index_buffer_binding.offset = offset; |
| 4264 | cb_state->index_buffer_binding.index_type = indexType; |
| 4265 | // Add binding for this index buffer to this commandbuffer |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4266 | AddCommandBufferBindingBuffer(cb_state, cb_state->index_buffer_binding.buffer_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding, |
| 4270 | uint32_t bindingCount, const VkBuffer *pBuffers, |
| 4271 | const VkDeviceSize *pOffsets) { |
| 4272 | auto cb_state = GetCBState(commandBuffer); |
| 4273 | |
| 4274 | uint32_t end = firstBinding + bindingCount; |
| 4275 | if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) { |
| 4276 | cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end); |
| 4277 | } |
| 4278 | |
| 4279 | for (uint32_t i = 0; i < bindingCount; ++i) { |
| 4280 | 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] | 4281 | vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4282 | vertex_buffer_binding.offset = pOffsets[i]; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4283 | vertex_buffer_binding.size = VK_WHOLE_SIZE; |
| 4284 | vertex_buffer_binding.stride = 0; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4285 | // Add binding for this vertex buffer to this commandbuffer |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 4286 | if (pBuffers[i]) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4287 | AddCommandBufferBindingBuffer(cb_state, vertex_buffer_binding.buffer_state.get()); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 4288 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4289 | } |
| 4290 | } |
| 4291 | |
| 4292 | void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, |
| 4293 | VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) { |
| 4294 | auto cb_state = GetCBState(commandBuffer); |
| 4295 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 4296 | |
| 4297 | // Update bindings between buffer and cmd buffer |
| 4298 | AddCommandBufferBindingBuffer(cb_state, dst_buffer_state); |
| 4299 | } |
| 4300 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4301 | bool ValidationStateTracker::SetEventStageMask(VkEvent event, VkPipelineStageFlags stageMask, |
| 4302 | EventToStageMap *localEventToStageMap) { |
| 4303 | (*localEventToStageMap)[event] = stageMask; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4304 | return false; |
| 4305 | } |
| 4306 | |
| 4307 | void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4308 | VkPipelineStageFlags stageMask) { |
| 4309 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4310 | auto event_state = GetEventState(event); |
| 4311 | if (event_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4312 | AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(event, kVulkanObjectTypeEvent, event_state), cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4313 | } |
| 4314 | cb_state->events.push_back(event); |
| 4315 | if (!cb_state->waitedEvents.count(event)) { |
| 4316 | cb_state->writeEventsBeforeWait.push_back(event); |
| 4317 | } |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4318 | cb_state->eventUpdates.emplace_back( |
| 4319 | [event, stageMask](const ValidationStateTracker *device_data, bool do_validate, EventToStageMap *localEventToStageMap) { |
| 4320 | return SetEventStageMask(event, stageMask, localEventToStageMap); |
| 4321 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4322 | } |
| 4323 | |
| 4324 | void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4325 | VkPipelineStageFlags stageMask) { |
| 4326 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4327 | auto event_state = GetEventState(event); |
| 4328 | if (event_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4329 | AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(event, kVulkanObjectTypeEvent, event_state), cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4330 | } |
| 4331 | cb_state->events.push_back(event); |
| 4332 | if (!cb_state->waitedEvents.count(event)) { |
| 4333 | cb_state->writeEventsBeforeWait.push_back(event); |
| 4334 | } |
| 4335 | |
| 4336 | cb_state->eventUpdates.emplace_back( |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4337 | [event](const ValidationStateTracker *, bool do_validate, EventToStageMap *localEventToStageMap) { |
| 4338 | return SetEventStageMask(event, VkPipelineStageFlags(0), localEventToStageMap); |
| 4339 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4340 | } |
| 4341 | |
| 4342 | void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4343 | VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask, |
| 4344 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4345 | uint32_t bufferMemoryBarrierCount, |
| 4346 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4347 | uint32_t imageMemoryBarrierCount, |
| 4348 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 4349 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4350 | for (uint32_t i = 0; i < eventCount; ++i) { |
| 4351 | auto event_state = GetEventState(pEvents[i]); |
| 4352 | if (event_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4353 | AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(pEvents[i], kVulkanObjectTypeEvent, event_state), |
| 4354 | cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4355 | } |
| 4356 | cb_state->waitedEvents.insert(pEvents[i]); |
| 4357 | cb_state->events.push_back(pEvents[i]); |
| 4358 | } |
| 4359 | } |
| 4360 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4361 | bool ValidationStateTracker::SetQueryState(QueryObject object, QueryState value, QueryMap *localQueryToStateMap) { |
| 4362 | (*localQueryToStateMap)[object] = value; |
| 4363 | return false; |
| 4364 | } |
| 4365 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4366 | bool ValidationStateTracker::SetQueryStateMulti(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, uint32_t perfPass, |
| 4367 | QueryState value, QueryMap *localQueryToStateMap) { |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4368 | for (uint32_t i = 0; i < queryCount; i++) { |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4369 | QueryObject object = QueryObject(QueryObject(queryPool, firstQuery + i), perfPass); |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4370 | (*localQueryToStateMap)[object] = value; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4371 | } |
| 4372 | return false; |
| 4373 | } |
| 4374 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4375 | QueryState ValidationStateTracker::GetQueryState(const QueryMap *localQueryToStateMap, VkQueryPool queryPool, uint32_t queryIndex, |
| 4376 | uint32_t perfPass) const { |
| 4377 | QueryObject query = QueryObject(QueryObject(queryPool, queryIndex), perfPass); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4378 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4379 | auto iter = localQueryToStateMap->find(query); |
| 4380 | if (iter != localQueryToStateMap->end()) return iter->second; |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4381 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4382 | return QUERYSTATE_UNKNOWN; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4383 | } |
| 4384 | |
| 4385 | void ValidationStateTracker::RecordCmdBeginQuery(CMD_BUFFER_STATE *cb_state, const QueryObject &query_obj) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4386 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4387 | cb_state->activeQueries.insert(query_obj); |
| 4388 | cb_state->startedQueries.insert(query_obj); |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4389 | cb_state->queryUpdates.emplace_back([query_obj](const ValidationStateTracker *device_data, bool do_validate, |
| 4390 | VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass, |
| 4391 | QueryMap *localQueryToStateMap) { |
| 4392 | SetQueryState(QueryObject(query_obj, perfQueryPass), QUERYSTATE_RUNNING, localQueryToStateMap); |
| 4393 | return false; |
| 4394 | }); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4395 | auto pool_state = GetQueryPoolState(query_obj.pool); |
| 4396 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(query_obj.pool, kVulkanObjectTypeQueryPool, pool_state), |
| 4397 | cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4398 | } |
| 4399 | |
| 4400 | void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, |
| 4401 | VkFlags flags) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4402 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4403 | QueryObject query = {queryPool, slot}; |
| 4404 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4405 | RecordCmdBeginQuery(cb_state, query); |
| 4406 | } |
| 4407 | |
| 4408 | void ValidationStateTracker::RecordCmdEndQuery(CMD_BUFFER_STATE *cb_state, const QueryObject &query_obj) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4409 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4410 | cb_state->activeQueries.erase(query_obj); |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4411 | cb_state->queryUpdates.emplace_back([query_obj](const ValidationStateTracker *device_data, bool do_validate, |
| 4412 | VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass, |
| 4413 | QueryMap *localQueryToStateMap) { |
| 4414 | return SetQueryState(QueryObject(query_obj, perfQueryPass), QUERYSTATE_ENDED, localQueryToStateMap); |
| 4415 | }); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4416 | auto pool_state = GetQueryPoolState(query_obj.pool); |
| 4417 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(query_obj.pool, kVulkanObjectTypeQueryPool, pool_state), |
| 4418 | cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4422 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4423 | QueryObject query_obj = {queryPool, slot}; |
| 4424 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4425 | RecordCmdEndQuery(cb_state, query_obj); |
| 4426 | } |
| 4427 | |
| 4428 | void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4429 | uint32_t firstQuery, uint32_t queryCount) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4430 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4431 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4432 | |
Lionel Landwerlin | b1e5a42 | 2020-02-18 16:49:09 +0200 | [diff] [blame] | 4433 | for (uint32_t slot = firstQuery; slot < (firstQuery + queryCount); slot++) { |
| 4434 | QueryObject query = {queryPool, slot}; |
| 4435 | cb_state->resetQueries.insert(query); |
| 4436 | } |
| 4437 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4438 | cb_state->queryUpdates.emplace_back([queryPool, firstQuery, queryCount](const ValidationStateTracker *device_data, |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4439 | bool do_validate, VkQueryPool &firstPerfQueryPool, |
| 4440 | uint32_t perfQueryPass, |
| 4441 | QueryMap *localQueryToStateMap) { |
| 4442 | return SetQueryStateMulti(queryPool, firstQuery, queryCount, perfQueryPass, QUERYSTATE_RESET, localQueryToStateMap); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4443 | }); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4444 | auto pool_state = GetQueryPoolState(queryPool); |
| 4445 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4446 | cb_state); |
| 4447 | } |
| 4448 | |
| 4449 | void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4450 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 4451 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 4452 | VkQueryResultFlags flags) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4453 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4454 | auto cb_state = GetCBState(commandBuffer); |
| 4455 | auto dst_buff_state = GetBufferState(dstBuffer); |
| 4456 | AddCommandBufferBindingBuffer(cb_state, dst_buff_state); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4457 | auto pool_state = GetQueryPoolState(queryPool); |
| 4458 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4459 | cb_state); |
| 4460 | } |
| 4461 | |
| 4462 | void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4463 | VkQueryPool queryPool, uint32_t slot) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4464 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4465 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4466 | auto pool_state = GetQueryPoolState(queryPool); |
| 4467 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4468 | cb_state); |
| 4469 | QueryObject query = {queryPool, slot}; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4470 | cb_state->queryUpdates.emplace_back([query](const ValidationStateTracker *device_data, bool do_validate, |
| 4471 | VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass, |
| 4472 | QueryMap *localQueryToStateMap) { |
| 4473 | return SetQueryState(QueryObject(query, perfQueryPass), QUERYSTATE_ENDED, localQueryToStateMap); |
| 4474 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo, |
| 4478 | const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer, |
| 4479 | VkResult result) { |
| 4480 | if (VK_SUCCESS != result) return; |
| 4481 | // Shadow create info and store in map |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 4482 | 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] | 4483 | |
| 4484 | if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR) == 0) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4485 | fb_state->attachments_view_state.resize(pCreateInfo->attachmentCount); |
| 4486 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4487 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4488 | 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] | 4489 | } |
| 4490 | } |
| 4491 | frameBufferMap[*pFramebuffer] = std::move(fb_state); |
| 4492 | } |
| 4493 | |
| 4494 | void ValidationStateTracker::RecordRenderPassDAG(RenderPassCreateVersion rp_version, const VkRenderPassCreateInfo2KHR *pCreateInfo, |
| 4495 | RENDER_PASS_STATE *render_pass) { |
| 4496 | auto &subpass_to_node = render_pass->subpassToNode; |
| 4497 | subpass_to_node.resize(pCreateInfo->subpassCount); |
| 4498 | auto &self_dependencies = render_pass->self_dependencies; |
| 4499 | self_dependencies.resize(pCreateInfo->subpassCount); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4500 | auto &subpass_dependencies = render_pass->subpass_dependencies; |
| 4501 | subpass_dependencies.resize(pCreateInfo->subpassCount); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4502 | |
| 4503 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { |
| 4504 | subpass_to_node[i].pass = i; |
| 4505 | self_dependencies[i].clear(); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4506 | subpass_dependencies[i].pass = i; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4507 | } |
| 4508 | for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4509 | const auto &dependency = pCreateInfo->pDependencies[i]; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 4510 | const auto src_subpass = dependency.srcSubpass; |
| 4511 | const auto dst_subpass = dependency.dstSubpass; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4512 | if ((dependency.srcSubpass != VK_SUBPASS_EXTERNAL) && (dependency.dstSubpass != VK_SUBPASS_EXTERNAL)) { |
| 4513 | if (dependency.srcSubpass == dependency.dstSubpass) { |
| 4514 | self_dependencies[dependency.srcSubpass].push_back(i); |
| 4515 | } else { |
| 4516 | subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass); |
| 4517 | subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass); |
| 4518 | } |
| 4519 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 4520 | if (src_subpass == VK_SUBPASS_EXTERNAL) { |
| 4521 | assert(dst_subpass != VK_SUBPASS_EXTERNAL); // this is invalid per VUID-VkSubpassDependency-srcSubpass-00865 |
| 4522 | subpass_dependencies[dst_subpass].barrier_from_external.emplace_back(&dependency); |
| 4523 | } else if (dst_subpass == VK_SUBPASS_EXTERNAL) { |
| 4524 | subpass_dependencies[src_subpass].barrier_to_external.emplace_back(&dependency); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4525 | } else if (dependency.srcSubpass != dependency.dstSubpass) { |
| 4526 | // ignore self dependencies in prev and next |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 4527 | subpass_dependencies[src_subpass].next[&subpass_dependencies[dst_subpass]].emplace_back(&dependency); |
| 4528 | subpass_dependencies[dst_subpass].prev[&subpass_dependencies[src_subpass]].emplace_back(&dependency); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4529 | } |
| 4530 | } |
| 4531 | |
| 4532 | // |
| 4533 | // Determine "asynchrononous" subpassess |
| 4534 | // syncronization is only interested in asyncronous stages *earlier* that the current one... so we'll only look towards those. |
| 4535 | // 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 |
| 4536 | // small and the K for |= from the prev is must less than for set, we'll accept the brute force. |
| 4537 | std::vector<std::vector<bool>> pass_depends(pCreateInfo->subpassCount); |
| 4538 | for (uint32_t i = 1; i < pCreateInfo->subpassCount; ++i) { |
| 4539 | auto &depends = pass_depends[i]; |
| 4540 | depends.resize(i); |
| 4541 | auto &subpass_dep = subpass_dependencies[i]; |
| 4542 | for (const auto &prev : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4543 | const auto prev_pass = prev.first->pass; |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4544 | const auto &prev_depends = pass_depends[prev_pass]; |
| 4545 | for (uint32_t j = 0; j < prev_pass; j++) { |
| 4546 | depends[j] = depends[j] | prev_depends[j]; |
| 4547 | } |
| 4548 | depends[prev_pass] = true; |
| 4549 | } |
| 4550 | for (uint32_t pass = 0; pass < subpass_dep.pass; pass++) { |
| 4551 | if (!depends[pass]) { |
| 4552 | subpass_dep.async.push_back(pass); |
| 4553 | } |
| 4554 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4555 | } |
| 4556 | } |
| 4557 | |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4558 | static VkSubpassDependency2 ImplicitDependencyFromExternal(uint32_t subpass) { |
| 4559 | VkSubpassDependency2 from_external = {VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, |
| 4560 | nullptr, |
| 4561 | VK_SUBPASS_EXTERNAL, |
| 4562 | subpass, |
| 4563 | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, |
| 4564 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4565 | 0, |
| 4566 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | |
| 4567 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | |
| 4568 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, |
| 4569 | 0, |
| 4570 | 0}; |
| 4571 | return from_external; |
| 4572 | } |
| 4573 | |
| 4574 | static VkSubpassDependency2 ImplicitDependencyToExternal(uint32_t subpass) { |
| 4575 | VkSubpassDependency2 to_external = {VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, |
| 4576 | nullptr, |
| 4577 | subpass, |
| 4578 | VK_SUBPASS_EXTERNAL, |
| 4579 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4580 | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, |
| 4581 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | |
| 4582 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | |
| 4583 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, |
| 4584 | 0, |
| 4585 | 0, |
| 4586 | 0}; |
| 4587 | return to_external; |
| 4588 | } |
| 4589 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4590 | void ValidationStateTracker::RecordCreateRenderPassState(RenderPassCreateVersion rp_version, |
| 4591 | std::shared_ptr<RENDER_PASS_STATE> &render_pass, |
| 4592 | VkRenderPass *pRenderPass) { |
| 4593 | render_pass->renderPass = *pRenderPass; |
| 4594 | auto create_info = render_pass->createInfo.ptr(); |
| 4595 | |
| 4596 | RecordRenderPassDAG(RENDER_PASS_VERSION_1, create_info, render_pass.get()); |
| 4597 | |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4598 | struct AttachmentTracker { // This is really only of local interest, but a bit big for a lambda |
| 4599 | RENDER_PASS_STATE *const rp; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4600 | std::vector<uint32_t> &first; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4601 | std::vector<bool> &first_is_transition; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4602 | std::vector<uint32_t> &last; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4603 | std::vector<std::vector<RENDER_PASS_STATE::AttachmentTransition>> &subpass_transitions; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4604 | std::unordered_map<uint32_t, bool> &first_read; |
| 4605 | const uint32_t attachment_count; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4606 | std::vector<VkImageLayout> attachment_layout; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4607 | std::vector<std::vector<VkImageLayout>> subpass_attachment_layout; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 4608 | explicit AttachmentTracker(std::shared_ptr<RENDER_PASS_STATE> &render_pass) |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4609 | : rp(render_pass.get()), |
| 4610 | first(rp->attachment_first_subpass), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4611 | first_is_transition(rp->attachment_first_is_transition), |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4612 | last(rp->attachment_last_subpass), |
| 4613 | subpass_transitions(rp->subpass_transitions), |
| 4614 | first_read(rp->attachment_first_read), |
| 4615 | attachment_count(rp->createInfo.attachmentCount), |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4616 | attachment_layout(), |
| 4617 | subpass_attachment_layout() { |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4618 | first.resize(attachment_count, VK_SUBPASS_EXTERNAL); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4619 | first_is_transition.resize(attachment_count, false); |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4620 | last.resize(attachment_count, VK_SUBPASS_EXTERNAL); |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4621 | subpass_transitions.resize(rp->createInfo.subpassCount + 1); // Add an extra for EndRenderPass |
| 4622 | attachment_layout.reserve(attachment_count); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4623 | subpass_attachment_layout.resize(rp->createInfo.subpassCount); |
| 4624 | for (auto &subpass_layouts : subpass_attachment_layout) { |
| 4625 | subpass_layouts.resize(attachment_count, kInvalidLayout); |
| 4626 | } |
| 4627 | |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4628 | for (uint32_t j = 0; j < attachment_count; j++) { |
| 4629 | attachment_layout.push_back(rp->createInfo.pAttachments[j].initialLayout); |
| 4630 | } |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4631 | } |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4632 | |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4633 | void Update(uint32_t subpass, const VkAttachmentReference2 *attach_ref, uint32_t count, bool is_read) { |
| 4634 | if (nullptr == attach_ref) return; |
| 4635 | for (uint32_t j = 0; j < count; ++j) { |
| 4636 | const auto attachment = attach_ref[j].attachment; |
| 4637 | if (attachment != VK_ATTACHMENT_UNUSED) { |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4638 | const auto layout = attach_ref[j].layout; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4639 | // Take advantage of the fact that insert won't overwrite, so we'll only write the first time. |
| 4640 | first_read.insert(std::make_pair(attachment, is_read)); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4641 | if (first[attachment] == VK_SUBPASS_EXTERNAL) { |
| 4642 | first[attachment] = subpass; |
| 4643 | const auto initial_layout = rp->createInfo.pAttachments[attachment].initialLayout; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4644 | if (initial_layout != layout) { |
| 4645 | subpass_transitions[subpass].emplace_back(VK_SUBPASS_EXTERNAL, attachment, initial_layout, layout); |
| 4646 | first_is_transition[attachment] = true; |
| 4647 | } |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4648 | } |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4649 | last[attachment] = subpass; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4650 | |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4651 | for (const auto &prev : rp->subpass_dependencies[subpass].prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4652 | const auto prev_pass = prev.first->pass; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4653 | const auto prev_layout = subpass_attachment_layout[prev_pass][attachment]; |
| 4654 | if ((prev_layout != kInvalidLayout) && (prev_layout != layout)) { |
| 4655 | subpass_transitions[subpass].emplace_back(prev_pass, attachment, prev_layout, layout); |
| 4656 | } |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4657 | } |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4658 | attachment_layout[attachment] = layout; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4659 | } |
| 4660 | } |
| 4661 | } |
| 4662 | void FinalTransitions() { |
| 4663 | auto &final_transitions = subpass_transitions[rp->createInfo.subpassCount]; |
| 4664 | |
| 4665 | for (uint32_t attachment = 0; attachment < attachment_count; ++attachment) { |
| 4666 | const auto final_layout = rp->createInfo.pAttachments[attachment].finalLayout; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4667 | // Add final transitions for attachments that were used and change layout. |
| 4668 | if ((last[attachment] != VK_SUBPASS_EXTERNAL) && final_layout != attachment_layout[attachment]) { |
| 4669 | final_transitions.emplace_back(last[attachment], attachment, attachment_layout[attachment], final_layout); |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4670 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4671 | } |
| 4672 | } |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4673 | }; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4674 | AttachmentTracker attachment_tracker(render_pass); |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4675 | |
| 4676 | for (uint32_t subpass_index = 0; subpass_index < create_info->subpassCount; ++subpass_index) { |
| 4677 | const VkSubpassDescription2KHR &subpass = create_info->pSubpasses[subpass_index]; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4678 | attachment_tracker.Update(subpass_index, subpass.pColorAttachments, subpass.colorAttachmentCount, false); |
| 4679 | attachment_tracker.Update(subpass_index, subpass.pResolveAttachments, subpass.colorAttachmentCount, false); |
| 4680 | attachment_tracker.Update(subpass_index, subpass.pDepthStencilAttachment, 1, false); |
| 4681 | attachment_tracker.Update(subpass_index, subpass.pInputAttachments, subpass.inputAttachmentCount, true); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4682 | } |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4683 | attachment_tracker.FinalTransitions(); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4684 | |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4685 | // Add implicit dependencies |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4686 | for (uint32_t attachment = 0; attachment < attachment_tracker.attachment_count; attachment++) { |
| 4687 | const auto first_use = attachment_tracker.first[attachment]; |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4688 | if (first_use != VK_SUBPASS_EXTERNAL) { |
| 4689 | auto &subpass_dep = render_pass->subpass_dependencies[first_use]; |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4690 | if (subpass_dep.barrier_from_external.size() == 0) { |
| 4691 | // Add implicit from barrier if they're aren't any |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4692 | subpass_dep.implicit_barrier_from_external.reset( |
| 4693 | new VkSubpassDependency2(ImplicitDependencyFromExternal(first_use))); |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4694 | 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] | 4695 | } |
| 4696 | } |
| 4697 | |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4698 | const auto last_use = attachment_tracker.last[attachment]; |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4699 | if (last_use != VK_SUBPASS_EXTERNAL) { |
| 4700 | auto &subpass_dep = render_pass->subpass_dependencies[last_use]; |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4701 | if (render_pass->subpass_dependencies[last_use].barrier_to_external.size() == 0) { |
| 4702 | // Add implicit to barrier if they're aren't any |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4703 | subpass_dep.implicit_barrier_to_external.reset(new VkSubpassDependency2(ImplicitDependencyToExternal(last_use))); |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4704 | 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] | 4705 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4706 | } |
| 4707 | } |
| 4708 | |
| 4709 | // Even though render_pass is an rvalue-ref parameter, still must move s.t. move assignment is invoked. |
| 4710 | renderPassMap[*pRenderPass] = std::move(render_pass); |
| 4711 | } |
| 4712 | |
| 4713 | // Style note: |
| 4714 | // Use of rvalue reference exceeds reccommended usage of rvalue refs in google style guide, but intentionally forces caller to move |
| 4715 | // or copy. This is clearer than passing a pointer to shared_ptr and avoids the atomic increment/decrement of shared_ptr copy |
| 4716 | // construction or assignment. |
| 4717 | void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, |
| 4718 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4719 | VkResult result) { |
| 4720 | if (VK_SUCCESS != result) return; |
| 4721 | auto render_pass_state = std::make_shared<RENDER_PASS_STATE>(pCreateInfo); |
| 4722 | RecordCreateRenderPassState(RENDER_PASS_VERSION_1, render_pass_state, pRenderPass); |
| 4723 | } |
| 4724 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4725 | void ValidationStateTracker::RecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo, |
| 4726 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4727 | VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4728 | if (VK_SUCCESS != result) return; |
| 4729 | auto render_pass_state = std::make_shared<RENDER_PASS_STATE>(pCreateInfo); |
| 4730 | RecordCreateRenderPassState(RENDER_PASS_VERSION_2, render_pass_state, pRenderPass); |
| 4731 | } |
| 4732 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4733 | void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo, |
| 4734 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4735 | VkResult result) { |
| 4736 | RecordCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass, result); |
| 4737 | } |
| 4738 | |
| 4739 | void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo, |
| 4740 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4741 | VkResult result) { |
| 4742 | RecordCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass, result); |
| 4743 | } |
| 4744 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4745 | void ValidationStateTracker::RecordCmdBeginRenderPassState(VkCommandBuffer commandBuffer, |
| 4746 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4747 | const VkSubpassContents contents) { |
| 4748 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4749 | auto render_pass_state = pRenderPassBegin ? GetShared<RENDER_PASS_STATE>(pRenderPassBegin->renderPass) : nullptr; |
| 4750 | auto framebuffer = pRenderPassBegin ? GetShared<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer) : nullptr; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4751 | |
| 4752 | if (render_pass_state) { |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4753 | cb_state->activeFramebuffer = framebuffer; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4754 | cb_state->activeRenderPass = render_pass_state; |
Tony-LunarG | 61e7c0c | 2020-03-03 16:09:11 -0700 | [diff] [blame] | 4755 | cb_state->activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4756 | cb_state->activeSubpass = 0; |
| 4757 | cb_state->activeSubpassContents = contents; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 4758 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4759 | // Connect this RP to cmdBuffer |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4760 | AddCommandBufferBinding( |
| 4761 | render_pass_state->cb_bindings, |
| 4762 | VulkanTypedHandle(render_pass_state->renderPass, kVulkanObjectTypeRenderPass, render_pass_state.get()), cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4763 | |
| 4764 | auto chained_device_group_struct = lvl_find_in_chain<VkDeviceGroupRenderPassBeginInfo>(pRenderPassBegin->pNext); |
| 4765 | if (chained_device_group_struct) { |
| 4766 | cb_state->active_render_pass_device_mask = chained_device_group_struct->deviceMask; |
| 4767 | } else { |
| 4768 | cb_state->active_render_pass_device_mask = cb_state->initial_device_mask; |
| 4769 | } |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 4770 | |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 4771 | cb_state->active_subpasses = nullptr; |
| 4772 | cb_state->active_attachments = nullptr; |
| 4773 | |
| 4774 | if (framebuffer) { |
| 4775 | cb_state->framebuffers.insert(framebuffer); |
| 4776 | |
| 4777 | // Set cb_state->active_subpasses |
| 4778 | cb_state->active_subpasses = |
| 4779 | std::make_shared<std::vector<SUBPASS_INFO>>(cb_state->activeFramebuffer->createInfo.attachmentCount); |
| 4780 | const auto &subpass = cb_state->activeRenderPass->createInfo.pSubpasses[cb_state->activeSubpass]; |
| 4781 | UpdateSubpassAttachments(subpass, *cb_state->active_subpasses); |
| 4782 | |
| 4783 | // Set cb_state->active_attachments & cb_state->attachments_view_states |
| 4784 | cb_state->active_attachments = |
| 4785 | std::make_shared<std::vector<IMAGE_VIEW_STATE *>>(framebuffer->createInfo.attachmentCount); |
| 4786 | UpdateAttachmentsView(*this, *cb_state, *cb_state->activeFramebuffer, pRenderPassBegin); |
| 4787 | |
| 4788 | // Connect this framebuffer and its children to this cmdBuffer |
| 4789 | AddFramebufferBinding(cb_state, framebuffer.get()); |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 4790 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4791 | } |
| 4792 | } |
| 4793 | |
| 4794 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, |
| 4795 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4796 | VkSubpassContents contents) { |
| 4797 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, contents); |
| 4798 | } |
| 4799 | |
| 4800 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4801 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4802 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo) { |
| 4803 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents); |
| 4804 | } |
| 4805 | |
Jeremy Hayes | 9bda85a | 2020-05-21 16:36:17 -0600 | [diff] [blame] | 4806 | void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer, |
| 4807 | uint32_t counterBufferCount, |
| 4808 | const VkBuffer *pCounterBuffers, |
| 4809 | const VkDeviceSize *pCounterBufferOffsets) { |
| 4810 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4811 | |
| 4812 | cb_state->transform_feedback_active = true; |
| 4813 | } |
| 4814 | |
| 4815 | void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer, |
| 4816 | uint32_t counterBufferCount, const VkBuffer *pCounterBuffers, |
| 4817 | const VkDeviceSize *pCounterBufferOffsets) { |
| 4818 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4819 | |
| 4820 | cb_state->transform_feedback_active = false; |
| 4821 | } |
| 4822 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4823 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, |
| 4824 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4825 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo) { |
| 4826 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents); |
| 4827 | } |
| 4828 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4829 | void ValidationStateTracker::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 4830 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4831 | cb_state->activeSubpass++; |
| 4832 | cb_state->activeSubpassContents = contents; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 4833 | |
| 4834 | // Update cb_state->active_subpasses |
| 4835 | if (cb_state->activeRenderPass && cb_state->activeFramebuffer) { |
| 4836 | cb_state->active_subpasses = nullptr; |
| 4837 | cb_state->active_subpasses = |
| 4838 | std::make_shared<std::vector<SUBPASS_INFO>>(cb_state->activeFramebuffer->createInfo.attachmentCount); |
| 4839 | |
| 4840 | const auto &subpass = cb_state->activeRenderPass->createInfo.pSubpasses[cb_state->activeSubpass]; |
| 4841 | UpdateSubpassAttachments(subpass, *cb_state->active_subpasses); |
| 4842 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 4846 | RecordCmdNextSubpass(commandBuffer, contents); |
| 4847 | } |
| 4848 | |
| 4849 | void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, |
| 4850 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo, |
| 4851 | const VkSubpassEndInfoKHR *pSubpassEndInfo) { |
| 4852 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents); |
| 4853 | } |
| 4854 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4855 | void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, |
| 4856 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo, |
| 4857 | const VkSubpassEndInfoKHR *pSubpassEndInfo) { |
| 4858 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents); |
| 4859 | } |
| 4860 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4861 | void ValidationStateTracker::RecordCmdEndRenderPassState(VkCommandBuffer commandBuffer) { |
| 4862 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4863 | cb_state->activeRenderPass = nullptr; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 4864 | cb_state->active_attachments = nullptr; |
| 4865 | cb_state->active_subpasses = nullptr; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4866 | cb_state->activeSubpass = 0; |
| 4867 | cb_state->activeFramebuffer = VK_NULL_HANDLE; |
| 4868 | } |
| 4869 | |
| 4870 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
| 4871 | RecordCmdEndRenderPassState(commandBuffer); |
| 4872 | } |
| 4873 | |
| 4874 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4875 | const VkSubpassEndInfoKHR *pSubpassEndInfo) { |
| 4876 | RecordCmdEndRenderPassState(commandBuffer); |
| 4877 | } |
| 4878 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4879 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, |
| 4880 | const VkSubpassEndInfoKHR *pSubpassEndInfo) { |
| 4881 | RecordCmdEndRenderPassState(commandBuffer); |
| 4882 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4883 | void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, |
| 4884 | const VkCommandBuffer *pCommandBuffers) { |
| 4885 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4886 | |
| 4887 | CMD_BUFFER_STATE *sub_cb_state = NULL; |
| 4888 | for (uint32_t i = 0; i < commandBuffersCount; i++) { |
| 4889 | sub_cb_state = GetCBState(pCommandBuffers[i]); |
| 4890 | assert(sub_cb_state); |
| 4891 | if (!(sub_cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) { |
| 4892 | if (cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) { |
| 4893 | // TODO: Because this is a state change, clearing the VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT needs to be moved |
| 4894 | // from the validation step to the recording step |
| 4895 | cb_state->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; |
| 4896 | } |
| 4897 | } |
| 4898 | |
| 4899 | // Propagate inital layout and current layout state to the primary cmd buffer |
| 4900 | // NOTE: The update/population of the image_layout_map is done in CoreChecks, but for other classes derived from |
| 4901 | // ValidationStateTracker these maps will be empty, so leaving the propagation in the the state tracker should be a no-op |
| 4902 | // for those other classes. |
| 4903 | for (const auto &sub_layout_map_entry : sub_cb_state->image_layout_map) { |
| 4904 | const auto image = sub_layout_map_entry.first; |
| 4905 | const auto *image_state = GetImageState(image); |
| 4906 | if (!image_state) continue; // Can't set layouts of a dead image |
| 4907 | |
| 4908 | auto *cb_subres_map = GetImageSubresourceLayoutMap(cb_state, *image_state); |
| 4909 | const auto *sub_cb_subres_map = sub_layout_map_entry.second.get(); |
| 4910 | assert(cb_subres_map && sub_cb_subres_map); // Non const get and map traversal should never be null |
| 4911 | cb_subres_map->UpdateFrom(*sub_cb_subres_map); |
| 4912 | } |
| 4913 | |
| 4914 | sub_cb_state->primaryCommandBuffer = cb_state->commandBuffer; |
| 4915 | cb_state->linkedCommandBuffers.insert(sub_cb_state); |
| 4916 | sub_cb_state->linkedCommandBuffers.insert(cb_state); |
| 4917 | for (auto &function : sub_cb_state->queryUpdates) { |
| 4918 | cb_state->queryUpdates.push_back(function); |
| 4919 | } |
| 4920 | for (auto &function : sub_cb_state->queue_submit_functions) { |
| 4921 | cb_state->queue_submit_functions.push_back(function); |
| 4922 | } |
| 4923 | } |
| 4924 | } |
| 4925 | |
| 4926 | void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, |
| 4927 | VkFlags flags, void **ppData, VkResult result) { |
| 4928 | if (VK_SUCCESS != result) return; |
| 4929 | RecordMappedMemory(mem, offset, size, ppData); |
| 4930 | } |
| 4931 | |
| 4932 | void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) { |
| 4933 | auto mem_info = GetDevMemState(mem); |
| 4934 | if (mem_info) { |
| 4935 | mem_info->mapped_range = MemRange(); |
| 4936 | mem_info->p_driver_data = nullptr; |
| 4937 | } |
| 4938 | } |
| 4939 | |
| 4940 | void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) { |
| 4941 | IMAGE_STATE *image_state = GetImageState(bindInfo.image); |
| 4942 | if (image_state) { |
locke-lunarg | ae26eac | 2020-04-16 15:29:05 -0600 | [diff] [blame] | 4943 | // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory. |
| 4944 | // See: VUID-vkGetImageSubresourceLayout-image-01895 |
| 4945 | image_state->fragment_encoder = |
| 4946 | std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4947 | const auto swapchain_info = lvl_find_in_chain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext); |
| 4948 | if (swapchain_info) { |
| 4949 | auto swapchain = GetSwapchainState(swapchain_info->swapchain); |
| 4950 | if (swapchain) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 4951 | swapchain->images[swapchain_info->imageIndex].bound_images.emplace(image_state->image); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4952 | image_state->bind_swapchain = swapchain_info->swapchain; |
| 4953 | image_state->bind_swapchain_imageIndex = swapchain_info->imageIndex; |
| 4954 | } |
| 4955 | } else { |
| 4956 | // Track bound memory range information |
| 4957 | auto mem_info = GetDevMemState(bindInfo.memory); |
| 4958 | if (mem_info) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 4959 | InsertImageMemoryRange(bindInfo.image, mem_info, bindInfo.memoryOffset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4960 | } |
| 4961 | |
| 4962 | // Track objects tied to memory |
| 4963 | SetMemBinding(bindInfo.memory, image_state, bindInfo.memoryOffset, |
| 4964 | VulkanTypedHandle(bindInfo.image, kVulkanObjectTypeImage)); |
| 4965 | } |
Tony-LunarG | 330cf4c | 2020-03-04 16:29:03 -0700 | [diff] [blame] | 4966 | if ((image_state->createInfo.flags & VK_IMAGE_CREATE_ALIAS_BIT) || swapchain_info) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4967 | AddAliasingImage(image_state); |
| 4968 | } |
| 4969 | } |
| 4970 | } |
| 4971 | |
| 4972 | void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem, |
| 4973 | VkDeviceSize memoryOffset, VkResult result) { |
| 4974 | if (VK_SUCCESS != result) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 4975 | VkBindImageMemoryInfo bind_info = {}; |
| 4976 | bind_info.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO; |
| 4977 | bind_info.image = image; |
| 4978 | bind_info.memory = mem; |
| 4979 | bind_info.memoryOffset = memoryOffset; |
| 4980 | UpdateBindImageMemoryState(bind_info); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4981 | } |
| 4982 | |
| 4983 | void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
| 4984 | const VkBindImageMemoryInfoKHR *pBindInfos, VkResult result) { |
| 4985 | if (VK_SUCCESS != result) return; |
| 4986 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 4987 | UpdateBindImageMemoryState(pBindInfos[i]); |
| 4988 | } |
| 4989 | } |
| 4990 | |
| 4991 | void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
| 4992 | const VkBindImageMemoryInfoKHR *pBindInfos, VkResult result) { |
| 4993 | if (VK_SUCCESS != result) return; |
| 4994 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 4995 | UpdateBindImageMemoryState(pBindInfos[i]); |
| 4996 | } |
| 4997 | } |
| 4998 | |
| 4999 | void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) { |
| 5000 | auto event_state = GetEventState(event); |
| 5001 | if (event_state) { |
| 5002 | event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT; |
| 5003 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device, |
| 5007 | const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo, |
| 5008 | VkResult result) { |
| 5009 | if (VK_SUCCESS != result) return; |
| 5010 | RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType, |
| 5011 | pImportSemaphoreFdInfo->flags); |
| 5012 | } |
| 5013 | |
| 5014 | void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore, |
| 5015 | VkExternalSemaphoreHandleTypeFlagBitsKHR handle_type) { |
| 5016 | SEMAPHORE_STATE *semaphore_state = GetSemaphoreState(semaphore); |
| 5017 | if (semaphore_state && handle_type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR) { |
| 5018 | // Cannot track semaphore state once it is exported, except for Sync FD handle types which have copy transference |
| 5019 | semaphore_state->scope = kSyncScopeExternalPermanent; |
| 5020 | } |
| 5021 | } |
| 5022 | |
| 5023 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 5024 | void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR( |
| 5025 | VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) { |
| 5026 | if (VK_SUCCESS != result) return; |
| 5027 | RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType, |
| 5028 | pImportSemaphoreWin32HandleInfo->flags); |
| 5029 | } |
| 5030 | |
| 5031 | void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device, |
| 5032 | const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo, |
| 5033 | HANDLE *pHandle, VkResult result) { |
| 5034 | if (VK_SUCCESS != result) return; |
| 5035 | RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType); |
| 5036 | } |
| 5037 | |
| 5038 | void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR( |
| 5039 | VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) { |
| 5040 | if (VK_SUCCESS != result) return; |
| 5041 | RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType, |
| 5042 | pImportFenceWin32HandleInfo->flags); |
| 5043 | } |
| 5044 | |
| 5045 | void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device, |
| 5046 | const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo, |
| 5047 | HANDLE *pHandle, VkResult result) { |
| 5048 | if (VK_SUCCESS != result) return; |
| 5049 | RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType); |
| 5050 | } |
| 5051 | #endif |
| 5052 | |
| 5053 | void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd, |
| 5054 | VkResult result) { |
| 5055 | if (VK_SUCCESS != result) return; |
| 5056 | RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType); |
| 5057 | } |
| 5058 | |
| 5059 | void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBitsKHR handle_type, |
| 5060 | VkFenceImportFlagsKHR flags) { |
| 5061 | FENCE_STATE *fence_node = GetFenceState(fence); |
| 5062 | if (fence_node && fence_node->scope != kSyncScopeExternalPermanent) { |
| 5063 | if ((handle_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR || flags & VK_FENCE_IMPORT_TEMPORARY_BIT_KHR) && |
| 5064 | fence_node->scope == kSyncScopeInternal) { |
| 5065 | fence_node->scope = kSyncScopeExternalTemporary; |
| 5066 | } else { |
| 5067 | fence_node->scope = kSyncScopeExternalPermanent; |
| 5068 | } |
| 5069 | } |
| 5070 | } |
| 5071 | |
| 5072 | void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo, |
| 5073 | VkResult result) { |
| 5074 | if (VK_SUCCESS != result) return; |
| 5075 | RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags); |
| 5076 | } |
| 5077 | |
| 5078 | void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBitsKHR handle_type) { |
| 5079 | FENCE_STATE *fence_state = GetFenceState(fence); |
| 5080 | if (fence_state) { |
| 5081 | if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR) { |
| 5082 | // Export with reference transference becomes external |
| 5083 | fence_state->scope = kSyncScopeExternalPermanent; |
| 5084 | } else if (fence_state->scope == kSyncScopeInternal) { |
| 5085 | // Export with copy transference has a side effect of resetting the fence |
| 5086 | fence_state->state = FENCE_UNSIGNALED; |
| 5087 | } |
| 5088 | } |
| 5089 | } |
| 5090 | |
| 5091 | void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd, |
| 5092 | VkResult result) { |
| 5093 | if (VK_SUCCESS != result) return; |
| 5094 | RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType); |
| 5095 | } |
| 5096 | |
| 5097 | void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo, |
| 5098 | const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) { |
| 5099 | if (VK_SUCCESS != result) return; |
| 5100 | eventMap[*pEvent].write_in_use = 0; |
| 5101 | eventMap[*pEvent].stageMask = VkPipelineStageFlags(0); |
| 5102 | } |
| 5103 | |
| 5104 | void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 5105 | VkSwapchainKHR *pSwapchain, SURFACE_STATE *surface_state, |
| 5106 | SWAPCHAIN_NODE *old_swapchain_state) { |
| 5107 | if (VK_SUCCESS == result) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5108 | auto swapchain_state = std::make_shared<SWAPCHAIN_NODE>(pCreateInfo, *pSwapchain); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5109 | if (VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR == pCreateInfo->presentMode || |
| 5110 | VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR == pCreateInfo->presentMode) { |
| 5111 | swapchain_state->shared_presentable = true; |
| 5112 | } |
| 5113 | surface_state->swapchain = swapchain_state.get(); |
| 5114 | swapchainMap[*pSwapchain] = std::move(swapchain_state); |
| 5115 | } else { |
| 5116 | surface_state->swapchain = nullptr; |
| 5117 | } |
| 5118 | // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired |
| 5119 | if (old_swapchain_state) { |
| 5120 | old_swapchain_state->retired = true; |
| 5121 | } |
| 5122 | return; |
| 5123 | } |
| 5124 | |
| 5125 | void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 5126 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain, |
| 5127 | VkResult result) { |
| 5128 | auto surface_state = GetSurfaceState(pCreateInfo->surface); |
| 5129 | auto old_swapchain_state = GetSwapchainState(pCreateInfo->oldSwapchain); |
| 5130 | RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, surface_state, old_swapchain_state); |
| 5131 | } |
| 5132 | |
| 5133 | void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 5134 | const VkAllocationCallbacks *pAllocator) { |
| 5135 | if (!swapchain) return; |
| 5136 | auto swapchain_data = GetSwapchainState(swapchain); |
| 5137 | if (swapchain_data) { |
| 5138 | for (const auto &swapchain_image : swapchain_data->images) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 5139 | ClearMemoryObjectBindings(VulkanTypedHandle(swapchain_image.image, kVulkanObjectTypeImage)); |
| 5140 | imageMap.erase(swapchain_image.image); |
| 5141 | RemoveAliasingImages(swapchain_image.bound_images); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | auto surface_state = GetSurfaceState(swapchain_data->createInfo.surface); |
| 5145 | if (surface_state) { |
| 5146 | if (surface_state->swapchain == swapchain_data) surface_state->swapchain = nullptr; |
| 5147 | } |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5148 | swapchain_data->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5149 | swapchainMap.erase(swapchain); |
| 5150 | } |
| 5151 | } |
| 5152 | |
sfricke-samsung | 5c1b739 | 2020-12-13 22:17:15 -0800 | [diff] [blame] | 5153 | void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, |
| 5154 | const VkDisplayModeCreateInfoKHR *pCreateInfo, |
| 5155 | const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode, |
| 5156 | VkResult result) { |
| 5157 | if (VK_SUCCESS != result) return; |
| 5158 | if (!pMode) return; |
| 5159 | auto display_mode_state = std::make_shared<DISPLAY_MODE_STATE>(*pMode); |
| 5160 | display_mode_state->physical_device = physicalDevice; |
| 5161 | display_mode_map[*pMode] = std::move(display_mode_state); |
| 5162 | } |
| 5163 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5164 | void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) { |
| 5165 | // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?) |
| 5166 | for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5167 | auto semaphore_state = GetSemaphoreState(pPresentInfo->pWaitSemaphores[i]); |
| 5168 | if (semaphore_state) { |
| 5169 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
| 5170 | semaphore_state->signaled = false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5171 | } |
| 5172 | } |
| 5173 | |
| 5174 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) { |
| 5175 | // 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 |
| 5176 | // confused itself just as much. |
| 5177 | auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result; |
| 5178 | if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen. |
| 5179 | // Mark the image as having been released to the WSI |
| 5180 | auto swapchain_data = GetSwapchainState(pPresentInfo->pSwapchains[i]); |
| 5181 | if (swapchain_data && (swapchain_data->images.size() > pPresentInfo->pImageIndices[i])) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 5182 | auto image = swapchain_data->images[pPresentInfo->pImageIndices[i]].image; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5183 | auto image_state = GetImageState(image); |
| 5184 | if (image_state) { |
| 5185 | image_state->acquired = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 5186 | if (image_state->shared_presentable) { |
| 5187 | image_state->layout_locked = true; |
| 5188 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5189 | } |
| 5190 | } |
| 5191 | } |
| 5192 | // Note: even though presentation is directed to a queue, there is no direct ordering between QP and subsequent work, so QP (and |
| 5193 | // its semaphore waits) /never/ participate in any completion proof. |
| 5194 | } |
| 5195 | |
| 5196 | void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 5197 | const VkSwapchainCreateInfoKHR *pCreateInfos, |
| 5198 | const VkAllocationCallbacks *pAllocator, |
| 5199 | VkSwapchainKHR *pSwapchains, VkResult result) { |
| 5200 | if (pCreateInfos) { |
| 5201 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| 5202 | auto surface_state = GetSurfaceState(pCreateInfos[i].surface); |
| 5203 | auto old_swapchain_state = GetSwapchainState(pCreateInfos[i].oldSwapchain); |
| 5204 | RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], surface_state, old_swapchain_state); |
| 5205 | } |
| 5206 | } |
| 5207 | } |
| 5208 | |
| 5209 | void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 5210 | VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5211 | auto fence_state = GetFenceState(fence); |
| 5212 | if (fence_state && fence_state->scope == kSyncScopeInternal) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5213 | // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary |
| 5214 | // import |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5215 | fence_state->state = FENCE_INFLIGHT; |
| 5216 | 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] | 5217 | } |
| 5218 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5219 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 5220 | if (semaphore_state && semaphore_state->scope == kSyncScopeInternal) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5221 | // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a |
| 5222 | // temporary import |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5223 | semaphore_state->signaled = true; |
| 5224 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | // Mark the image as acquired. |
| 5228 | auto swapchain_data = GetSwapchainState(swapchain); |
| 5229 | if (swapchain_data && (swapchain_data->images.size() > *pImageIndex)) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 5230 | auto image = swapchain_data->images[*pImageIndex].image; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5231 | auto image_state = GetImageState(image); |
| 5232 | if (image_state) { |
| 5233 | image_state->acquired = true; |
| 5234 | image_state->shared_presentable = swapchain_data->shared_presentable; |
| 5235 | } |
| 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 5240 | VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex, |
| 5241 | VkResult result) { |
| 5242 | if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return; |
| 5243 | RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex); |
| 5244 | } |
| 5245 | |
| 5246 | void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo, |
| 5247 | uint32_t *pImageIndex, VkResult result) { |
| 5248 | if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return; |
| 5249 | RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore, |
| 5250 | pAcquireInfo->fence, pImageIndex); |
| 5251 | } |
| 5252 | |
| 5253 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 5254 | VkPhysicalDevice *pPhysicalDevices, VkResult result) { |
| 5255 | if ((NULL != pPhysicalDevices) && ((result == VK_SUCCESS || result == VK_INCOMPLETE))) { |
| 5256 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
| 5257 | auto &phys_device_state = physical_device_map[pPhysicalDevices[i]]; |
| 5258 | phys_device_state.phys_device = pPhysicalDevices[i]; |
| 5259 | // Init actual features for each physical device |
| 5260 | DispatchGetPhysicalDeviceFeatures(pPhysicalDevices[i], &phys_device_state.features2.features); |
| 5261 | } |
| 5262 | } |
| 5263 | } |
| 5264 | |
| 5265 | // Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
| 5266 | static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count, |
| 5267 | VkQueueFamilyProperties2KHR *pQueueFamilyProperties) { |
| 5268 | pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count); |
| 5269 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5270 | if (pQueueFamilyProperties) { // Save queue family properties |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5271 | pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count)); |
| 5272 | for (uint32_t i = 0; i < count; ++i) { |
| 5273 | pd_state->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties; |
| 5274 | } |
| 5275 | } |
| 5276 | } |
| 5277 | |
| 5278 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 5279 | uint32_t *pQueueFamilyPropertyCount, |
| 5280 | VkQueueFamilyProperties *pQueueFamilyProperties) { |
| 5281 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5282 | assert(physical_device_state); |
| 5283 | VkQueueFamilyProperties2KHR *pqfp = nullptr; |
| 5284 | std::vector<VkQueueFamilyProperties2KHR> qfp; |
| 5285 | qfp.resize(*pQueueFamilyPropertyCount); |
| 5286 | if (pQueueFamilyProperties) { |
| 5287 | for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; ++i) { |
| 5288 | qfp[i].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR; |
| 5289 | qfp[i].pNext = nullptr; |
| 5290 | qfp[i].queueFamilyProperties = pQueueFamilyProperties[i]; |
| 5291 | } |
| 5292 | pqfp = qfp.data(); |
| 5293 | } |
| 5294 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, pqfp); |
| 5295 | } |
| 5296 | |
| 5297 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2( |
| 5298 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR *pQueueFamilyProperties) { |
| 5299 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5300 | assert(physical_device_state); |
| 5301 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 5302 | pQueueFamilyProperties); |
| 5303 | } |
| 5304 | |
| 5305 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR( |
| 5306 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR *pQueueFamilyProperties) { |
| 5307 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5308 | assert(physical_device_state); |
| 5309 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 5310 | pQueueFamilyProperties); |
| 5311 | } |
| 5312 | void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, |
| 5313 | const VkAllocationCallbacks *pAllocator) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5314 | if (!surface) return; |
| 5315 | auto surface_state = GetSurfaceState(surface); |
| 5316 | surface_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5317 | surface_map.erase(surface); |
| 5318 | } |
| 5319 | |
| 5320 | void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5321 | surface_map[*pSurface] = std::make_shared<SURFACE_STATE>(*pSurface); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5322 | } |
| 5323 | |
| 5324 | void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance, |
| 5325 | const VkDisplaySurfaceCreateInfoKHR *pCreateInfo, |
| 5326 | const VkAllocationCallbacks *pAllocator, |
| 5327 | VkSurfaceKHR *pSurface, VkResult result) { |
| 5328 | if (VK_SUCCESS != result) return; |
| 5329 | RecordVulkanSurface(pSurface); |
| 5330 | } |
| 5331 | |
| 5332 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 5333 | void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance, |
| 5334 | const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, |
| 5335 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5336 | VkResult result) { |
| 5337 | if (VK_SUCCESS != result) return; |
| 5338 | RecordVulkanSurface(pSurface); |
| 5339 | } |
| 5340 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 5341 | |
| 5342 | #ifdef VK_USE_PLATFORM_IOS_MVK |
| 5343 | void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo, |
| 5344 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5345 | VkResult result) { |
| 5346 | if (VK_SUCCESS != result) return; |
| 5347 | RecordVulkanSurface(pSurface); |
| 5348 | } |
| 5349 | #endif // VK_USE_PLATFORM_IOS_MVK |
| 5350 | |
| 5351 | #ifdef VK_USE_PLATFORM_MACOS_MVK |
| 5352 | void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance, |
| 5353 | const VkMacOSSurfaceCreateInfoMVK *pCreateInfo, |
| 5354 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5355 | VkResult result) { |
| 5356 | if (VK_SUCCESS != result) return; |
| 5357 | RecordVulkanSurface(pSurface); |
| 5358 | } |
| 5359 | #endif // VK_USE_PLATFORM_MACOS_MVK |
| 5360 | |
Jeremy Kniager | f33a67c | 2019-12-09 09:44:39 -0700 | [diff] [blame] | 5361 | #ifdef VK_USE_PLATFORM_METAL_EXT |
| 5362 | void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance, |
| 5363 | const VkMetalSurfaceCreateInfoEXT *pCreateInfo, |
| 5364 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5365 | VkResult result) { |
| 5366 | if (VK_SUCCESS != result) return; |
| 5367 | RecordVulkanSurface(pSurface); |
| 5368 | } |
| 5369 | #endif // VK_USE_PLATFORM_METAL_EXT |
| 5370 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5371 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 5372 | void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance, |
| 5373 | const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, |
| 5374 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5375 | VkResult result) { |
| 5376 | if (VK_SUCCESS != result) return; |
| 5377 | RecordVulkanSurface(pSurface); |
| 5378 | } |
| 5379 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 5380 | |
| 5381 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 5382 | void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance, |
| 5383 | const VkWin32SurfaceCreateInfoKHR *pCreateInfo, |
| 5384 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5385 | VkResult result) { |
| 5386 | if (VK_SUCCESS != result) return; |
| 5387 | RecordVulkanSurface(pSurface); |
| 5388 | } |
| 5389 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 5390 | |
| 5391 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 5392 | void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, |
| 5393 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5394 | VkResult result) { |
| 5395 | if (VK_SUCCESS != result) return; |
| 5396 | RecordVulkanSurface(pSurface); |
| 5397 | } |
| 5398 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 5399 | |
| 5400 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 5401 | void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, |
| 5402 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5403 | VkResult result) { |
| 5404 | if (VK_SUCCESS != result) return; |
| 5405 | RecordVulkanSurface(pSurface); |
| 5406 | } |
| 5407 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 5408 | |
Niklas Haas | 8b84af1 | 2020-04-19 22:20:11 +0200 | [diff] [blame] | 5409 | void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance, |
| 5410 | const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo, |
| 5411 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5412 | VkResult result) { |
| 5413 | if (VK_SUCCESS != result) return; |
| 5414 | RecordVulkanSurface(pSurface); |
| 5415 | } |
| 5416 | |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5417 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5418 | VkPhysicalDeviceFeatures *pFeatures) { |
| 5419 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Yilong Li | 358152a | 2020-07-08 02:16:45 -0700 | [diff] [blame] | 5420 | // Reset the features2 safe struct before setting up the features field. |
| 5421 | physical_device_state->features2 = safe_VkPhysicalDeviceFeatures2(); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5422 | physical_device_state->features2.features = *pFeatures; |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5423 | } |
| 5424 | |
| 5425 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5426 | VkPhysicalDeviceFeatures2 *pFeatures) { |
| 5427 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5428 | physical_device_state->features2.initialize(pFeatures); |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2KHR(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5432 | VkPhysicalDeviceFeatures2 *pFeatures) { |
| 5433 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5434 | physical_device_state->features2.initialize(pFeatures); |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5435 | } |
| 5436 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5437 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, |
| 5438 | VkSurfaceKHR surface, |
| 5439 | VkSurfaceCapabilitiesKHR *pSurfaceCapabilities, |
| 5440 | VkResult result) { |
| 5441 | if (VK_SUCCESS != result) return; |
| 5442 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5443 | physical_device_state->surfaceCapabilities = *pSurfaceCapabilities; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5444 | |
| 5445 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 5446 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR( |
| 5450 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, |
| 5451 | VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) { |
| 5452 | if (VK_SUCCESS != result) return; |
| 5453 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5454 | physical_device_state->surfaceCapabilities = pSurfaceCapabilities->surfaceCapabilities; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5455 | |
| 5456 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 5457 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice, |
| 5461 | VkSurfaceKHR surface, |
| 5462 | VkSurfaceCapabilities2EXT *pSurfaceCapabilities, |
| 5463 | VkResult result) { |
| 5464 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5465 | physical_device_state->surfaceCapabilities.minImageCount = pSurfaceCapabilities->minImageCount; |
| 5466 | physical_device_state->surfaceCapabilities.maxImageCount = pSurfaceCapabilities->maxImageCount; |
| 5467 | physical_device_state->surfaceCapabilities.currentExtent = pSurfaceCapabilities->currentExtent; |
| 5468 | physical_device_state->surfaceCapabilities.minImageExtent = pSurfaceCapabilities->minImageExtent; |
| 5469 | physical_device_state->surfaceCapabilities.maxImageExtent = pSurfaceCapabilities->maxImageExtent; |
| 5470 | physical_device_state->surfaceCapabilities.maxImageArrayLayers = pSurfaceCapabilities->maxImageArrayLayers; |
| 5471 | physical_device_state->surfaceCapabilities.supportedTransforms = pSurfaceCapabilities->supportedTransforms; |
| 5472 | physical_device_state->surfaceCapabilities.currentTransform = pSurfaceCapabilities->currentTransform; |
| 5473 | physical_device_state->surfaceCapabilities.supportedCompositeAlpha = pSurfaceCapabilities->supportedCompositeAlpha; |
| 5474 | physical_device_state->surfaceCapabilities.supportedUsageFlags = pSurfaceCapabilities->supportedUsageFlags; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5475 | |
| 5476 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 5477 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5478 | } |
| 5479 | |
| 5480 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, |
| 5481 | uint32_t queueFamilyIndex, VkSurfaceKHR surface, |
| 5482 | VkBool32 *pSupported, VkResult result) { |
| 5483 | if (VK_SUCCESS != result) return; |
| 5484 | auto surface_state = GetSurfaceState(surface); |
| 5485 | surface_state->gpu_queue_support[{physicalDevice, queueFamilyIndex}] = (*pSupported == VK_TRUE); |
| 5486 | } |
| 5487 | |
| 5488 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, |
| 5489 | VkSurfaceKHR surface, |
| 5490 | uint32_t *pPresentModeCount, |
| 5491 | VkPresentModeKHR *pPresentModes, |
| 5492 | VkResult result) { |
| 5493 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5494 | |
| 5495 | // TODO: This isn't quite right -- available modes may differ by surface AND physical device. |
| 5496 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5497 | |
| 5498 | if (*pPresentModeCount) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5499 | if (*pPresentModeCount > physical_device_state->present_modes.size()) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5500 | physical_device_state->present_modes.resize(*pPresentModeCount); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5501 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5502 | } |
| 5503 | if (pPresentModes) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5504 | for (uint32_t i = 0; i < *pPresentModeCount; i++) { |
| 5505 | physical_device_state->present_modes[i] = pPresentModes[i]; |
| 5506 | } |
| 5507 | } |
| 5508 | } |
| 5509 | |
| 5510 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 5511 | uint32_t *pSurfaceFormatCount, |
| 5512 | VkSurfaceFormatKHR *pSurfaceFormats, |
| 5513 | VkResult result) { |
| 5514 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5515 | |
| 5516 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5517 | |
| 5518 | if (*pSurfaceFormatCount) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5519 | if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5520 | physical_device_state->surface_formats.resize(*pSurfaceFormatCount); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5521 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5522 | } |
| 5523 | if (pSurfaceFormats) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5524 | for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) { |
| 5525 | physical_device_state->surface_formats[i] = pSurfaceFormats[i]; |
| 5526 | } |
| 5527 | } |
| 5528 | } |
| 5529 | |
| 5530 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, |
| 5531 | const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, |
| 5532 | uint32_t *pSurfaceFormatCount, |
| 5533 | VkSurfaceFormat2KHR *pSurfaceFormats, |
| 5534 | VkResult result) { |
| 5535 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5536 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5537 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5538 | if (*pSurfaceFormatCount) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5539 | if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) { |
| 5540 | physical_device_state->surface_formats.resize(*pSurfaceFormatCount); |
| 5541 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5542 | } |
| 5543 | if (pSurfaceFormats) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5544 | for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5545 | physical_device_state->surface_formats[i] = pSurfaceFormats[i].surfaceFormat; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5546 | } |
| 5547 | } |
| 5548 | } |
| 5549 | |
| 5550 | void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, |
| 5551 | const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 5552 | BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo); |
| 5553 | } |
| 5554 | |
| 5555 | void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) { |
| 5556 | EndCmdDebugUtilsLabel(report_data, commandBuffer); |
| 5557 | } |
| 5558 | |
| 5559 | void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, |
| 5560 | const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 5561 | InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo); |
| 5562 | |
| 5563 | // Squirrel away an easily accessible copy. |
| 5564 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5565 | cb_state->debug_label = LoggingLabel(pLabelInfo); |
| 5566 | } |
| 5567 | |
| 5568 | void ValidationStateTracker::RecordEnumeratePhysicalDeviceGroupsState( |
| 5569 | uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupPropertiesKHR *pPhysicalDeviceGroupProperties) { |
| 5570 | if (NULL != pPhysicalDeviceGroupProperties) { |
| 5571 | for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) { |
| 5572 | for (uint32_t j = 0; j < pPhysicalDeviceGroupProperties[i].physicalDeviceCount; j++) { |
| 5573 | VkPhysicalDevice cur_phys_dev = pPhysicalDeviceGroupProperties[i].physicalDevices[j]; |
| 5574 | auto &phys_device_state = physical_device_map[cur_phys_dev]; |
| 5575 | phys_device_state.phys_device = cur_phys_dev; |
| 5576 | // Init actual features for each physical device |
| 5577 | DispatchGetPhysicalDeviceFeatures(cur_phys_dev, &phys_device_state.features2.features); |
| 5578 | } |
| 5579 | } |
| 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroups( |
| 5584 | VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupPropertiesKHR *pPhysicalDeviceGroupProperties, |
| 5585 | VkResult result) { |
| 5586 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5587 | RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties); |
| 5588 | } |
| 5589 | |
| 5590 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroupsKHR( |
| 5591 | VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupPropertiesKHR *pPhysicalDeviceGroupProperties, |
| 5592 | VkResult result) { |
| 5593 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5594 | RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties); |
| 5595 | } |
| 5596 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5597 | void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice, |
| 5598 | uint32_t queueFamilyIndex, |
| 5599 | uint32_t *pCounterCount, |
| 5600 | VkPerformanceCounterKHR *pCounters) { |
| 5601 | if (NULL == pCounters) return; |
| 5602 | |
| 5603 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5604 | assert(physical_device_state); |
| 5605 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5606 | std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS()); |
| 5607 | queue_family_counters->counters.resize(*pCounterCount); |
| 5608 | 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] | 5609 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5610 | physical_device_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters); |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR( |
| 5614 | VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters, |
| 5615 | VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) { |
| 5616 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5617 | RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters); |
| 5618 | } |
| 5619 | |
| 5620 | void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo, |
| 5621 | VkResult result) { |
| 5622 | if (result == VK_SUCCESS) performance_lock_acquired = true; |
| 5623 | } |
| 5624 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5625 | void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) { |
| 5626 | performance_lock_acquired = false; |
| 5627 | for (auto &cmd_buffer : commandBufferMap) { |
| 5628 | cmd_buffer.second->performance_lock_released = true; |
| 5629 | } |
| 5630 | } |
| 5631 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5632 | void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device, |
| 5633 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 5634 | const VkAllocationCallbacks *pAllocator) { |
| 5635 | if (!descriptorUpdateTemplate) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5636 | auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 5637 | template_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5638 | desc_template_map.erase(descriptorUpdateTemplate); |
| 5639 | } |
| 5640 | |
| 5641 | void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device, |
| 5642 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 5643 | const VkAllocationCallbacks *pAllocator) { |
| 5644 | if (!descriptorUpdateTemplate) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5645 | auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 5646 | template_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5647 | desc_template_map.erase(descriptorUpdateTemplate); |
| 5648 | } |
| 5649 | |
| 5650 | void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo, |
| 5651 | VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate) { |
| 5652 | safe_VkDescriptorUpdateTemplateCreateInfo local_create_info(pCreateInfo); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5653 | auto template_state = std::make_shared<TEMPLATE_STATE>(*pDescriptorUpdateTemplate, &local_create_info); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5654 | desc_template_map[*pDescriptorUpdateTemplate] = std::move(template_state); |
| 5655 | } |
| 5656 | |
| 5657 | void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate( |
| 5658 | VkDevice device, const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 5659 | VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate, VkResult result) { |
| 5660 | if (VK_SUCCESS != result) return; |
| 5661 | RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate); |
| 5662 | } |
| 5663 | |
| 5664 | void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR( |
| 5665 | VkDevice device, const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 5666 | VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate, VkResult result) { |
| 5667 | if (VK_SUCCESS != result) return; |
| 5668 | RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate); |
| 5669 | } |
| 5670 | |
| 5671 | void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet, |
| 5672 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 5673 | const void *pData) { |
| 5674 | auto const template_map_entry = desc_template_map.find(descriptorUpdateTemplate); |
| 5675 | if ((template_map_entry == desc_template_map.end()) || (template_map_entry->second.get() == nullptr)) { |
| 5676 | assert(0); |
| 5677 | } else { |
| 5678 | const TEMPLATE_STATE *template_state = template_map_entry->second.get(); |
| 5679 | // TODO: Record template push descriptor updates |
| 5680 | if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) { |
| 5681 | PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state, pData); |
| 5682 | } |
| 5683 | } |
| 5684 | } |
| 5685 | |
| 5686 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet, |
| 5687 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
| 5688 | const void *pData) { |
| 5689 | RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData); |
| 5690 | } |
| 5691 | |
| 5692 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet, |
| 5693 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 5694 | const void *pData) { |
| 5695 | RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData); |
| 5696 | } |
| 5697 | |
| 5698 | void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR( |
| 5699 | VkCommandBuffer commandBuffer, VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, VkPipelineLayout layout, uint32_t set, |
| 5700 | const void *pData) { |
| 5701 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5702 | |
| 5703 | const auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 5704 | if (template_state) { |
| 5705 | auto layout_data = GetPipelineLayout(layout); |
| 5706 | auto dsl = GetDslFromPipelineLayout(layout_data, set); |
| 5707 | const auto &template_ci = template_state->create_info; |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 5708 | if (dsl && !dsl->destroyed) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5709 | // Decode the template into a set of write updates |
| 5710 | cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state, pData, |
| 5711 | dsl->GetDescriptorSetLayout()); |
| 5712 | RecordCmdPushDescriptorSetState(cb_state, template_ci.pipelineBindPoint, layout, set, |
| 5713 | static_cast<uint32_t>(decoded_template.desc_writes.size()), |
| 5714 | decoded_template.desc_writes.data()); |
| 5715 | } |
| 5716 | } |
| 5717 | } |
| 5718 | |
| 5719 | void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice, |
| 5720 | uint32_t *pPropertyCount, void *pProperties) { |
| 5721 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5722 | if (*pPropertyCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5723 | physical_device_state->display_plane_property_count = *pPropertyCount; |
| 5724 | } |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5725 | if (*pPropertyCount || pProperties) { |
| 5726 | physical_device_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5727 | } |
| 5728 | } |
| 5729 | |
| 5730 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, |
| 5731 | uint32_t *pPropertyCount, |
| 5732 | VkDisplayPlanePropertiesKHR *pProperties, |
| 5733 | VkResult result) { |
| 5734 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5735 | RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties); |
| 5736 | } |
| 5737 | |
| 5738 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice, |
| 5739 | uint32_t *pPropertyCount, |
| 5740 | VkDisplayPlaneProperties2KHR *pProperties, |
| 5741 | VkResult result) { |
| 5742 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5743 | RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties); |
| 5744 | } |
| 5745 | |
| 5746 | void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 5747 | uint32_t query, VkQueryControlFlags flags, uint32_t index) { |
| 5748 | QueryObject query_obj = {queryPool, query, index}; |
| 5749 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5750 | RecordCmdBeginQuery(cb_state, query_obj); |
| 5751 | } |
| 5752 | |
| 5753 | void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 5754 | uint32_t query, uint32_t index) { |
| 5755 | QueryObject query_obj = {queryPool, query, index}; |
| 5756 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5757 | RecordCmdEndQuery(cb_state, query_obj); |
| 5758 | } |
| 5759 | |
| 5760 | void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info, |
| 5761 | VkSamplerYcbcrConversion ycbcr_conversion) { |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5762 | auto ycbcr_state = std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(); |
| 5763 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5764 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5765 | RecordCreateSamplerYcbcrConversionANDROID(create_info, ycbcr_conversion, ycbcr_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5766 | } |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5767 | |
| 5768 | const VkFormat conversion_format = create_info->format; |
| 5769 | |
| 5770 | if (conversion_format != VK_FORMAT_UNDEFINED) { |
| 5771 | // If format is VK_FORMAT_UNDEFINED, will be set by external AHB features |
| 5772 | ycbcr_state->format_features = GetPotentialFormatFeatures(conversion_format); |
| 5773 | } |
| 5774 | |
| 5775 | ycbcr_state->chromaFilter = create_info->chromaFilter; |
| 5776 | ycbcr_state->format = conversion_format; |
| 5777 | samplerYcbcrConversionMap[ycbcr_conversion] = std::move(ycbcr_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5778 | } |
| 5779 | |
| 5780 | void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device, |
| 5781 | const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, |
| 5782 | const VkAllocationCallbacks *pAllocator, |
| 5783 | VkSamplerYcbcrConversion *pYcbcrConversion, |
| 5784 | VkResult result) { |
| 5785 | if (VK_SUCCESS != result) return; |
| 5786 | RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion); |
| 5787 | } |
| 5788 | |
| 5789 | void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device, |
| 5790 | const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, |
| 5791 | const VkAllocationCallbacks *pAllocator, |
| 5792 | VkSamplerYcbcrConversion *pYcbcrConversion, |
| 5793 | VkResult result) { |
| 5794 | if (VK_SUCCESS != result) return; |
| 5795 | RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion); |
| 5796 | } |
| 5797 | |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5798 | void ValidationStateTracker::RecordDestroySamplerYcbcrConversionState(VkSamplerYcbcrConversion ycbcr_conversion) { |
| 5799 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
| 5800 | RecordDestroySamplerYcbcrConversionANDROID(ycbcr_conversion); |
| 5801 | } |
| 5802 | |
| 5803 | auto ycbcr_state = GetSamplerYcbcrConversionState(ycbcr_conversion); |
| 5804 | ycbcr_state->destroyed = true; |
| 5805 | samplerYcbcrConversionMap.erase(ycbcr_conversion); |
| 5806 | } |
| 5807 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5808 | void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion, |
| 5809 | const VkAllocationCallbacks *pAllocator) { |
| 5810 | if (!ycbcrConversion) return; |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5811 | RecordDestroySamplerYcbcrConversionState(ycbcrConversion); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device, |
| 5815 | VkSamplerYcbcrConversion ycbcrConversion, |
| 5816 | const VkAllocationCallbacks *pAllocator) { |
| 5817 | if (!ycbcrConversion) return; |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5818 | RecordDestroySamplerYcbcrConversionState(ycbcrConversion); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5819 | } |
| 5820 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5821 | void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 5822 | uint32_t queryCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5823 | // Do nothing if the feature is not enabled. |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 5824 | if (!enabled_features.core12.hostQueryReset) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5825 | |
| 5826 | // Do nothing if the query pool has been destroyed. |
| 5827 | auto query_pool_state = GetQueryPoolState(queryPool); |
| 5828 | if (!query_pool_state) return; |
| 5829 | |
| 5830 | // Reset the state of existing entries. |
| 5831 | QueryObject query_obj{queryPool, 0}; |
| 5832 | const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery); |
| 5833 | for (uint32_t i = 0; i < max_query_count; ++i) { |
| 5834 | query_obj.query = firstQuery + i; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 5835 | queryToStateMap[query_obj] = QUERYSTATE_RESET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5836 | if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5837 | for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) { |
| 5838 | query_obj.perf_pass = pass_index; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 5839 | queryToStateMap[query_obj] = QUERYSTATE_RESET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5840 | } |
| 5841 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5842 | } |
| 5843 | } |
| 5844 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5845 | void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 5846 | uint32_t queryCount) { |
| 5847 | RecordResetQueryPool(device, queryPool, firstQuery, queryCount); |
| 5848 | } |
| 5849 | |
| 5850 | void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 5851 | uint32_t queryCount) { |
| 5852 | RecordResetQueryPool(device, queryPool, firstQuery, queryCount); |
| 5853 | } |
| 5854 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5855 | void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet, |
| 5856 | const TEMPLATE_STATE *template_state, const void *pData) { |
| 5857 | // Translate the templated update into a normal update for validation... |
| 5858 | cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData); |
| 5859 | cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()), |
| 5860 | decoded_update.desc_writes.data(), 0, NULL); |
| 5861 | } |
| 5862 | |
| 5863 | // Update the common AllocateDescriptorSetsData |
| 5864 | void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 5865 | cvdescriptorset::AllocateDescriptorSetsData *ds_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5866 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 5867 | auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5868 | if (layout) { |
| 5869 | ds_data->layout_nodes[i] = layout; |
| 5870 | // Count total descriptors required per type |
| 5871 | for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) { |
| 5872 | const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 5873 | uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType); |
| 5874 | ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5875 | } |
| 5876 | } |
| 5877 | // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call |
| 5878 | } |
| 5879 | } |
| 5880 | |
| 5881 | // Decrement allocated sets from the pool and insert new sets into set_map |
| 5882 | void ValidationStateTracker::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 5883 | const VkDescriptorSet *descriptor_sets, |
| 5884 | const cvdescriptorset::AllocateDescriptorSetsData *ds_data) { |
| 5885 | auto pool_state = descriptorPoolMap[p_alloc_info->descriptorPool].get(); |
| 5886 | // Account for sets and individual descriptors allocated from pool |
| 5887 | pool_state->availableSets -= p_alloc_info->descriptorSetCount; |
| 5888 | for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) { |
| 5889 | pool_state->availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first); |
| 5890 | } |
| 5891 | |
| 5892 | const auto *variable_count_info = lvl_find_in_chain<VkDescriptorSetVariableDescriptorCountAllocateInfoEXT>(p_alloc_info->pNext); |
| 5893 | bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == p_alloc_info->descriptorSetCount; |
| 5894 | |
| 5895 | // Create tracking object for each descriptor set; insert into global map and the pool's set. |
| 5896 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
| 5897 | uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0; |
| 5898 | |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 5899 | 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] | 5900 | variable_count, this); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5901 | pool_state->sets.insert(new_ds.get()); |
| 5902 | new_ds->in_use.store(0); |
| 5903 | setMap[descriptor_sets[i]] = std::move(new_ds); |
| 5904 | } |
| 5905 | } |
| 5906 | |
| 5907 | // 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] | 5908 | void ValidationStateTracker::UpdateStateCmdDrawDispatchType(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5909 | VkPipelineBindPoint bind_point, const char *function) { |
| 5910 | UpdateDrawState(cb_state, cmd_type, bind_point, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5911 | cb_state->hasDispatchCmd = true; |
| 5912 | } |
| 5913 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5914 | // Generic function to handle state update for all CmdDraw* type functions |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5915 | void ValidationStateTracker::UpdateStateCmdDrawType(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, VkPipelineBindPoint bind_point, |
| 5916 | const char *function) { |
| 5917 | UpdateStateCmdDrawDispatchType(cb_state, cmd_type, bind_point, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5918 | cb_state->hasDrawCmd = true; |
| 5919 | } |
| 5920 | |
| 5921 | void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 5922 | uint32_t firstVertex, uint32_t firstInstance) { |
| 5923 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5924 | UpdateStateCmdDrawType(cb_state, CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, |
| 5928 | uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, |
| 5929 | uint32_t firstInstance) { |
| 5930 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5931 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5935 | uint32_t count, uint32_t stride) { |
| 5936 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5937 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5938 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5939 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5940 | } |
| 5941 | |
| 5942 | void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5943 | VkDeviceSize offset, uint32_t count, uint32_t stride) { |
| 5944 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5945 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5946 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5947 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5948 | } |
| 5949 | |
| 5950 | void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) { |
| 5951 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5952 | UpdateStateCmdDrawDispatchType(cb_state, CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5953 | } |
| 5954 | |
| 5955 | void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5956 | VkDeviceSize offset) { |
| 5957 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5958 | UpdateStateCmdDrawDispatchType(cb_state, CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5959 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 5960 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5961 | } |
| 5962 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5963 | void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5964 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5965 | uint32_t stride, const char *function) { |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5966 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5967 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 5968 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5969 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5970 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5971 | AddCommandBufferBindingBuffer(cb_state, count_buffer_state); |
| 5972 | } |
| 5973 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5974 | void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5975 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5976 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5977 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5978 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5979 | "vkCmdDrawIndirectCountKHR()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5980 | } |
| 5981 | |
| 5982 | void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5983 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5984 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5985 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5986 | "vkCmdDrawIndirectCount()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5987 | } |
| 5988 | |
| 5989 | void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5990 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5991 | uint32_t maxDrawCount, uint32_t stride, const char *function) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5992 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5993 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 5994 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5995 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXEDINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5996 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5997 | AddCommandBufferBindingBuffer(cb_state, count_buffer_state); |
| 5998 | } |
| 5999 | |
| 6000 | void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6001 | VkDeviceSize offset, VkBuffer countBuffer, |
| 6002 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 6003 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6004 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 6005 | "vkCmdDrawIndexedIndirectCountKHR()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 6006 | } |
| 6007 | |
| 6008 | void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6009 | VkDeviceSize offset, VkBuffer countBuffer, |
| 6010 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 6011 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6012 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 6013 | "vkCmdDrawIndexedIndirectCount()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, |
| 6017 | uint32_t firstTask) { |
| 6018 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6019 | UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawMeshTasksNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6023 | VkDeviceSize offset, uint32_t drawCount, uint32_t stride) { |
| 6024 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6025 | UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6026 | "vkCmdDrawMeshTasksIndirectNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6027 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 6028 | if (buffer_state) { |
| 6029 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 6030 | } |
| 6031 | } |
| 6032 | |
| 6033 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 6034 | VkDeviceSize offset, VkBuffer countBuffer, |
| 6035 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 6036 | uint32_t stride) { |
| 6037 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6038 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 6039 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 6040 | UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6041 | "vkCmdDrawMeshTasksIndirectCountNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6042 | if (buffer_state) { |
| 6043 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 6044 | } |
| 6045 | if (count_buffer_state) { |
| 6046 | AddCommandBufferBindingBuffer(cb_state, count_buffer_state); |
| 6047 | } |
| 6048 | } |
| 6049 | |
| 6050 | void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo, |
| 6051 | const VkAllocationCallbacks *pAllocator, |
| 6052 | VkShaderModule *pShaderModule, VkResult result, |
| 6053 | void *csm_state_data) { |
| 6054 | if (VK_SUCCESS != result) return; |
| 6055 | create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data); |
| 6056 | |
Tony-LunarG | 8a51b7d | 2020-07-01 15:57:23 -0600 | [diff] [blame] | 6057 | 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] | 6058 | bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 6059 | auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment, |
| 6060 | csm_state->unique_shader_id) |
| 6061 | : std::make_shared<SHADER_MODULE_STATE>(); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6062 | SetPushConstantUsedInShader(*new_shader_module); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6063 | shaderModuleMap[*pShaderModule] = std::move(new_shader_module); |
| 6064 | } |
| 6065 | |
| 6066 | void ValidationStateTracker::RecordPipelineShaderStage(VkPipelineShaderStageCreateInfo const *pStage, PIPELINE_STATE *pipeline, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 6067 | PIPELINE_STATE::StageState *stage_state) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6068 | // 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] | 6069 | stage_state->entry_point_name = pStage->pName; |
| 6070 | stage_state->shader_state = GetShared<SHADER_MODULE_STATE>(pStage->module); |
| 6071 | auto module = stage_state->shader_state.get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6072 | if (!module->has_valid_spirv) return; |
| 6073 | |
| 6074 | // Validation shouldn't rely on anything in stage state being valid if the entrypoint isn't present |
| 6075 | auto entrypoint = FindEntrypoint(module, pStage->pName, pStage->stage); |
| 6076 | if (entrypoint == module->end()) return; |
| 6077 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 6078 | stage_state->stage_flag = pStage->stage; |
| 6079 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6080 | // Mark accessible ids |
| 6081 | stage_state->accessible_ids = MarkAccessibleIds(module, entrypoint); |
| 6082 | ProcessExecutionModes(module, entrypoint, pipeline); |
| 6083 | |
locke-lunarg | 63e4daf | 2020-08-17 17:53:25 -0600 | [diff] [blame] | 6084 | stage_state->descriptor_uses = CollectInterfaceByDescriptorSlot( |
| 6085 | module, 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] | 6086 | // Capture descriptor uses for the pipeline |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 6087 | for (const auto &use : stage_state->descriptor_uses) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6088 | // While validating shaders capture which slots are used by the pipeline |
John Zulauf | 649edd5 | 2019-10-02 14:39:41 -0600 | [diff] [blame] | 6089 | const uint32_t slot = use.first.first; |
locke-lunarg | 351c9d8 | 2020-10-23 14:43:21 -0600 | [diff] [blame] | 6090 | 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] | 6091 | auto &reqs = pipeline->active_slots[slot][use.first.second].reqs; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6092 | reqs = descriptor_req(reqs | DescriptorTypeToReqs(module, use.second.type_id)); |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 6093 | 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] | 6094 | 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] | 6095 | 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] | 6096 | |
John Zulauf | 649edd5 | 2019-10-02 14:39:41 -0600 | [diff] [blame] | 6097 | pipeline->max_active_slot = std::max(pipeline->max_active_slot, slot); |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 6098 | if (use.second.samplers_used_by_image.size()) { |
locke-lunarg | 654a905 | 2020-10-13 16:28:42 -0600 | [diff] [blame] | 6099 | auto &samplers_used_by_image = pipeline->active_slots[slot][use.first.second].samplers_used_by_image; |
| 6100 | if (use.second.samplers_used_by_image.size() > samplers_used_by_image.size()) { |
| 6101 | samplers_used_by_image.resize(use.second.samplers_used_by_image.size()); |
| 6102 | } |
locke-lunarg | 654a905 | 2020-10-13 16:28:42 -0600 | [diff] [blame] | 6103 | uint32_t image_index = 0; |
| 6104 | for (const auto &samplers : use.second.samplers_used_by_image) { |
| 6105 | for (const auto &sampler : samplers) { |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 6106 | samplers_used_by_image[image_index].emplace(sampler, nullptr); |
locke-lunarg | 654a905 | 2020-10-13 16:28:42 -0600 | [diff] [blame] | 6107 | } |
| 6108 | ++image_index; |
| 6109 | } |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 6110 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6111 | } |
locke-lunarg | 7848683 | 2020-09-09 19:39:42 -0600 | [diff] [blame] | 6112 | |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 6113 | if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) { |
| 6114 | pipeline->fragmentShader_writable_output_location_list = CollectWritableOutputLocationinFS(*module, *pStage); |
| 6115 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | void ValidationStateTracker::ResetCommandBufferPushConstantDataIfIncompatible(CMD_BUFFER_STATE *cb_state, VkPipelineLayout layout) { |
| 6119 | if (cb_state == nullptr) { |
| 6120 | return; |
| 6121 | } |
| 6122 | |
| 6123 | const PIPELINE_LAYOUT_STATE *pipeline_layout_state = GetPipelineLayout(layout); |
| 6124 | if (pipeline_layout_state == nullptr) { |
| 6125 | return; |
| 6126 | } |
| 6127 | |
| 6128 | if (cb_state->push_constant_data_ranges != pipeline_layout_state->push_constant_ranges) { |
| 6129 | cb_state->push_constant_data_ranges = pipeline_layout_state->push_constant_ranges; |
| 6130 | cb_state->push_constant_data.clear(); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6131 | cb_state->push_constant_data_update.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6132 | uint32_t size_needed = 0; |
| 6133 | for (auto push_constant_range : *cb_state->push_constant_data_ranges) { |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6134 | auto size = push_constant_range.offset + push_constant_range.size; |
| 6135 | size_needed = std::max(size_needed, size); |
| 6136 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 6137 | auto stage_flags = push_constant_range.stageFlags; |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6138 | uint32_t bit_shift = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 6139 | while (stage_flags) { |
| 6140 | if (stage_flags & 1) { |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6141 | VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift); |
| 6142 | const auto it = cb_state->push_constant_data_update.find(flag); |
| 6143 | |
| 6144 | if (it != cb_state->push_constant_data_update.end()) { |
| 6145 | if (it->second.size() < push_constant_range.offset) { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 6146 | it->second.resize(push_constant_range.offset, PC_Byte_Not_Set); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6147 | } |
| 6148 | if (it->second.size() < size) { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 6149 | it->second.resize(size, PC_Byte_Not_Updated); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6150 | } |
| 6151 | } else { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 6152 | std::vector<uint8_t> bytes; |
| 6153 | bytes.resize(push_constant_range.offset, PC_Byte_Not_Set); |
| 6154 | bytes.resize(size, PC_Byte_Not_Updated); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6155 | cb_state->push_constant_data_update[flag] = bytes; |
| 6156 | } |
| 6157 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 6158 | stage_flags = stage_flags >> 1; |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 6159 | ++bit_shift; |
| 6160 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6161 | } |
| 6162 | cb_state->push_constant_data.resize(size_needed, 0); |
| 6163 | } |
| 6164 | } |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6165 | |
| 6166 | void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 6167 | uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages, |
| 6168 | VkResult result) { |
| 6169 | if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return; |
| 6170 | auto swapchain_state = GetSwapchainState(swapchain); |
| 6171 | |
| 6172 | if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount); |
| 6173 | |
| 6174 | if (pSwapchainImages) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6175 | for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 6176 | if (swapchain_state->images[i].image != VK_NULL_HANDLE) continue; // Already retrieved this. |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6177 | |
| 6178 | // Add imageMap entries for each swapchain image |
| 6179 | VkImageCreateInfo image_ci; |
| 6180 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Mark Lobodzinski | d3ec86f | 2020-03-18 11:23:04 -0600 | [diff] [blame] | 6181 | image_ci.pNext = nullptr; // to be set later |
| 6182 | image_ci.flags = 0; // to be updated below |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6183 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 6184 | image_ci.format = swapchain_state->createInfo.imageFormat; |
| 6185 | image_ci.extent.width = swapchain_state->createInfo.imageExtent.width; |
| 6186 | image_ci.extent.height = swapchain_state->createInfo.imageExtent.height; |
| 6187 | image_ci.extent.depth = 1; |
| 6188 | image_ci.mipLevels = 1; |
| 6189 | image_ci.arrayLayers = swapchain_state->createInfo.imageArrayLayers; |
| 6190 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 6191 | image_ci.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 6192 | image_ci.usage = swapchain_state->createInfo.imageUsage; |
| 6193 | image_ci.sharingMode = swapchain_state->createInfo.imageSharingMode; |
| 6194 | image_ci.queueFamilyIndexCount = swapchain_state->createInfo.queueFamilyIndexCount; |
| 6195 | image_ci.pQueueFamilyIndices = swapchain_state->createInfo.pQueueFamilyIndices; |
| 6196 | image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 6197 | |
| 6198 | image_ci.pNext = lvl_find_in_chain<VkImageFormatListCreateInfoKHR>(swapchain_state->createInfo.pNext); |
| 6199 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 6200 | 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] | 6201 | image_ci.flags |= VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 6202 | } |
| 6203 | if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6204 | image_ci.flags |= VK_IMAGE_CREATE_PROTECTED_BIT; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 6205 | } |
| 6206 | if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6207 | image_ci.flags |= (VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT_KHR); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame^] | 6208 | } |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6209 | |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 6210 | imageMap[pSwapchainImages[i]] = std::make_shared<IMAGE_STATE>(device, pSwapchainImages[i], &image_ci); |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6211 | auto &image_state = imageMap[pSwapchainImages[i]]; |
| 6212 | image_state->valid = false; |
| 6213 | image_state->create_from_swapchain = swapchain; |
| 6214 | image_state->bind_swapchain = swapchain; |
| 6215 | image_state->bind_swapchain_imageIndex = i; |
Tony-LunarG | e64e4fe | 2020-02-17 16:21:55 -0700 | [diff] [blame] | 6216 | image_state->is_swapchain_image = true; |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 6217 | swapchain_state->images[i].image = pSwapchainImages[i]; |
| 6218 | swapchain_state->images[i].bound_images.emplace(pSwapchainImages[i]); |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 6219 | |
| 6220 | AddImageStateProps(*image_state, device, physical_device); |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6221 | } |
| 6222 | } |
| 6223 | |
| 6224 | if (*pSwapchainImageCount) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 6225 | swapchain_state->get_swapchain_image_count = *pSwapchainImageCount; |
| 6226 | } |
| 6227 | } |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 6228 | |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 6229 | void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer, |
| 6230 | const VkCopyAccelerationStructureInfoKHR *pInfo) { |
| 6231 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6232 | if (cb_state) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 6233 | ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfo->src); |
| 6234 | ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfo->dst); |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 6235 | if (dst_as_state != nullptr && src_as_state != nullptr) { |
| 6236 | dst_as_state->built = true; |
| 6237 | dst_as_state->build_info_khr = src_as_state->build_info_khr; |
| 6238 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 6239 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 6240 | } |
| 6241 | } |
| 6242 | } |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 6243 | |
| 6244 | void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) { |
| 6245 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6246 | cb_state->status |= CBSTATUS_CULL_MODE_SET; |
| 6247 | cb_state->static_status &= ~CBSTATUS_CULL_MODE_SET; |
| 6248 | } |
| 6249 | |
| 6250 | void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) { |
| 6251 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6252 | cb_state->status |= CBSTATUS_FRONT_FACE_SET; |
| 6253 | cb_state->static_status &= ~CBSTATUS_FRONT_FACE_SET; |
| 6254 | } |
| 6255 | |
| 6256 | void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer, |
| 6257 | VkPrimitiveTopology primitiveTopology) { |
| 6258 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6259 | cb_state->primitiveTopology = primitiveTopology; |
| 6260 | cb_state->status |= CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 6261 | cb_state->static_status &= ~CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 6262 | } |
| 6263 | |
| 6264 | void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount, |
| 6265 | const VkViewport *pViewports) { |
| 6266 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6267 | cb_state->viewportWithCountMask |= (1u << viewportCount) - 1u; |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 6268 | cb_state->viewportWithCountCount = viewportCount; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 6269 | cb_state->status |= CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
| 6270 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
| 6271 | } |
| 6272 | |
| 6273 | void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount, |
| 6274 | const VkRect2D *pScissors) { |
| 6275 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6276 | cb_state->scissorWithCountMask |= (1u << scissorCount) - 1u; |
| 6277 | cb_state->status |= CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 6278 | cb_state->static_status &= ~CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 6279 | } |
| 6280 | |
| 6281 | void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding, |
| 6282 | uint32_t bindingCount, const VkBuffer *pBuffers, |
| 6283 | const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes, |
| 6284 | const VkDeviceSize *pStrides) { |
| 6285 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6286 | if (pStrides) { |
| 6287 | cb_state->status |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 6288 | cb_state->static_status &= ~CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 6289 | } |
| 6290 | |
| 6291 | uint32_t end = firstBinding + bindingCount; |
| 6292 | if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) { |
| 6293 | cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end); |
| 6294 | } |
| 6295 | |
| 6296 | for (uint32_t i = 0; i < bindingCount; ++i) { |
| 6297 | 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] | 6298 | vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]); |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 6299 | vertex_buffer_binding.offset = pOffsets[i]; |
| 6300 | vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE; |
| 6301 | vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0; |
| 6302 | // Add binding for this vertex buffer to this commandbuffer |
| 6303 | if (pBuffers[i]) { |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 6304 | AddCommandBufferBindingBuffer(cb_state, vertex_buffer_binding.buffer_state.get()); |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 6305 | } |
| 6306 | } |
| 6307 | } |
| 6308 | |
| 6309 | void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) { |
| 6310 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6311 | cb_state->status |= CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 6312 | cb_state->static_status &= ~CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 6313 | } |
| 6314 | |
| 6315 | void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) { |
| 6316 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6317 | cb_state->status |= CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 6318 | cb_state->static_status &= ~CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 6319 | } |
| 6320 | |
| 6321 | void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) { |
| 6322 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6323 | cb_state->status |= CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 6324 | cb_state->static_status &= ~CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 6325 | } |
| 6326 | |
| 6327 | void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer, |
| 6328 | VkBool32 depthBoundsTestEnable) { |
| 6329 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6330 | cb_state->status |= CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 6331 | cb_state->static_status &= ~CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 6332 | } |
| 6333 | void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) { |
| 6334 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6335 | cb_state->status |= CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 6336 | cb_state->static_status &= ~CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 6337 | } |
| 6338 | |
| 6339 | void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 6340 | VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp, |
| 6341 | VkCompareOp compareOp) { |
| 6342 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6343 | cb_state->status |= CBSTATUS_STENCIL_OP_SET; |
| 6344 | cb_state->static_status &= ~CBSTATUS_STENCIL_OP_SET; |
| 6345 | } |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 6346 | |
| 6347 | void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle, |
| 6348 | uint32_t discardRectangleCount, |
| 6349 | const VkRect2D *pDiscardRectangles) { |
| 6350 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6351 | cb_state->status |= CBSTATUS_DISCARD_RECTANGLE_SET; |
| 6352 | cb_state->static_status &= ~CBSTATUS_DISCARD_RECTANGLE_SET; |
| 6353 | } |
| 6354 | |
| 6355 | void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer, |
| 6356 | const VkSampleLocationsInfoEXT *pSampleLocationsInfo) { |
| 6357 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6358 | cb_state->status |= CBSTATUS_SAMPLE_LOCATIONS_SET; |
| 6359 | cb_state->static_status &= ~CBSTATUS_SAMPLE_LOCATIONS_SET; |
| 6360 | } |
| 6361 | |
| 6362 | void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer, |
| 6363 | VkCoarseSampleOrderTypeNV sampleOrderType, |
| 6364 | uint32_t customSampleOrderCount, |
| 6365 | const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) { |
| 6366 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 6367 | cb_state->status |= CBSTATUS_COARSE_SAMPLE_ORDER_SET; |
| 6368 | cb_state->static_status &= ~CBSTATUS_COARSE_SAMPLE_ORDER_SET; |
| 6369 | } |